hijri 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.document +1 -1
- data/.travis.yml +14 -2
- data/CHANGELOG +7 -0
- data/Gemfile +10 -4
- data/README.md +37 -16
- data/hijri.gemspec +4 -3
- data/lib/hijri.rb +2 -2
- data/lib/hijri/converter.rb +22 -8
- data/lib/hijri/date.rb +7 -8
- data/lib/hijri/datetime.rb +2 -2
- data/lib/hijri/format.rb +486 -486
- data/lib/hijri/gregorian.rb +2 -2
- data/lib/hijri/version.rb +1 -1
- data/test/helper.rb +1 -3
- data/test/test_hijri.rb +50 -18
- metadata +11 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e50011d4655e25f84f05d477ea82dc05dc3b100dd2c4811fc1b0f407d534c8d
|
4
|
+
data.tar.gz: 605027362b082021453311e602e8b8b4189563f6c9ae192cca3b7d276db56b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be9e5fec28e71cd801c6bf791d7f7086cf3ec29a2581fa0e561a00bc00425f08fbc92a18be83981a93cafed0b0e8d6e7b157f75b2bc50bad67b6cbe8b873e51
|
7
|
+
data.tar.gz: 2d104b2f9e6ca427585a67509f21f82a6217a016fea91af5caf1da54c24e4b3af0274adad52f15448d37ca3328edc9e19883a8cdb91ebf7e0c6b4df4cc49524c
|
data/.document
CHANGED
data/.travis.yml
CHANGED
@@ -7,9 +7,21 @@ rvm:
|
|
7
7
|
- "2.0.0"
|
8
8
|
- "2.1"
|
9
9
|
- "2.2.0"
|
10
|
+
- "2.2.2"
|
11
|
+
- "2.3.0"
|
12
|
+
- "2.3.1"
|
13
|
+
- "2.4.0"
|
14
|
+
- "2.4.1"
|
15
|
+
- "2.5.1"
|
16
|
+
- "2.6.2"
|
10
17
|
- jruby-18mode # JRuby in 1.8 mode
|
11
18
|
- jruby-19mode # JRuby in 1.9 mode
|
12
|
-
- rbx
|
13
|
-
- rbx-2
|
14
19
|
|
15
20
|
sudo: false
|
21
|
+
notifications:
|
22
|
+
webhooks:
|
23
|
+
urls:
|
24
|
+
- https://webhooks.gitter.im/e/d9c6d1347901833a5f5b
|
25
|
+
on_success: change # options: [always|never|change] default: always
|
26
|
+
on_failure: always # options: [always|never|change] default: always
|
27
|
+
on_start: false # default: false
|
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/hijri.svg)](http://badge.fury.io/rb/hijri)
|
4
4
|
[![Build Status](https://travis-ci.org/ecleel/hijri.svg?branch=master)](https://travis-ci.org/ecleel/hijri)
|
5
|
+
[![Join the chat at https://gitter.im/ecleel/hijri](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ecleel/hijri?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
6
|
|
6
|
-
#####Hijri Date library for Ruby.
|
7
|
-
hijri is full Islamic Hijri calendar lib for ruby.
|
8
|
-
|
7
|
+
##### Hijri Date library for Ruby.
|
8
|
+
hijri is full lunar Islamic Hijri calendar lib for ruby.
|
9
|
+
|
10
|
+
##### Hijri Calendar (from Wikipedia)
|
9
11
|
The Islamic calendar or Muslim calendar or Hijri calendar: is a lunar calendar consisting of 12 lunar months in a year of 354 or 355 days. It is used to date events in many Muslim countries (concurrently with the Gregorian calendar), and used by Muslims everywhere to determine the proper day on which to celebrate Islamic holy days and festivals. The first year was the year during which the emigration of the Islamic prophet Muhammad from Mecca to Medina, known as the Hijra, occurred. Each numbered year is designated either H for Hijra or AH for the Latin anno Hegirae (in the year of the Hijra).[1] A limited number of years before Hijra (BH) are used to date events related to Islam, such as the birth of Muhammad in 53 BH.[2] The current Islamic year is 1431 AH, from approximately 18 December 2009 (evening) to 6 December 2010 (evening).
|
10
12
|
|
11
13
|
http://en.wikipedia.org/wiki/Islamic_calendar
|
@@ -26,18 +28,6 @@ Or install it yourself as:
|
|
26
28
|
|
27
29
|
$ gem install hijri
|
28
30
|
|
29
|
-
###hijri tested and worked in:
|
30
|
-
- Ruby MRI:
|
31
|
-
- 1.8.7
|
32
|
-
- 1.9.2
|
33
|
-
- 1.9.3
|
34
|
-
- 2.0.0
|
35
|
-
- 2.1
|
36
|
-
- 2.2
|
37
|
-
- JRuby 1.7.16.1
|
38
|
-
- jruby-18mode
|
39
|
-
- jruby-19mode
|
40
|
-
- Rubinius 2.4.1
|
41
31
|
|
42
32
|
## Usage
|
43
33
|
|
@@ -51,7 +41,7 @@ h = Date.today.to_hijri # => #<Hijri::Date:0x007f875e8c84e8 @year=1436, @month=2
|
|
51
41
|
hijri = Hijri::Date.new 1430, 1, 3 # => #<Hijri::Date:0x007f875e8dbb38 @year=1430, @month=1, @day=3>
|
52
42
|
|
53
43
|
# or you can get today hijri date directly.
|
54
|
-
|
44
|
+
today = Hijri::Date.today # => #<Hijri::Date:0x007f875e8d8410 @year=1436, @month=2, @day=16>
|
55
45
|
|
56
46
|
# and you can convert hijri date to greogian date also.
|
57
47
|
hijri.to_greo # => #<Date: 2009-01-01 ((2454833j,0s,0n),+0s,2299161j)>
|
@@ -63,6 +53,37 @@ date_and_time = Hijri::DateTime.now # => #<Hijri::DateTime:0x007f875e8eac00 @yea
|
|
63
53
|
Hijri::DateTime.now.strftime('%c') # => "Ahad Rabia I 20 16:00:25 1436"
|
64
54
|
```
|
65
55
|
|
56
|
+
## Supported Ruby versions
|
57
|
+
|
58
|
+
This library aims to support and is [tested against](https://travis-ci.org/ecleel/hijri) the following Ruby
|
59
|
+
implementations:
|
60
|
+
|
61
|
+
* MRI 1.8.7
|
62
|
+
* MRI 1.9.2
|
63
|
+
* MRI 1.9.3
|
64
|
+
* MRI 2.0.0
|
65
|
+
* MRI 2.1.0
|
66
|
+
* MRI 2.2.0
|
67
|
+
* MRI 2.3.0
|
68
|
+
* MRI 2.4.0
|
69
|
+
* MRI 2.4.1
|
70
|
+
* MRI 2.5.1
|
71
|
+
* MRI 2.6.2
|
72
|
+
* JRuby 1.8 mode
|
73
|
+
* JRuby 1.9 mode
|
74
|
+
|
75
|
+
If something doesn't work on one of these Ruby versions, it's a bug.
|
76
|
+
|
77
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
78
|
+
implementations, however support will only be provided for the versions listed
|
79
|
+
above.
|
80
|
+
|
81
|
+
If you would like this library to support another Ruby version, you may
|
82
|
+
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
83
|
+
run and pass on that implementation. When something breaks on your
|
84
|
+
implementation, you will be responsible for providing patches in a timely
|
85
|
+
fashion. If critical issues for a particular implementation exist at the time
|
86
|
+
of a major release, support for that Ruby version may be dropped.
|
66
87
|
|
67
88
|
## TODO
|
68
89
|
|
data/hijri.gemspec
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../lib/hijri/version', __FILE__)
|
4
4
|
|
5
|
+
rake_version = "11.2.2"
|
6
|
+
|
5
7
|
Gem::Specification.new do |gem|
|
6
8
|
gem.name = "hijri"
|
7
9
|
gem.version = Hijri::VERSION
|
@@ -17,7 +19,6 @@ Gem::Specification.new do |gem|
|
|
17
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
20
|
gem.require_paths = ['lib']
|
19
21
|
|
20
|
-
gem.add_development_dependency 'bundler'
|
21
|
-
gem.add_development_dependency '
|
22
|
-
gem.add_development_dependency 'yard', '~> 0.8'
|
22
|
+
gem.add_development_dependency 'bundler'
|
23
|
+
gem.add_development_dependency 'yard'
|
23
24
|
end
|
data/lib/hijri.rb
CHANGED
data/lib/hijri/converter.rb
CHANGED
@@ -2,12 +2,13 @@ module Hijri
|
|
2
2
|
module Converter
|
3
3
|
def self.hijri_to_greo hijri
|
4
4
|
results = absolute_to_greo(hijri_to_absolute(hijri.year, hijri.month, hijri.day))
|
5
|
+
|
5
6
|
if hijri.is_a? DateTime
|
6
7
|
results.push hijri.hour, hijri.minute, hijri.second, hijri.zone
|
7
8
|
end
|
8
9
|
results
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
def self.greo_to_hijri greg
|
12
13
|
results = absolute_to_hijri(greo_to_absolute(greg.year, greg.month, greg.day))
|
13
14
|
if greg.is_a? ::DateTime
|
@@ -16,18 +17,18 @@ module Hijri
|
|
16
17
|
results
|
17
18
|
end
|
18
19
|
|
19
|
-
module_function
|
20
|
-
|
20
|
+
module_function
|
21
|
+
|
21
22
|
# Hijri Methods
|
22
23
|
def islamic_leap_year?(year)
|
23
24
|
return (((((11 * year) + 14) % 30) < 11) ? true : false)
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
def last_day_of_islamic_month(month, year)
|
27
28
|
# Last day in month during year on the Islamic calendar.
|
28
29
|
return ((month % 2 == 1) || (month == 12 && islamic_leap_year?(year)) ? 30 : 29)
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
def hijri_to_absolute(year, month, day)
|
32
33
|
month_days = 29 * (month - 1) # days on this year
|
33
34
|
nonleap_year_days = 354 * (year - 1)
|
@@ -36,7 +37,7 @@ module Hijri
|
|
36
37
|
|
37
38
|
return (day + month_days + this_year + nonleap_year_days + leap_year_days + ISLAMIC_EPOCH).to_i
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
# Gregorian Methods
|
41
42
|
def last_day_of_gregorian_month(month, year)
|
42
43
|
# Compute the last date of the month for the Gregorian calendar.
|
@@ -45,11 +46,21 @@ module Hijri
|
|
45
46
|
end
|
46
47
|
return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]
|
47
48
|
end
|
48
|
-
|
49
|
+
|
50
|
+
def adjust_day(year, month, day)
|
51
|
+
last_day = last_day_of_gregorian_month(month, year)
|
52
|
+
if last_day > day
|
53
|
+
day
|
54
|
+
else
|
55
|
+
last_day
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
# Absolute Methods
|
50
60
|
def greo_to_absolute(year, month, day)
|
51
61
|
# Computes the absolute date from the Gregorian date.
|
52
62
|
d = day
|
63
|
+
|
53
64
|
(month - 1).downto(1) do |m|
|
54
65
|
d += last_day_of_gregorian_month(m, year)
|
55
66
|
end
|
@@ -69,16 +80,19 @@ module Hijri
|
|
69
80
|
while abs >= greo_to_absolute(year + 1, 1, 1)
|
70
81
|
year += 1
|
71
82
|
end
|
83
|
+
|
72
84
|
# Search forward month by month from January
|
73
85
|
month = 1
|
74
86
|
while abs > greo_to_absolute(year, month, last_day_of_gregorian_month(month, year))
|
75
87
|
month += 1
|
88
|
+
break if month == 12
|
76
89
|
end
|
77
90
|
day = abs - greo_to_absolute(year, month, 1) + 1
|
91
|
+
day = adjust_day(year, month, day)
|
78
92
|
|
79
93
|
return [year, month, day]
|
80
94
|
end
|
81
|
-
|
95
|
+
|
82
96
|
def absolute_to_hijri(abs)
|
83
97
|
# Computes the Islamic date from the absolute date.
|
84
98
|
if abs <= ISLAMIC_EPOCH
|
data/lib/hijri/date.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Hijri
|
2
2
|
class Date
|
3
|
-
|
4
3
|
include Comparable
|
5
4
|
|
6
5
|
attr_reader :day, :month, :year
|
@@ -12,11 +11,11 @@ module Hijri
|
|
12
11
|
DAYNAMES = %w(as-Sabt al-Ahad al-Ithnayn ath-Thalaathaa al-Arba'aa' al-Khamis al-Jumu'ah)
|
13
12
|
ABBR_MONTHNAMES = [nil] + ["Muharram", "Safar", "Rabia I", "Rabia II", "Jumaada I", "Jumaada II", "Rajab", "Sha'ban", "Ramadan", "Shawwal", "Dhul-Qi'dah", "Dhul-Hijjah"]
|
14
13
|
ABBR_DAYNAMES = %w(Sabt Ahad Ithnayn Thalaathaa Arba'aa' Khamis Jumu'ah)
|
15
|
-
|
14
|
+
|
16
15
|
[MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYNAMES].each do |xs|
|
17
16
|
xs.each{|x| x.freeze unless x.nil?}.freeze
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
HALF_DAYS_IN_DAY = Rational(1, 2) # :nodoc:
|
21
20
|
HOURS_IN_DAY = Rational(1, 24) # :nodoc:
|
22
21
|
MINUTES_IN_DAY = Rational(1, 1440) # :nodoc:
|
@@ -37,10 +36,10 @@ module Hijri
|
|
37
36
|
if valid_date?(year, month, day)
|
38
37
|
@year, @month, @day = year, month, day
|
39
38
|
else
|
40
|
-
raise ArgumentError, "Invalid Date"
|
39
|
+
raise ArgumentError, "Invalid Date"
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
def change(kargs)
|
45
44
|
# Remove nil values
|
46
45
|
kargs.reject!{|k,v| v.nil?}
|
@@ -77,15 +76,15 @@ module Hijri
|
|
77
76
|
end
|
78
77
|
alias :abs :to_abs
|
79
78
|
|
80
|
-
def to_greo
|
81
|
-
::Date.new
|
79
|
+
def to_greo(adjust=0)
|
80
|
+
::Date.new(*Converter.hijri_to_greo(self)) + adjust
|
82
81
|
end
|
83
82
|
|
84
83
|
# Just to have a consistent Interface.
|
85
84
|
def to_hijri
|
86
85
|
self
|
87
86
|
end
|
88
|
-
|
87
|
+
|
89
88
|
def valid_date?(year, month, day)
|
90
89
|
return false unless (1..INFINITY).cover?(year)
|
91
90
|
return false unless (1..12).cover?(month)
|
data/lib/hijri/datetime.rb
CHANGED
data/lib/hijri/format.rb
CHANGED
@@ -114,22 +114,22 @@ module Hijri
|
|
114
114
|
class Bag # :nodoc:
|
115
115
|
|
116
116
|
def initialize
|
117
|
-
|
117
|
+
@elem = {}
|
118
118
|
end
|
119
119
|
|
120
120
|
def method_missing(t, *args, &block)
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
121
|
+
t = t.to_s
|
122
|
+
set = t.chomp!('=')
|
123
|
+
t = t.intern
|
124
|
+
if set
|
125
|
+
@elem[t] = args[0]
|
126
|
+
else
|
127
|
+
@elem[t]
|
128
|
+
end
|
129
129
|
end
|
130
130
|
|
131
131
|
def to_hash
|
132
|
-
|
132
|
+
@elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
|
133
133
|
end
|
134
134
|
|
135
135
|
end
|
@@ -212,7 +212,7 @@ module Hijri
|
|
212
212
|
end
|
213
213
|
|
214
214
|
private :emit, :emit_w, :emit_n, :emit_sn, :emit_z,
|
215
|
-
|
215
|
+
:emit_a, :emit_ad, :emit_au
|
216
216
|
|
217
217
|
def strftime(fmt='%F')
|
218
218
|
fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/m) do
|
@@ -362,13 +362,13 @@ module Hijri
|
|
362
362
|
else
|
363
363
|
case jd
|
364
364
|
when 2405160...2419614
|
365
|
-
|
365
|
+
g = 'M%02d' % (year - 1867)
|
366
366
|
when 2419614...2424875
|
367
|
-
|
367
|
+
g = 'T%02d' % (year - 1911)
|
368
368
|
when 2424875...2447535
|
369
|
-
|
369
|
+
g = 'S%02d' % (year - 1925)
|
370
370
|
else
|
371
|
-
|
371
|
+
g = 'H%02d' % (year - 1988)
|
372
372
|
end
|
373
373
|
g + strftime('.%m.%d')
|
374
374
|
end
|
@@ -394,177 +394,177 @@ module Hijri
|
|
394
394
|
fmt.scan(/%([EO]?(?::{1,3}z|.))|(.)/m) do |s, c|
|
395
395
|
a = $&
|
396
396
|
if s
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
#
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
#
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
397
|
+
case s
|
398
|
+
when 'A', 'a'
|
399
|
+
return unless str.sub!(/\A(#{Format::DAYS.keys.join('|')})/io, '') ||
|
400
|
+
str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})/io, '')
|
401
|
+
val = Format::DAYS[$1.downcase] || Format::ABBR_DAYS[$1.downcase]
|
402
|
+
return unless val
|
403
|
+
e.wday = val
|
404
|
+
when 'B', 'b', 'h'
|
405
|
+
return unless str.sub!(/\A(#{Format::MONTHS.keys.join('|')})/io, '') ||
|
406
|
+
str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})/io, '')
|
407
|
+
val = Format::MONTHS[$1.downcase] || Format::ABBR_MONTHS[$1.downcase]
|
408
|
+
return unless val
|
409
|
+
e.mon = val
|
410
|
+
when 'C', 'EC'
|
411
|
+
return unless str.sub!(if num_pattern?($')
|
412
|
+
then /\A([-+]?\d{1,2})/
|
413
|
+
else /\A([-+]?\d{1,})/
|
414
|
+
end, '')
|
415
|
+
val = $1.to_i
|
416
|
+
e._cent = val
|
417
|
+
when 'c', 'Ec'
|
418
|
+
return unless _strptime_i(str, '%a %b %e %H:%M:%S %Y', e)
|
419
|
+
when 'D'
|
420
|
+
return unless _strptime_i(str, '%m/%d/%y', e)
|
421
|
+
when 'd', 'e', 'Od', 'Oe'
|
422
|
+
return unless str.sub!(/\A( \d|\d{1,2})/, '')
|
423
|
+
val = $1.to_i
|
424
|
+
return unless (1..31) === val
|
425
|
+
e.mday = val
|
426
|
+
when 'F'
|
427
|
+
return unless _strptime_i(str, '%Y-%m-%d', e)
|
428
|
+
when 'G'
|
429
|
+
return unless str.sub!(if num_pattern?($')
|
430
|
+
then /\A([-+]?\d{1,4})/
|
431
|
+
else /\A([-+]?\d{1,})/
|
432
|
+
end, '')
|
433
|
+
val = $1.to_i
|
434
|
+
e.cwyear = val
|
435
|
+
when 'g'
|
436
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
437
|
+
val = $1.to_i
|
438
|
+
return unless (0..99) === val
|
439
|
+
e.cwyear = val
|
440
|
+
e._cent ||= if val >= 69 then 19 else 20 end
|
441
|
+
when 'H', 'k', 'OH'
|
442
|
+
return unless str.sub!(/\A( \d|\d{1,2})/, '')
|
443
|
+
val = $1.to_i
|
444
|
+
return unless (0..24) === val
|
445
|
+
e.hour = val
|
446
|
+
when 'I', 'l', 'OI'
|
447
|
+
return unless str.sub!(/\A( \d|\d{1,2})/, '')
|
448
|
+
val = $1.to_i
|
449
|
+
return unless (1..12) === val
|
450
|
+
e.hour = val
|
451
|
+
when 'j'
|
452
|
+
return unless str.sub!(/\A(\d{1,3})/, '')
|
453
|
+
val = $1.to_i
|
454
|
+
return unless (1..366) === val
|
455
|
+
e.yday = val
|
456
|
+
when 'L'
|
457
|
+
return unless str.sub!(if num_pattern?($')
|
458
|
+
then /\A([-+]?\d{1,3})/
|
459
|
+
else /\A([-+]?\d{1,})/
|
460
|
+
end, '')
|
461
|
+
# val = Rational($1.to_i, 10**3)
|
462
|
+
val = Rational($1.to_i, 10**$1.size)
|
463
|
+
e.sec_fraction = val
|
464
|
+
when 'M', 'OM'
|
465
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
466
|
+
val = $1.to_i
|
467
|
+
return unless (0..59) === val
|
468
|
+
e.min = val
|
469
|
+
when 'm', 'Om'
|
470
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
471
|
+
val = $1.to_i
|
472
|
+
return unless (1..12) === val
|
473
|
+
e.mon = val
|
474
|
+
when 'N'
|
475
|
+
return unless str.sub!(if num_pattern?($')
|
476
|
+
then /\A([-+]?\d{1,9})/
|
477
|
+
else /\A([-+]?\d{1,})/
|
478
|
+
end, '')
|
479
|
+
# val = Rational($1.to_i, 10**9)
|
480
|
+
val = Rational($1.to_i, 10**$1.size)
|
481
|
+
e.sec_fraction = val
|
482
|
+
when 'n', 't'
|
483
|
+
return unless _strptime_i(str, "\s", e)
|
484
|
+
when 'P', 'p'
|
485
|
+
return unless str.sub!(/\A([ap])(?:m\b|\.m\.)/i, '')
|
486
|
+
e._merid = if $1.downcase == 'a' then 0 else 12 end
|
487
|
+
when 'Q'
|
488
|
+
return unless str.sub!(/\A(-?\d{1,})/, '')
|
489
|
+
val = Rational($1.to_i, 10**3)
|
490
|
+
e.seconds = val
|
491
|
+
when 'R'
|
492
|
+
return unless _strptime_i(str, '%H:%M', e)
|
493
|
+
when 'r'
|
494
|
+
return unless _strptime_i(str, '%I:%M:%S %p', e)
|
495
|
+
when 'S', 'OS'
|
496
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
497
|
+
val = $1.to_i
|
498
|
+
return unless (0..60) === val
|
499
|
+
e.sec = val
|
500
|
+
when 's'
|
501
|
+
return unless str.sub!(/\A(-?\d{1,})/, '')
|
502
|
+
val = $1.to_i
|
503
|
+
e.seconds = val
|
504
|
+
when 'T'
|
505
|
+
return unless _strptime_i(str, '%H:%M:%S', e)
|
506
|
+
when 'U', 'W', 'OU', 'OW'
|
507
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
508
|
+
val = $1.to_i
|
509
|
+
return unless (0..53) === val
|
510
|
+
e.__send__(if s[-1,1] == 'U' then :wnum0= else :wnum1= end, val)
|
511
|
+
when 'u', 'Ou'
|
512
|
+
return unless str.sub!(/\A(\d{1})/, '')
|
513
|
+
val = $1.to_i
|
514
|
+
return unless (1..7) === val
|
515
|
+
e.cwday = val
|
516
|
+
when 'V', 'OV'
|
517
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
518
|
+
val = $1.to_i
|
519
|
+
return unless (1..53) === val
|
520
|
+
e.cweek = val
|
521
|
+
when 'v'
|
522
|
+
return unless _strptime_i(str, '%e-%b-%Y', e)
|
523
|
+
when 'w'
|
524
|
+
return unless str.sub!(/\A(\d{1})/, '')
|
525
|
+
val = $1.to_i
|
526
|
+
return unless (0..6) === val
|
527
|
+
e.wday = val
|
528
|
+
when 'X', 'EX'
|
529
|
+
return unless _strptime_i(str, '%H:%M:%S', e)
|
530
|
+
when 'x', 'Ex'
|
531
|
+
return unless _strptime_i(str, '%m/%d/%y', e)
|
532
|
+
when 'Y', 'EY'
|
533
|
+
return unless str.sub!(if num_pattern?($')
|
534
|
+
then /\A([-+]?\d{1,4})/
|
535
|
+
else /\A([-+]?\d{1,})/
|
536
|
+
end, '')
|
537
|
+
val = $1.to_i
|
538
|
+
e.year = val
|
539
|
+
when 'y', 'Ey', 'Oy'
|
540
|
+
return unless str.sub!(/\A(\d{1,2})/, '')
|
541
|
+
val = $1.to_i
|
542
|
+
return unless (0..99) === val
|
543
|
+
e.year = val
|
544
|
+
e._cent ||= if val >= 69 then 19 else 20 end
|
545
|
+
when 'Z', /\A:{0,3}z/
|
546
|
+
return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|
547
|
+
|[[:alpha:].\s]+(?:standard|daylight)\s+time\b
|
548
|
+
|[[:alpha:]]+(?:\s+dst)?\b
|
549
|
+
)/ix, '')
|
550
|
+
val = $1
|
551
|
+
e.zone = val
|
552
|
+
offset = zone_to_diff(val)
|
553
|
+
e.offset = offset
|
554
|
+
when '%'
|
555
|
+
return unless str.sub!(/\A%/, '')
|
556
|
+
when '+'
|
557
|
+
return unless _strptime_i(str, '%a %b %e %H:%M:%S %Z %Y', e)
|
558
|
+
else
|
559
|
+
return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
|
560
|
+
end
|
561
561
|
else
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
562
|
+
case c
|
563
|
+
when /\A\s/
|
564
|
+
str.sub!(/\A\s+/, '')
|
565
|
+
else
|
566
|
+
return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
|
567
|
+
end
|
568
568
|
end
|
569
569
|
end
|
570
570
|
end
|
@@ -578,17 +578,17 @@ module Hijri
|
|
578
578
|
|
579
579
|
if e._cent
|
580
580
|
if e.cwyear
|
581
|
-
|
581
|
+
e.cwyear += e._cent * 100
|
582
582
|
end
|
583
583
|
if e.year
|
584
|
-
|
584
|
+
e. year += e._cent * 100
|
585
585
|
end
|
586
586
|
end
|
587
587
|
|
588
588
|
if e._merid
|
589
589
|
if e.hour
|
590
|
-
|
591
|
-
|
590
|
+
e.hour %= 12
|
591
|
+
e.hour += e._merid
|
592
592
|
end
|
593
593
|
end
|
594
594
|
|
@@ -610,42 +610,42 @@ module Hijri
|
|
610
610
|
|
611
611
|
if y == nil
|
612
612
|
if d && d.size > 2
|
613
|
-
|
614
|
-
|
613
|
+
y = d
|
614
|
+
d = nil
|
615
615
|
end
|
616
616
|
if d && d[0,1] == "'"
|
617
|
-
|
618
|
-
|
617
|
+
y = d
|
618
|
+
d = nil
|
619
619
|
end
|
620
620
|
end
|
621
621
|
|
622
622
|
if y
|
623
623
|
y.scan(/(\d+)(.+)?/)
|
624
624
|
if $2
|
625
|
-
|
625
|
+
y, d = d, $1
|
626
626
|
end
|
627
627
|
end
|
628
628
|
|
629
629
|
if m
|
630
630
|
if m[0,1] == "'" || m.size > 2
|
631
|
-
|
631
|
+
y, m, d = m, d, y # us -> be
|
632
632
|
end
|
633
633
|
end
|
634
634
|
|
635
635
|
if d
|
636
636
|
if d[0,1] == "'" || d.size > 2
|
637
|
-
|
637
|
+
y, d = d, y
|
638
638
|
end
|
639
639
|
end
|
640
640
|
|
641
641
|
if y
|
642
642
|
y =~ /([-+])?(\d+)/
|
643
643
|
if $1 || $2.size > 2
|
644
|
-
|
644
|
+
c = false
|
645
645
|
end
|
646
646
|
iy = $&.to_i
|
647
647
|
if bc
|
648
|
-
|
648
|
+
iy = -iy + 1
|
649
649
|
end
|
650
650
|
e.year = iy
|
651
651
|
end
|
@@ -680,45 +680,45 @@ module Hijri
|
|
680
680
|
|
681
681
|
def self._parse_time(str, e) # :nodoc:
|
682
682
|
if str.sub!(
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
683
|
+
/(
|
684
|
+
(?:
|
685
|
+
\d+\s*:\s*\d+
|
686
|
+
(?:
|
687
|
+
\s*:\s*\d+(?:[,.]\d*)?
|
688
|
+
)?
|
689
|
+
|
|
690
|
+
\d+\s*h(?:\s*\d+m?(?:\s*\d+s?)?)?
|
691
|
+
)
|
692
|
+
(?:
|
693
|
+
\s*
|
694
|
+
[ap](?:m\b|\.m\.)
|
695
|
+
)?
|
696
|
+
|
|
697
|
+
\d+\s*[ap](?:m\b|\.m\.)
|
698
|
+
)
|
699
|
+
(?:
|
700
|
+
\s*
|
701
|
+
(
|
702
|
+
(?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|
703
|
+
|
|
704
|
+
[[:alpha:].\s]+(?:standard|daylight)\stime\b
|
705
|
+
|
|
706
|
+
[[:alpha:]]+(?:\sdst)?\b
|
707
|
+
)
|
708
|
+
)?
|
709
|
+
/ix,
|
710
|
+
' ')
|
711
711
|
|
712
712
|
t = $1
|
713
713
|
e.zone = $2 if $2
|
714
714
|
|
715
715
|
t =~ /\A(\d+)h?
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
716
|
+
(?:\s*:?\s*(\d+)m?
|
717
|
+
(?:
|
718
|
+
\s*:?\s*(\d+)(?:[,.](\d+))?s?
|
719
|
+
)?
|
720
|
+
)?
|
721
|
+
(?:\s*([ap])(?:m\b|\.m\.))?/ix
|
722
722
|
|
723
723
|
e.hour = $1.to_i
|
724
724
|
e.min = $2.to_i if $2
|
@@ -726,10 +726,10 @@ module Hijri
|
|
726
726
|
e.sec_fraction = Rational($4.to_i, 10**$4.size) if $4
|
727
727
|
|
728
728
|
if $5
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
729
|
+
e.hour %= 12
|
730
|
+
if $5.downcase == 'p'
|
731
|
+
e.hour += 12
|
732
|
+
end
|
733
733
|
end
|
734
734
|
true
|
735
735
|
end
|
@@ -752,38 +752,38 @@ module Hijri
|
|
752
752
|
|
753
753
|
def self._parse_eu(str, e) # :nodoc:
|
754
754
|
if str.sub!(
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
755
|
+
/'?(\d+)[^-\d\s]*
|
756
|
+
\s*
|
757
|
+
(#{Format::ABBR_MONTHS.keys.join('|')})[^-\d\s']*
|
758
|
+
(?:
|
759
|
+
\s*
|
760
|
+
(c(?:e|\.e\.)|b(?:ce|\.c\.e\.)|a(?:d|\.d\.)|b(?:c|\.c\.))?
|
761
|
+
\s*
|
762
|
+
('?-?\d+(?:(?:st|nd|rd|th)\b)?)
|
763
|
+
)?
|
764
|
+
/iox,
|
765
|
+
' ') # '
|
766
766
|
s3e(e, $4, Format::ABBR_MONTHS[$2.downcase], $1,
|
767
|
-
|
767
|
+
$3 && $3[0,1].downcase == 'b')
|
768
768
|
true
|
769
769
|
end
|
770
770
|
end
|
771
771
|
|
772
772
|
def self._parse_us(str, e) # :nodoc:
|
773
773
|
if str.sub!(
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
774
|
+
/\b(#{Format::ABBR_MONTHS.keys.join('|')})[^-\d\s']*
|
775
|
+
\s*
|
776
|
+
('?\d+)[^-\d\s']*
|
777
|
+
(?:
|
778
|
+
\s*
|
779
|
+
(c(?:e|\.e\.)|b(?:ce|\.c\.e\.)|a(?:d|\.d\.)|b(?:c|\.c\.))?
|
780
|
+
\s*
|
781
|
+
('?-?\d+)
|
782
|
+
)?
|
783
|
+
/iox,
|
784
|
+
' ') # '
|
785
785
|
s3e(e, $4, Format::ABBR_MONTHS[$1.downcase], $2,
|
786
|
-
|
786
|
+
$3 && $3[0,1].downcase == 'b')
|
787
787
|
true
|
788
788
|
end
|
789
789
|
end
|
@@ -813,12 +813,12 @@ module Hijri
|
|
813
813
|
e.mday = $2.to_i if $2
|
814
814
|
true
|
815
815
|
elsif /[,.](\d{2}|\d{4})-\d{3}\b/ !~ str &&
|
816
|
-
|
816
|
+
str.sub!(/\b(\d{2}|\d{4})-(\d{3})\b/, ' ')
|
817
817
|
e.year = $1.to_i
|
818
818
|
e.yday = $2.to_i
|
819
819
|
true
|
820
820
|
elsif /\d-\d{3}\b/ !~ str &&
|
821
|
-
|
821
|
+
str.sub!(/\b-(\d{3})\b/, ' ')
|
822
822
|
e.yday = $1.to_i
|
823
823
|
true
|
824
824
|
end
|
@@ -827,10 +827,10 @@ module Hijri
|
|
827
827
|
def self._parse_jis(str, e) # :nodoc:
|
828
828
|
if str.sub!(/\b([mtsh])(\d+)\.(\d+)\.(\d+)/i, ' ')
|
829
829
|
era = { 'm'=>1867,
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
830
|
+
't'=>1911,
|
831
|
+
's'=>1925,
|
832
|
+
'h'=>1988
|
833
|
+
}[$1.downcase]
|
834
834
|
e.year = $2.to_i + era
|
835
835
|
e.mon = $3.to_i
|
836
836
|
e.mday = $4.to_i
|
@@ -840,11 +840,11 @@ module Hijri
|
|
840
840
|
|
841
841
|
def self._parse_vms(str, e) # :nodoc:
|
842
842
|
if str.sub!(/('?-?\d+)-(#{Format::ABBR_MONTHS.keys.join('|')})[^-]*
|
843
|
-
|
843
|
+
-('?-?\d+)/iox, ' ')
|
844
844
|
s3e(e, $3, Format::ABBR_MONTHS[$2.downcase], $1)
|
845
845
|
true
|
846
846
|
elsif str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join('|')})[^-]*
|
847
|
-
|
847
|
+
-('?-?\d+)(?:-('?-?\d+))?/iox, ' ')
|
848
848
|
s3e(e, $3, Format::ABBR_MONTHS[$1.downcase], $2)
|
849
849
|
true
|
850
850
|
end
|
@@ -887,141 +887,141 @@ module Hijri
|
|
887
887
|
|
888
888
|
def self._parse_ddd(str, e) # :nodoc:
|
889
889
|
if str.sub!(
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
890
|
+
/([-+]?)(\d{2,14})
|
891
|
+
(?:
|
892
|
+
\s*
|
893
|
+
t?
|
894
|
+
\s*
|
895
|
+
(\d{2,6})?(?:[,.](\d*))?
|
896
|
+
)?
|
897
|
+
(?:
|
898
|
+
\s*
|
899
|
+
(
|
900
|
+
z\b
|
901
|
+
|
|
902
|
+
[-+]\d{1,4}\b
|
903
|
+
|
|
904
|
+
\[[-+]?\d[^\]]*\]
|
905
|
+
)
|
906
|
+
)?
|
907
|
+
/ix,
|
908
|
+
' ')
|
909
909
|
case $2.size
|
910
910
|
when 2
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
911
|
+
if $3.nil? && $4
|
912
|
+
e.sec = $2[-2, 2].to_i
|
913
|
+
else
|
914
|
+
e.mday = $2[ 0, 2].to_i
|
915
|
+
end
|
916
916
|
when 4
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
917
|
+
if $3.nil? && $4
|
918
|
+
e.sec = $2[-2, 2].to_i
|
919
|
+
e.min = $2[-4, 2].to_i
|
920
|
+
else
|
921
|
+
e.mon = $2[ 0, 2].to_i
|
922
|
+
e.mday = $2[ 2, 2].to_i
|
923
|
+
end
|
924
924
|
when 6
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
925
|
+
if $3.nil? && $4
|
926
|
+
e.sec = $2[-2, 2].to_i
|
927
|
+
e.min = $2[-4, 2].to_i
|
928
|
+
e.hour = $2[-6, 2].to_i
|
929
|
+
else
|
930
|
+
e.year = ($1 + $2[ 0, 2]).to_i
|
931
|
+
e.mon = $2[ 2, 2].to_i
|
932
|
+
e.mday = $2[ 4, 2].to_i
|
933
|
+
end
|
934
934
|
when 8, 10, 12, 14
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
935
|
+
if $3.nil? && $4
|
936
|
+
e.sec = $2[-2, 2].to_i
|
937
|
+
e.min = $2[-4, 2].to_i
|
938
|
+
e.hour = $2[-6, 2].to_i
|
939
|
+
e.mday = $2[-8, 2].to_i
|
940
|
+
if $2.size >= 10
|
941
|
+
e.mon = $2[-10, 2].to_i
|
942
|
+
end
|
943
|
+
if $2.size == 12
|
944
|
+
e.year = ($1 + $2[-12, 2]).to_i
|
945
|
+
end
|
946
|
+
if $2.size == 14
|
947
|
+
e.year = ($1 + $2[-14, 4]).to_i
|
948
|
+
e._comp = false
|
949
|
+
end
|
950
|
+
else
|
951
|
+
e.year = ($1 + $2[ 0, 4]).to_i
|
952
|
+
e.mon = $2[ 4, 2].to_i
|
953
|
+
e.mday = $2[ 6, 2].to_i
|
954
|
+
e.hour = $2[ 8, 2].to_i if $2.size >= 10
|
955
|
+
e.min = $2[10, 2].to_i if $2.size >= 12
|
956
|
+
e.sec = $2[12, 2].to_i if $2.size >= 14
|
957
|
+
e._comp = false
|
958
|
+
end
|
959
959
|
when 3
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
960
|
+
if $3.nil? && $4
|
961
|
+
e.sec = $2[-2, 2].to_i
|
962
|
+
e.min = $2[-3, 1].to_i
|
963
|
+
else
|
964
|
+
e.yday = $2[ 0, 3].to_i
|
965
|
+
end
|
966
966
|
when 5
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
967
|
+
if $3.nil? && $4
|
968
|
+
e.sec = $2[-2, 2].to_i
|
969
|
+
e.min = $2[-4, 2].to_i
|
970
|
+
e.hour = $2[-5, 1].to_i
|
971
|
+
else
|
972
|
+
e.year = ($1 + $2[ 0, 2]).to_i
|
973
|
+
e.yday = $2[ 2, 3].to_i
|
974
|
+
end
|
975
975
|
when 7
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
976
|
+
if $3.nil? && $4
|
977
|
+
e.sec = $2[-2, 2].to_i
|
978
|
+
e.min = $2[-4, 2].to_i
|
979
|
+
e.hour = $2[-6, 2].to_i
|
980
|
+
e.mday = $2[-7, 1].to_i
|
981
|
+
else
|
982
|
+
e.year = ($1 + $2[ 0, 4]).to_i
|
983
|
+
e.yday = $2[ 4, 3].to_i
|
984
|
+
end
|
985
985
|
end
|
986
986
|
if $3
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
987
|
+
if $4
|
988
|
+
case $3.size
|
989
|
+
when 2, 4, 6
|
990
|
+
e.sec = $3[-2, 2].to_i
|
991
|
+
e.min = $3[-4, 2].to_i if $3.size >= 4
|
992
|
+
e.hour = $3[-6, 2].to_i if $3.size >= 6
|
993
|
+
end
|
994
|
+
else
|
995
|
+
case $3.size
|
996
|
+
when 2, 4, 6
|
997
|
+
e.hour = $3[ 0, 2].to_i
|
998
|
+
e.min = $3[ 2, 2].to_i if $3.size >= 4
|
999
|
+
e.sec = $3[ 4, 2].to_i if $3.size >= 6
|
1000
|
+
end
|
1001
|
+
end
|
1002
1002
|
end
|
1003
1003
|
if $4
|
1004
|
-
|
1004
|
+
e.sec_fraction = Rational($4.to_i, 10**$4.size)
|
1005
1005
|
end
|
1006
1006
|
if $5
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1007
|
+
e.zone = $5
|
1008
|
+
if e.zone[0,1] == '['
|
1009
|
+
o, n, = e.zone[1..-2].split(':')
|
1010
|
+
e.zone = n || o
|
1011
|
+
if /\A\d/ =~ o
|
1012
|
+
o = format('+%s', o)
|
1013
|
+
end
|
1014
|
+
e.offset = zone_to_diff(o)
|
1015
|
+
end
|
1016
1016
|
end
|
1017
1017
|
true
|
1018
1018
|
end
|
1019
1019
|
end
|
1020
1020
|
|
1021
1021
|
private_class_method :_parse_day, :_parse_time, # :_parse_beat,
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1022
|
+
:_parse_eu, :_parse_us, :_parse_iso, :_parse_iso2,
|
1023
|
+
:_parse_jis, :_parse_vms, :_parse_sla, :_parse_dot,
|
1024
|
+
:_parse_year, :_parse_mon, :_parse_mday, :_parse_ddd
|
1025
1025
|
|
1026
1026
|
def self._parse(str, comp=true)
|
1027
1027
|
str = str.dup
|
@@ -1050,37 +1050,37 @@ module Hijri
|
|
1050
1050
|
|
1051
1051
|
if str.sub!(/\b(bc\b|bce\b|b\.c\.|b\.c\.e\.)/i, ' ')
|
1052
1052
|
if e.year
|
1053
|
-
|
1053
|
+
e.year = -e.year + 1
|
1054
1054
|
end
|
1055
1055
|
end
|
1056
1056
|
|
1057
1057
|
if str.sub!(/\A\s*(\d{1,2})\s*\z/, ' ')
|
1058
1058
|
if e.hour && !e.mday
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1059
|
+
v = $1.to_i
|
1060
|
+
if (1..31) === v
|
1061
|
+
e.mday = v
|
1062
|
+
end
|
1063
1063
|
end
|
1064
1064
|
if e.mday && !e.hour
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1065
|
+
v = $1.to_i
|
1066
|
+
if (0..24) === v
|
1067
|
+
e.hour = v
|
1068
|
+
end
|
1069
1069
|
end
|
1070
1070
|
end
|
1071
1071
|
|
1072
1072
|
if e._comp
|
1073
1073
|
if e.cwyear
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1074
|
+
if e.cwyear >= 0 && e.cwyear <= 99
|
1075
|
+
e.cwyear += if e.cwyear >= 69
|
1076
|
+
then 1900 else 2000 end
|
1077
|
+
end
|
1078
1078
|
end
|
1079
1079
|
if e.year
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1080
|
+
if e.year >= 0 && e.year <= 99
|
1081
|
+
e.year += if e.year >= 69
|
1082
|
+
then 1900 else 2000 end
|
1083
|
+
end
|
1084
1084
|
end
|
1085
1085
|
end
|
1086
1086
|
|
@@ -1091,43 +1091,43 @@ module Hijri
|
|
1091
1091
|
|
1092
1092
|
def self._iso8601(str) # :nodoc:
|
1093
1093
|
if /\A\s*(([-+]?\d{2,}|-)-\d{2}-\d{2}|
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1094
|
+
([-+]?\d{2,})?-\d{3}|
|
1095
|
+
(\d{2}|\d{4})?-w\d{2}-\d|
|
1096
|
+
-w-\d)
|
1097
|
+
(t
|
1098
|
+
\d{2}:\d{2}(:\d{2}([,.]\d+)?)?
|
1099
|
+
(z|[-+]\d{2}(:?\d{2})?)?)?\s*\z/ix =~ str
|
1100
1100
|
_parse(str)
|
1101
1101
|
elsif /\A\s*(([-+]?(\d{2}|\d{4})|--)\d{2}\d{2}|
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1102
|
+
([-+]?(\d{2}|\d{4}))?\d{3}|-\d{3}|
|
1103
|
+
(\d{2}|\d{4})?w\d{2}\d)
|
1104
|
+
(t?
|
1105
|
+
\d{2}\d{2}(\d{2}([,.]\d+)?)?
|
1106
|
+
(z|[-+]\d{2}(\d{2})?)?)?\s*\z/ix =~ str
|
1107
1107
|
_parse(str)
|
1108
1108
|
elsif /\A\s*(\d{2}:\d{2}(:\d{2}([,.]\d+)?)?
|
1109
|
-
|
1109
|
+
(z|[-+]\d{2}(:?\d{2})?)?)?\s*\z/ix =~ str
|
1110
1110
|
_parse(str)
|
1111
1111
|
elsif /\A\s*(\d{2}\d{2}(\d{2}([,.]\d+)?)?
|
1112
|
-
|
1112
|
+
(z|[-+]\d{2}(\d{2})?)?)?\s*\z/ix =~ str
|
1113
1113
|
_parse(str)
|
1114
1114
|
end
|
1115
1115
|
end
|
1116
1116
|
|
1117
1117
|
def self._rfc3339(str) # :nodoc:
|
1118
1118
|
if /\A\s*-?\d{4}-\d{2}-\d{2} # allow minus, anyway
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1119
|
+
(t|\s)
|
1120
|
+
\d{2}:\d{2}:\d{2}(\.\d+)?
|
1121
|
+
(z|[-+]\d{2}:\d{2})\s*\z/ix =~ str
|
1122
1122
|
_parse(str)
|
1123
1123
|
end
|
1124
1124
|
end
|
1125
1125
|
|
1126
1126
|
def self._xmlschema(str) # :nodoc:
|
1127
1127
|
if /\A\s*(-?\d{4,})(?:-(\d{2})(?:-(\d{2}))?)?
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1128
|
+
(?:t
|
1129
|
+
(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?
|
1130
|
+
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
|
1131
1131
|
e = Format::Bag.new
|
1132
1132
|
e.year = $1.to_i
|
1133
1133
|
e.mon = $2.to_i if $2
|
@@ -1137,31 +1137,31 @@ module Hijri
|
|
1137
1137
|
e.sec = $6.to_i if $6
|
1138
1138
|
e.sec_fraction = Rational($7.to_i, 10**$7.size) if $7
|
1139
1139
|
if $8
|
1140
|
-
|
1141
|
-
|
1140
|
+
e.zone = $8
|
1141
|
+
e.offset = zone_to_diff($8)
|
1142
1142
|
end
|
1143
1143
|
e.to_hash
|
1144
1144
|
elsif /\A\s*(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?
|
1145
|
-
|
1145
|
+
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
|
1146
1146
|
e = Format::Bag.new
|
1147
1147
|
e.hour = $1.to_i if $1
|
1148
1148
|
e.min = $2.to_i if $2
|
1149
1149
|
e.sec = $3.to_i if $3
|
1150
1150
|
e.sec_fraction = Rational($4.to_i, 10**$4.size) if $4
|
1151
1151
|
if $5
|
1152
|
-
|
1153
|
-
|
1152
|
+
e.zone = $5
|
1153
|
+
e.offset = zone_to_diff($5)
|
1154
1154
|
end
|
1155
1155
|
e.to_hash
|
1156
1156
|
elsif /\A\s*(?:--(\d{2})(?:-(\d{2}))?|---(\d{2}))
|
1157
|
-
|
1157
|
+
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
|
1158
1158
|
e = Format::Bag.new
|
1159
1159
|
e.mon = $1.to_i if $1
|
1160
1160
|
e.mday = $2.to_i if $2
|
1161
1161
|
e.mday = $3.to_i if $3
|
1162
1162
|
if $4
|
1163
|
-
|
1164
|
-
|
1163
|
+
e.zone = $4
|
1164
|
+
e.offset = zone_to_diff($4)
|
1165
1165
|
end
|
1166
1166
|
e.to_hash
|
1167
1167
|
end
|
@@ -1169,18 +1169,18 @@ module Hijri
|
|
1169
1169
|
|
1170
1170
|
def self._rfc2822(str) # :nodoc:
|
1171
1171
|
if /\A\s*(?:(?:#{Format::ABBR_DAYS.keys.join('|')})\s*,\s+)?
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1172
|
+
\d{1,2}\s+
|
1173
|
+
(?:#{Format::ABBR_MONTHS.keys.join('|')})\s+
|
1174
|
+
-?(\d{2,})\s+ # allow minus, anyway
|
1175
|
+
\d{2}:\d{2}(:\d{2})?\s*
|
1176
|
+
(?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/iox =~ str
|
1177
1177
|
e = _parse(str, false)
|
1178
1178
|
if $1.size < 4
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1179
|
+
if e[:year] < 50
|
1180
|
+
e[:year] += 2000
|
1181
|
+
elsif e[:year] < 1000
|
1182
|
+
e[:year] += 1900
|
1183
|
+
end
|
1184
1184
|
end
|
1185
1185
|
e
|
1186
1186
|
end
|
@@ -1190,37 +1190,37 @@ module Hijri
|
|
1190
1190
|
|
1191
1191
|
def self._httpdate(str) # :nodoc:
|
1192
1192
|
if /\A\s*(#{Format::ABBR_DAYS.keys.join('|')})\s*,\s+
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1193
|
+
\d{2}\s+
|
1194
|
+
(#{Format::ABBR_MONTHS.keys.join('|')})\s+
|
1195
|
+
-?\d{4}\s+ # allow minus, anyway
|
1196
|
+
\d{2}:\d{2}:\d{2}\s+
|
1197
|
+
gmt\s*\z/iox =~ str
|
1198
1198
|
_rfc2822(str)
|
1199
1199
|
elsif /\A\s*(#{Format::DAYS.keys.join('|')})\s*,\s+
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1200
|
+
\d{2}\s*-\s*
|
1201
|
+
(#{Format::ABBR_MONTHS.keys.join('|')})\s*-\s*
|
1202
|
+
\d{2}\s+
|
1203
|
+
\d{2}:\d{2}:\d{2}\s+
|
1204
|
+
gmt\s*\z/iox =~ str
|
1205
1205
|
_parse(str)
|
1206
1206
|
elsif /\A\s*(#{Format::ABBR_DAYS.keys.join('|')})\s+
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1207
|
+
(#{Format::ABBR_MONTHS.keys.join('|')})\s+
|
1208
|
+
\d{1,2}\s+
|
1209
|
+
\d{2}:\d{2}:\d{2}\s+
|
1210
|
+
\d{4}\s*\z/iox =~ str
|
1211
1211
|
_parse(str)
|
1212
1212
|
end
|
1213
1213
|
end
|
1214
1214
|
|
1215
1215
|
def self._jisx0301(str) # :nodoc:
|
1216
1216
|
if /\A\s*[mtsh]?\d{2}\.\d{2}\.\d{2}
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1217
|
+
(t
|
1218
|
+
(\d{2}:\d{2}(:\d{2}([,.]\d*)?)?
|
1219
|
+
(z|[-+]\d{2}(:?\d{2})?)?)?)?\s*\z/ix =~ str
|
1220
1220
|
if /\A\s*\d/ =~ str
|
1221
|
-
|
1221
|
+
_parse(str.sub(/\A\s*(\d)/, 'h\1'))
|
1222
1222
|
else
|
1223
|
-
|
1223
|
+
_parse(str)
|
1224
1224
|
end
|
1225
1225
|
else
|
1226
1226
|
_iso8601(str)
|
@@ -1234,33 +1234,33 @@ module Hijri
|
|
1234
1234
|
def zone_to_diff(zone) # :nodoc:
|
1235
1235
|
zone = zone.downcase
|
1236
1236
|
if zone.sub!(/\s+(standard|daylight)\s+time\z/, '')
|
1237
|
-
|
1237
|
+
dst = $1 == 'daylight'
|
1238
1238
|
else
|
1239
|
-
|
1239
|
+
dst = zone.sub!(/\s+dst\z/, '')
|
1240
1240
|
end
|
1241
1241
|
if Format::ZONES.include?(zone)
|
1242
|
-
|
1243
|
-
|
1242
|
+
offset = Format::ZONES[zone]
|
1243
|
+
offset += 3600 if dst
|
1244
1244
|
elsif zone.sub!(/\A(?:gmt|utc?)?([-+])/, '')
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1245
|
+
sign = $1
|
1246
|
+
if zone.include?(':')
|
1247
|
+
hour, min, sec, = zone.split(':')
|
1248
|
+
elsif zone.include?(',') || zone.include?('.')
|
1249
|
+
hour, fr, = zone.split(/[,.]/)
|
1250
|
+
min = Rational(fr.to_i, 10**fr.size) * 60
|
1251
|
+
else
|
1252
|
+
case zone.size
|
1253
|
+
when 3
|
1254
|
+
hour = zone[0,1]
|
1255
|
+
min = zone[1,2]
|
1256
|
+
else
|
1257
|
+
hour = zone[0,2]
|
1258
|
+
min = zone[2,2]
|
1259
|
+
sec = zone[4,2]
|
1260
|
+
end
|
1261
|
+
end
|
1262
|
+
offset = hour.to_i * 3600 + min.to_i * 60 + sec.to_i
|
1263
|
+
offset *= -1 if sign == '-'
|
1264
1264
|
end
|
1265
1265
|
offset
|
1266
1266
|
end
|
@@ -1284,12 +1284,12 @@ module Hijri
|
|
1284
1284
|
|
1285
1285
|
def iso8601_timediv(n) # :nodoc:
|
1286
1286
|
strftime('T%T' +
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1287
|
+
if n < 1
|
1288
|
+
''
|
1289
|
+
else
|
1290
|
+
'.%0*d' % [n, (sec_fraction / Rational(1, 10**n)).round]
|
1291
|
+
end +
|
1292
|
+
'%:z')
|
1293
1293
|
end
|
1294
1294
|
|
1295
1295
|
private :iso8601_timediv
|
@@ -1307,4 +1307,4 @@ module Hijri
|
|
1307
1307
|
end
|
1308
1308
|
|
1309
1309
|
end
|
1310
|
-
end
|
1310
|
+
end
|