iso8601 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.travis.yml +1 -1
- data/lib/iso8601/atoms.rb +34 -5
- data/lib/iso8601/date.rb +62 -29
- data/lib/iso8601/dateTime.rb +7 -4
- data/lib/iso8601/time.rb +22 -8
- data/lib/iso8601/version.rb +1 -1
- data/spec/iso8601/duration_spec.rb +110 -51
- metadata +41 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6de980e2da893c391f09b68e2e4cc46bd9d67c90
|
4
|
+
data.tar.gz: 3853cfee5b7a1797e937e296b8ac7aff5f6c5a0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5826689b055f19401bb1abd644982e3a589f12e7d44d57dda721124784401fe59ba9a8a52e68c9daf864ea2c00577366cd66d896eb3e5340a943cd979f27f799
|
7
|
+
data.tar.gz: 65e6b987b1334d9b1023d80a2196ea5125c889a4dbd6c7323b989058ae5d2527acb75cdff12a5e785249737a0c93bdfafdacd2f0b3aa3ee27a04eb8dcb03e56b
|
data/.travis.yml
CHANGED
data/lib/iso8601/atoms.rb
CHANGED
@@ -79,16 +79,45 @@ module ISO8601
|
|
79
79
|
# years” of 365 “calendar days” and 97 “leap years” of 366 “calendar days”.
|
80
80
|
def factor
|
81
81
|
if @base.nil?
|
82
|
-
|
82
|
+
nobase_calculation
|
83
83
|
elsif @atom == 0
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
zero_calculation
|
85
|
+
else
|
86
|
+
calculation
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def nobase_calculation
|
93
|
+
(((365 * 303 + 366 * 97) / 400) * 86400) / 12
|
94
|
+
end
|
95
|
+
|
96
|
+
def zero_calculation
|
97
|
+
month = (@base.month <= 12) ? (@base.month) : ((@base.month) % 12)
|
98
|
+
year = @base.year + ((@base.month) / 12).to_i
|
99
|
+
|
100
|
+
(::Time.utc(year, month) - ::Time.utc(@base.year, @base.month))
|
101
|
+
end
|
102
|
+
|
103
|
+
def calculation
|
104
|
+
if @base.month + @atom <= 0
|
105
|
+
month = @base.month + @atom
|
106
|
+
|
107
|
+
if month % 12 == 0
|
108
|
+
year = @base.year + (month / 12) - 1
|
109
|
+
month = 12
|
110
|
+
else
|
111
|
+
year = @base.year + (month / 12).floor
|
112
|
+
month = (12 + month > 0) ? (12 + month) : (12 + (month % -12))
|
113
|
+
end
|
87
114
|
else
|
88
115
|
month = (@base.month + @atom <= 12) ? (@base.month + @atom) : ((@base.month + @atom) % 12)
|
116
|
+
month = 12 if month == 0
|
89
117
|
year = @base.year + ((@base.month + @atom) / 12).to_i
|
90
|
-
(::Time.utc(year, month) - ::Time.utc(@base.year, @base.month)) / @atom
|
91
118
|
end
|
119
|
+
|
120
|
+
(::Time.utc(year, month) - ::Time.utc(@base.year, @base.month)) / @atom
|
92
121
|
end
|
93
122
|
end
|
94
123
|
##
|
data/lib/iso8601/date.rb
CHANGED
@@ -28,14 +28,13 @@ module ISO8601
|
|
28
28
|
# @param [String] input The date pattern
|
29
29
|
def initialize(input)
|
30
30
|
@original = input
|
31
|
-
|
32
31
|
@atoms = atomize(input)
|
33
|
-
@date =
|
34
|
-
rescue ArgumentError => error
|
35
|
-
raise ISO8601::Errors::RangeError, input
|
32
|
+
@date = compose(@atoms)
|
36
33
|
end
|
37
34
|
##
|
38
35
|
# The calendar week number (1-53)
|
36
|
+
#
|
37
|
+
# @return [Integer]
|
39
38
|
def week
|
40
39
|
@date.cweek
|
41
40
|
end
|
@@ -74,52 +73,86 @@ module ISO8601
|
|
74
73
|
# * YYYY-MM-DD, YYYYMMDD
|
75
74
|
# * YYYY-Www, YYYYWdd
|
76
75
|
# * YYYY-Www-D, YYYYWddD
|
76
|
+
# * YYYY-DDD, YYYYDDD
|
77
77
|
#
|
78
78
|
# @param [String] input
|
79
79
|
#
|
80
80
|
# @return [Array<Integer>]
|
81
81
|
def atomize(input)
|
82
|
-
|
83
|
-
|
84
|
-
([+-]?\d{4})(-?)(\d{3}) | # YYYY-DDD
|
85
|
-
([+-]?\d{4})(-)(\d{2}) | # YYYY-MM
|
86
|
-
([+-]?\d{4}) # YYYY
|
87
|
-
)$/x.match(input).to_a.compact
|
82
|
+
week_date = /^([+-]?)\d{4}(-?)W\d{2}(?:\2\d)?$/.match(input)
|
83
|
+
return atomize_week_date(input, week_date[2], week_date[1]) unless week_date.nil?
|
88
84
|
|
89
|
-
|
90
|
-
|
91
|
-
_, year, separator, week, wday = /^(?:
|
92
|
-
([+-]?\d{4})(-?)(W\d{2})\2(\d) | # YYYY-Www-D
|
93
|
-
([+-]?\d{4})(-?)(W\d{2}) # YYYY-Www
|
94
|
-
)$/x.match(input).to_a.compact
|
85
|
+
_, sign, year, separator, day = /^([+-]?)(\d{4})(-?)(\d{3})$/.match(input).to_a.compact
|
86
|
+
return atomize_ordinal(year, day, separator, sign) unless year.nil?
|
95
87
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
88
|
+
_, year, separator, month, day = /^
|
89
|
+
([+-]?\d{4}) # YYYY
|
90
|
+
(?:
|
91
|
+
(-?)(\d{2}) # YYYY-MM
|
92
|
+
(?:
|
93
|
+
\2(\d{2}) # YYYY-MM-DD
|
94
|
+
)?
|
95
|
+
)?
|
96
|
+
$/x.match(input).to_a.compact
|
103
97
|
|
104
98
|
raise ISO8601::Errors::UnknownPattern.new(@original) if year.nil?
|
105
99
|
|
106
100
|
@separator = separator
|
107
101
|
|
108
|
-
return atomize_ordinal(year, month) if month && month.to_s.length == 3
|
109
|
-
|
110
102
|
[year, month, day].compact.map(&:to_i)
|
111
103
|
end
|
112
104
|
##
|
105
|
+
# Parses a week date (YYYY-Www-D, YYYY-Www) and returns its atoms.
|
106
|
+
#
|
107
|
+
# @param [String] input the date string.
|
108
|
+
# @param [String] separator the separator found in the input.
|
109
|
+
# @param [String] sign the sign found in the input.
|
110
|
+
#
|
111
|
+
# @return [Array<Integer>] date atoms.
|
112
|
+
def atomize_week_date(input, separator, sign)
|
113
|
+
date = parse(input)
|
114
|
+
sign = "#{sign}1".to_i
|
115
|
+
@separator = separator
|
116
|
+
|
117
|
+
[sign * date.year, date.month, date.day]
|
118
|
+
end
|
119
|
+
##
|
113
120
|
# Parses an ordinal date (YYYY-DDD) and returns its atoms.
|
114
121
|
#
|
115
122
|
# @param [String] year in YYYY form.
|
116
123
|
# @param [String] day in DDD form.
|
124
|
+
# @param [String] separator the separator found in the input.
|
125
|
+
# @param [String] sign the sign found in the input.
|
117
126
|
#
|
118
|
-
# @return [Array<Integer>] date atoms
|
119
|
-
def atomize_ordinal(year, day)
|
120
|
-
date =
|
127
|
+
# @return [Array<Integer>] date atoms.
|
128
|
+
def atomize_ordinal(year, day, separator, sign)
|
129
|
+
date = parse([year, day].join('-'))
|
130
|
+
sign = "#{sign}1".to_i
|
131
|
+
@separator = separator
|
121
132
|
|
122
|
-
[date.year, date.month, date.day]
|
133
|
+
[sign * date.year, date.month, date.day]
|
134
|
+
end
|
135
|
+
##
|
136
|
+
# Wraps ::Date.parse to play nice with ArgumentError.
|
137
|
+
#
|
138
|
+
# @param [String] string The formatted date.
|
139
|
+
#
|
140
|
+
# @return [::Date]
|
141
|
+
def parse(string)
|
142
|
+
::Date.parse(string)
|
143
|
+
rescue ArgumentError
|
144
|
+
raise ISO8601::Errors::RangeError, @original
|
145
|
+
end
|
146
|
+
##
|
147
|
+
# Wraps ::Date.new to play nice with ArgumentError.
|
148
|
+
#
|
149
|
+
# @param [Array<Integer>] atoms The date atoms.
|
150
|
+
#
|
151
|
+
# @return [::Date]
|
152
|
+
def compose(atoms)
|
153
|
+
::Date.new(*atoms)
|
154
|
+
rescue ArgumentError
|
155
|
+
raise ISO8601::Errors::RangeError, @original
|
123
156
|
end
|
124
157
|
end
|
125
158
|
end
|
data/lib/iso8601/dateTime.rb
CHANGED
@@ -16,6 +16,9 @@ module ISO8601
|
|
16
16
|
|
17
17
|
attr_reader :second
|
18
18
|
|
19
|
+
FORMAT = '%Y-%m-%dT%H:%M:%S%:z'
|
20
|
+
FORMAT_WITH_FRACTION = '%Y-%m-%dT%H:%M:%S.%2N%:z'
|
21
|
+
|
19
22
|
##
|
20
23
|
# @param [String] date_time The datetime pattern
|
21
24
|
def initialize(date_time)
|
@@ -29,7 +32,7 @@ module ISO8601
|
|
29
32
|
# @param [Numeric] seconds The seconds to add
|
30
33
|
def +(seconds)
|
31
34
|
moment = @date_time.to_time.localtime(zone) + seconds
|
32
|
-
format = moment.subsec.zero? ?
|
35
|
+
format = moment.subsec.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
33
36
|
|
34
37
|
ISO8601::DateTime.new(moment.strftime(format))
|
35
38
|
end
|
@@ -38,15 +41,15 @@ module ISO8601
|
|
38
41
|
#
|
39
42
|
# @param [Numeric] seconds The seconds to substract
|
40
43
|
def -(seconds)
|
41
|
-
moment = @date_time.to_time.localtime(zone) - seconds
|
42
|
-
format = moment.subsec.zero? ?
|
44
|
+
moment = @date_time.to_time.localtime(zone) - seconds
|
45
|
+
format = moment.subsec.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
43
46
|
|
44
47
|
ISO8601::DateTime.new(moment.strftime(format))
|
45
48
|
end
|
46
49
|
##
|
47
50
|
# Converts DateTime to a formated string
|
48
51
|
def to_s
|
49
|
-
format = @date_time.second_fraction.zero? ?
|
52
|
+
format = @date_time.second_fraction.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
50
53
|
@date_time.strftime(format)
|
51
54
|
end
|
52
55
|
##
|
data/lib/iso8601/time.rb
CHANGED
@@ -24,17 +24,19 @@ module ISO8601
|
|
24
24
|
##
|
25
25
|
# The original atoms
|
26
26
|
attr_reader :atoms
|
27
|
+
|
28
|
+
FORMAT = 'T%H:%M:%S%:z'
|
29
|
+
FORMAT_WITH_FRACTION = 'T%H:%M:%S.%2N%:z'
|
30
|
+
|
27
31
|
##
|
28
32
|
# @param [String] input The time pattern
|
29
33
|
# @param [Date] base The base date to determine the time
|
30
34
|
def initialize(input, base = ::Date.today)
|
31
35
|
@original = input
|
32
|
-
|
36
|
+
@base = base
|
33
37
|
@atoms = atomize(input)
|
34
|
-
@time =
|
38
|
+
@time = compose(@atoms, @base)
|
35
39
|
@second = @time.second + @time.second_fraction.to_f
|
36
|
-
rescue ArgumentError => error
|
37
|
-
raise ISO8601::Errors::RangeError, input
|
38
40
|
end
|
39
41
|
##
|
40
42
|
# Forwards the time the given amount of seconds.
|
@@ -44,7 +46,7 @@ module ISO8601
|
|
44
46
|
# @return [ISO8601::Time] New time resulting of the addition
|
45
47
|
def +(seconds)
|
46
48
|
moment = @time.to_time.localtime(zone) + seconds
|
47
|
-
format = moment.subsec.zero? ?
|
49
|
+
format = moment.subsec.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
48
50
|
|
49
51
|
ISO8601::Time.new(moment.strftime(format), ::Date.parse(moment.strftime('%Y-%m-%d')))
|
50
52
|
end
|
@@ -56,15 +58,15 @@ module ISO8601
|
|
56
58
|
# @return [ISO8601::Time] New time resulting of the substraction
|
57
59
|
def -(seconds)
|
58
60
|
moment = @time.to_time.localtime(zone) - seconds
|
59
|
-
format = moment.subsec.zero? ?
|
61
|
+
format = moment.subsec.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
60
62
|
|
61
63
|
ISO8601::Time.new(moment.strftime(format), ::Date.parse(moment.strftime('%Y-%m-%d')))
|
62
64
|
end
|
63
65
|
##
|
64
66
|
# Converts self to a time component representation.
|
65
67
|
def to_s
|
66
|
-
|
67
|
-
@time.strftime(
|
68
|
+
format = @time.second_fraction.zero? ? FORMAT : FORMAT_WITH_FRACTION
|
69
|
+
@time.strftime(format)
|
68
70
|
end
|
69
71
|
##
|
70
72
|
# Converts self to an array of atoms.
|
@@ -111,5 +113,17 @@ module ISO8601
|
|
111
113
|
|
112
114
|
!(wrong_pattern || invalid_separators)
|
113
115
|
end
|
116
|
+
##
|
117
|
+
# Wraps ::DateNew.new to play nice with ArgumentError.
|
118
|
+
#
|
119
|
+
# @param [Array<Integer>] atoms The time atoms.
|
120
|
+
# @param [::Date] base The base date to start computing time.
|
121
|
+
#
|
122
|
+
# @return [::DateTime]
|
123
|
+
def compose(atoms, base)
|
124
|
+
::DateTime.new(*[base.year, base.month, base.day], *atoms)
|
125
|
+
rescue ArgumentError
|
126
|
+
raise ISO8601::Errors::RangeError, @original
|
127
|
+
end
|
114
128
|
end
|
115
129
|
end
|
data/lib/iso8601/version.rb
CHANGED
@@ -84,58 +84,117 @@ describe ISO8601::Duration do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
describe '#to_seconds' do
|
87
|
-
|
88
|
-
|
87
|
+
context 'positive durations' do
|
88
|
+
it "should return the seconds of a P[n]Y duration in a common year" do
|
89
|
+
ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2010, 1))
|
90
|
+
end
|
91
|
+
it "should return the seconds of a P[n]Y duration in a leap year" do
|
92
|
+
ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 1) - Time.utc(2000, 1))
|
93
|
+
end
|
94
|
+
it "should return the seconds of a P[n]Y[n]M duration in a common year" do
|
95
|
+
ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2012, 4) - Time.utc(2010, 1))
|
96
|
+
end
|
97
|
+
it "should return the seconds of a P[n]Y[n]M duration in a leap year" do
|
98
|
+
ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 4) - Time.utc(2000, 1))
|
99
|
+
end
|
100
|
+
it "should return the seconds of a P[n]M duration in a common year" do
|
101
|
+
ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 2) - Time.utc(2012, 1))
|
102
|
+
ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 3) - Time.utc(2012, 1))
|
103
|
+
ISO8601::Duration.new('P19M', ISO8601::DateTime.new('2012-05-01')).to_seconds.should == (Time.utc(2014, 12) - Time.utc(2012, 5))
|
104
|
+
ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 3) - Time.utc(2012, 1))
|
105
|
+
end
|
106
|
+
it "should return the seconds of a P[n]M duration in a leap year" do
|
107
|
+
ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 2) - Time.utc(2000, 1))
|
108
|
+
ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 3) - Time.utc(2000, 1))
|
109
|
+
ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2001, 3) - Time.utc(2000, 1))
|
110
|
+
end
|
111
|
+
it "should return the seconds of a P[n]Y[n]M[n]D duration" do
|
112
|
+
ISO8601::Duration.new('P2Y11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2014, 1, 12) - Time.utc(2012, 1))
|
113
|
+
ISO8601::Duration.new('P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds.should == (Time.utc(2011, 6, 2) - Time.utc(2010, 5))
|
114
|
+
end
|
115
|
+
it "should return the seconds of a P[n]D duration" do
|
116
|
+
ISO8601::Duration.new('P1D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 2) - Time.utc(2012, 1, 1))
|
117
|
+
ISO8601::Duration.new('P11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 12) - Time.utc(2012, 1, 1))
|
118
|
+
ISO8601::Duration.new('P3M11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 4, 12) - Time.utc(2012, 1))
|
119
|
+
end
|
120
|
+
it "should return the seconds of a P[n]W duration" do
|
121
|
+
ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 15) - Time.utc(2012, 1))
|
122
|
+
ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 2, 15) - Time.utc(2012, 2))
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return the seconds of a PT[n]H duration" do
|
126
|
+
ISO8601::Duration.new('PT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 5) - Time.utc(2012, 1))
|
127
|
+
ISO8601::Duration.new('P1YT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 1, 1, 5) - Time.utc(2012, 1))
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should return the seconds of a PT[n]H[n]M duration" do
|
131
|
+
ISO8601::Duration.new('PT5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 5) - Time.utc(2012, 1))
|
132
|
+
ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 1, 5) - Time.utc(2012, 1))
|
133
|
+
ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == ISO8601::Duration.new('PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return the seconds of a PT[n]H[n]M duration" do
|
137
|
+
ISO8601::Duration.new('PT10S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 0, 10) - Time.utc(2012, 1))
|
138
|
+
ISO8601::Duration.new('PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == 10.4
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'negative durations' do
|
143
|
+
it "should return the seconds of a -P[n]Y duration" do
|
144
|
+
ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2008, 1) - Time.utc(2010, 1))
|
145
|
+
end
|
146
|
+
it "should return the seconds of a -P[n]Y duration in a leap year" do
|
147
|
+
ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2001-01-01')).to_seconds.should == (Time.utc(1999, 1) - Time.utc(2001, 1))
|
148
|
+
end
|
149
|
+
it "should return the seconds of a -P[n]Y[n]M duration in a common year" do
|
150
|
+
ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2007, 10) - Time.utc(2010, 1))
|
151
|
+
end
|
152
|
+
it "should return the seconds of a -P[n]Y[n]M duration in a leap year" do
|
153
|
+
ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2001-01-01')).to_seconds.should == (Time.utc(1998, 10) - Time.utc(2001, 1))
|
154
|
+
end
|
155
|
+
it "should return the seconds of a -P[n]M duration in a common year" do
|
156
|
+
ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2011, 12) - Time.utc(2012, 1))
|
157
|
+
ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 2))
|
158
|
+
ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2012-03-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 3))
|
159
|
+
ISO8601::Duration.new('-P36M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2010, 3) - Time.utc(2013, 3))
|
160
|
+
ISO8601::Duration.new('-P39M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2009, 12) - Time.utc(2013, 3))
|
161
|
+
ISO8601::Duration.new('-P156M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2000, 3) - Time.utc(2013, 3))
|
162
|
+
end
|
163
|
+
it "should return the seconds of a -P[n]M duration in a leap year" do
|
164
|
+
ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2000-02-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2000, 2))
|
165
|
+
ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2000-03-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2000, 3))
|
166
|
+
ISO8601::Duration.new('-P14M', ISO8601::DateTime.new('2001-03-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2001, 3))
|
167
|
+
end
|
168
|
+
it "should return the seconds of a -P[n]Y[n]M[n]D duration" do
|
169
|
+
ISO8601::Duration.new('-P2Y11D', ISO8601::DateTime.new('2014-01-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2014, 1, 12))
|
170
|
+
ISO8601::Duration.new('-P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds.should == (Time.utc(2009, 3, 31) - Time.utc(2010, 5))
|
171
|
+
end
|
172
|
+
it "should return the seconds of a -P[n]D duration" do
|
173
|
+
ISO8601::Duration.new('-P1D', ISO8601::DateTime.new('2012-01-02')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 2))
|
174
|
+
ISO8601::Duration.new('-P11D', ISO8601::DateTime.new('2012-01-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 12))
|
175
|
+
ISO8601::Duration.new('-P3M11D', ISO8601::DateTime.new('2012-04-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 4, 12))
|
176
|
+
end
|
177
|
+
it "should return the seconds of a -P[n]W duration" do
|
178
|
+
ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-01-15')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 15))
|
179
|
+
ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 2) - Time.utc(2012, 2, 15))
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should return the seconds of a -PT[n]H duration" do
|
183
|
+
ISO8601::Duration.new('-PT5H', ISO8601::DateTime.new('2012-01-01T05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 5))
|
184
|
+
ISO8601::Duration.new('-P1YT5H', ISO8601::DateTime.new('2013-01-01T05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2013, 1, 1, 5))
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return the seconds of a -PT[n]H[n]M duration" do
|
188
|
+
ISO8601::Duration.new('-PT5M', ISO8601::DateTime.new('2012-01-01T00:05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 0, 5))
|
189
|
+
ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01T01:05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 1, 5))
|
190
|
+
ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == ISO8601::Duration.new('-PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should return the seconds of a -PT[n]H[n]M duration" do
|
194
|
+
ISO8601::Duration.new('-PT10S', ISO8601::DateTime.new('2012-01-01T00:00:00')).to_seconds.should == (Time.utc(2011, 12, 31, 23, 59, 50) - Time.utc(2012, 1))
|
195
|
+
ISO8601::Duration.new('-PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == -10.4
|
196
|
+
end
|
89
197
|
end
|
90
|
-
it "should return the seconds of a P[n]Y duration in a leap year" do
|
91
|
-
ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 1) - Time.utc(2000, 1))
|
92
|
-
end
|
93
|
-
it "should return the seconds of a P[n]Y[n]M duration in a common year" do
|
94
|
-
ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2012, 4) - Time.utc(2010, 1))
|
95
|
-
end
|
96
|
-
it "should return the seconds of a P[n]Y[n]M duration in a leap year" do
|
97
|
-
ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 4) - Time.utc(2000, 1))
|
98
|
-
end
|
99
|
-
it "should return the seconds of a P[n]M duration in a common year" do
|
100
|
-
ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 2) - Time.utc(2012, 1))
|
101
|
-
ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 3) - Time.utc(2012, 1))
|
102
|
-
ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 3) - Time.utc(2012, 1))
|
103
|
-
end
|
104
|
-
it "should return the seconds of a P[n]M duration in a leap year" do
|
105
|
-
ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 2) - Time.utc(2000, 1))
|
106
|
-
ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 3) - Time.utc(2000, 1))
|
107
|
-
ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2001, 3) - Time.utc(2000, 1))
|
108
|
-
end
|
109
|
-
it "should return the seconds of a P[n]Y[n]M[n]D duration" do
|
110
|
-
ISO8601::Duration.new('P2Y11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2014, 1, 12) - Time.utc(2012, 1))
|
111
|
-
ISO8601::Duration.new('P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds.should == (Time.utc(2011, 6, 2) - Time.utc(2010, 5))
|
112
|
-
end
|
113
|
-
it "should return the seconds of a P[n]D duration" do
|
114
|
-
ISO8601::Duration.new('P1D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 2) - Time.utc(2012, 1, 1))
|
115
|
-
ISO8601::Duration.new('P11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 12) - Time.utc(2012, 1, 1))
|
116
|
-
ISO8601::Duration.new('P3M11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 4, 12) - Time.utc(2012, 1))
|
117
|
-
end
|
118
|
-
it "should return the seconds of a P[n]W duration" do
|
119
|
-
ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 15) - Time.utc(2012, 1))
|
120
|
-
ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 2, 15) - Time.utc(2012, 2))
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should return the seconds of a PT[n]H duration" do
|
124
|
-
ISO8601::Duration.new('PT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 5) - Time.utc(2012, 1))
|
125
|
-
ISO8601::Duration.new('P1YT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 1, 1, 5) - Time.utc(2012, 1))
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return the seconds of a PT[n]H[n]M duration" do
|
129
|
-
ISO8601::Duration.new('PT5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 5) - Time.utc(2012, 1))
|
130
|
-
ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 1, 5) - Time.utc(2012, 1))
|
131
|
-
ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == ISO8601::Duration.new('PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should return the seconds of a PT[n]H[n]M duration" do
|
135
|
-
ISO8601::Duration.new('PT10S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 0, 10) - Time.utc(2012, 1))
|
136
|
-
ISO8601::Duration.new('PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == 10.4
|
137
|
-
end
|
138
|
-
|
139
198
|
end
|
140
199
|
|
141
200
|
describe '#==' do
|
metadata
CHANGED
@@ -1,53 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso8601
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Arnau Siches
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-07-27 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: "2.14"
|
14
20
|
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.14'
|
20
21
|
type: :development
|
22
|
+
requirement: *id001
|
21
23
|
prerelease: false
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- &id003
|
28
|
+
- ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: "0"
|
28
31
|
name: rerun
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
32
|
type: :development
|
33
|
+
requirement: *id002
|
35
34
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
description: " ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data
|
42
|
-
elements and \n interchange formats - Information interchange - Representation
|
43
|
-
of dates \n and times) standard.\n"
|
35
|
+
description: " ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and \n interchange formats - Information interchange - Representation of dates \n and times) standard.\n"
|
44
36
|
email: arnau.siches@gmail.com
|
45
37
|
executables: []
|
38
|
+
|
46
39
|
extensions: []
|
40
|
+
|
47
41
|
extra_rdoc_files: []
|
48
|
-
|
49
|
-
|
50
|
-
-
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .travis.yml
|
51
46
|
- Gemfile
|
52
47
|
- LICENSE
|
53
48
|
- README.md
|
@@ -68,30 +63,29 @@ files:
|
|
68
63
|
- spec/iso8601/time_spec.rb
|
69
64
|
- spec/spec_helper.rb
|
70
65
|
homepage: https://github.com/arnau/ISO8601
|
71
|
-
licenses:
|
66
|
+
licenses:
|
72
67
|
- MIT
|
73
68
|
metadata: {}
|
69
|
+
|
74
70
|
post_install_message:
|
75
71
|
rdoc_options: []
|
76
|
-
|
72
|
+
|
73
|
+
require_paths:
|
77
74
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
requirements:
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '0'
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- *id003
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- *id003
|
88
81
|
requirements: []
|
82
|
+
|
89
83
|
rubyforge_project: iso8601
|
90
84
|
rubygems_version: 2.2.2
|
91
85
|
signing_key:
|
92
86
|
specification_version: 4
|
93
87
|
summary: Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601
|
94
|
-
test_files:
|
88
|
+
test_files:
|
95
89
|
- spec/iso8601/atoms_spec.rb
|
96
90
|
- spec/iso8601/dateTime_spec.rb
|
97
91
|
- spec/iso8601/date_spec.rb
|