timeliness 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +5 -0
- data/lib/timeliness/definitions.rb +5 -1
- data/lib/timeliness/version.rb +1 -1
- data/spec/timeliness/format_set_spec.rb +4 -3
- data/spec/timeliness/format_spec.rb +8 -0
- data/spec/timeliness/parser_spec.rb +30 -32
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22c5b15397d7f945442d9768efb71ebbb243e7d44b8948d8ccf03e31c70858b3
|
4
|
+
data.tar.gz: 96ac6e12fd20b0b5530e3ae99e60b2df81c9014bd7cedba26fa6e9395268d8b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3c968646a9f6bc9d867d31c062724e162c8824fd4feb9f76a682f46cfd20cf817948b06bb1f14731eb2f3bb2be5d433edcb39d51ee8655e863898940f9ebf08
|
7
|
+
data.tar.gz: 5eb2af292e5248ee58cfd539bad3491c668adf8c564579c1694ebffd0163e27d0353aec2bd0d478923d930d796d878ca8e99861ea15c9ea86d4bac9089ce16f8
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 0.4.1 - 2019-06-11
|
2
|
+
* Add format for ISO 8601 with usec and 'Z' UTC zone offset (jartek)
|
3
|
+
* Fix ISO 8601 parsing bug where Z was not recognised as UTC
|
4
|
+
* Add 'zt' format token to support 'Z' (Zulu time) zone offset i.e. +00:00 or UTC
|
5
|
+
|
1
6
|
= 0.4.0 - 2019-02-09
|
2
7
|
* Add threadsafety for use_euro_formats & use_us_formats to allow runtime
|
3
8
|
switching (andruby, timdiggins)
|
@@ -75,10 +75,12 @@ module Timeliness
|
|
75
75
|
'ddd, dd mmm yyyy hh:nn:ss tz', # RFC 822
|
76
76
|
'ddd, dd mmm yyyy hh:nn:ss zo', # RFC 822
|
77
77
|
'ddd mmm d hh:nn:ss zo yyyy', # Ruby time string
|
78
|
-
'yyyy-mm-ddThh:nn:
|
78
|
+
'yyyy-mm-ddThh:nn:ss', # ISO 8601
|
79
79
|
'yyyy-mm-ddThh:nn:sszo', # ISO 8601 with zone offset
|
80
|
+
'yyyy-mm-ddThh:nn:sszt', # ISO 8601 with 'Zulu time' (i.e. Z) UTC zone designator
|
80
81
|
'yyyy-mm-ddThh:nn:ss.u', # ISO 8601 with usec
|
81
82
|
'yyyy-mm-ddThh:nn:ss.uzo', # ISO 8601 with usec and offset
|
83
|
+
'yyyy-mm-ddThh:nn:ss.uzt', # ISO 8601 with usec and 'Zulu time' (i.e. Z) UTC zone designator
|
82
84
|
'yyyy-mm-dd hh:nn:ss zo', # Ruby time string in later versions
|
83
85
|
'yyyy-mm-dd hh:nn:ss tz', # Ruby time string for UTC in later versions
|
84
86
|
]
|
@@ -105,6 +107,7 @@ module Timeliness
|
|
105
107
|
'ampm' => [ '[aApP]\.?[mM]\.?', :meridian ],
|
106
108
|
'zo' => [ '[+-]\d{2}:?\d{2}', :offset ],
|
107
109
|
'tz' => [ '[A-Z]{1,5}', :zone ],
|
110
|
+
'zt' => [ '[Z]{1}', :zulu],
|
108
111
|
'_' => [ '\s?' ]
|
109
112
|
}
|
110
113
|
|
@@ -127,6 +130,7 @@ module Timeliness
|
|
127
130
|
:usec => [ 6, 'microseconds(usec)'],
|
128
131
|
:offset => [ 7, 'offset_in_seconds(offset)'],
|
129
132
|
:zone => [ 7, 'zone'],
|
133
|
+
:zulu => [ 7, 'offset_in_seconds("00:00")'],
|
130
134
|
:meridian => [ nil ]
|
131
135
|
}
|
132
136
|
|
data/lib/timeliness/version.rb
CHANGED
@@ -57,8 +57,10 @@ describe Timeliness::FormatSet do
|
|
57
57
|
|
58
58
|
context "for datetime formats" do
|
59
59
|
format_tests = {
|
60
|
-
'ddd mmm d hh:nn:ss zo yyyy'
|
61
|
-
'
|
60
|
+
'ddd mmm d hh:nn:ss zo yyyy' => {:pass => ['Sat Jul 19 12:00:00 +1000 2008'], :fail => []},
|
61
|
+
'ddd mmm d hh:nn:ss tz yyyy' => {:pass => ['Sat Jul 19 12:00:00 EST 2008'], :fail => []},
|
62
|
+
'yyyy-mm-ddThh:nn:sszo' => {:pass => ['2008-07-19T12:00:00+10:00'], :fail => ['2008-07-19T12:00:00Z+10:00']},
|
63
|
+
'yyyy-mm-ddThh:nn:ss.uzt' => {:pass => ['2019-06-07T03:35:55.100000Z'], :fail => []},
|
62
64
|
}
|
63
65
|
format_tests.each do |format, values|
|
64
66
|
it "should correctly match datetimes in format '#{format}'" do
|
@@ -68,7 +70,6 @@ describe Timeliness::FormatSet do
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
71
|
-
|
72
73
|
end
|
73
74
|
|
74
75
|
context "#match" do
|
@@ -55,10 +55,18 @@ describe Timeliness::Format do
|
|
55
55
|
expect(format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00')).to eq [2001,2,3,4,5,6,990000,36000]
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should define method which outputs datetime array with zone offset" do
|
59
|
+
expect(format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00')).to eq [2001,2,3,4,5,6,990000,36000]
|
60
|
+
end
|
61
|
+
|
58
62
|
it "should define method which outputs datetime array with timezone string" do
|
59
63
|
expect(format_for('yyyy-mm-dd hh:nn:ss.u tz').process('2001', '02', '03', '04', '05', '06', '99', 'EST')).to eq [2001,2,3,4,5,6,990000,'EST']
|
60
64
|
end
|
61
65
|
|
66
|
+
it "should define method which outputs datetime array with 0 offset for zulu time ('Z')" do
|
67
|
+
expect(format_for('yyyy-mm-dd hh:nn:ss.uzt').process('2001', '02', '03', '04', '05', '06', '99', 'Z')).to eq [2001,2,3,4,5,6,990000,0]
|
68
|
+
end
|
69
|
+
|
62
70
|
context "with long month" do
|
63
71
|
let(:format) { format_for('dd mmm yyyy') }
|
64
72
|
|
@@ -1,4 +1,19 @@
|
|
1
1
|
describe Timeliness::Parser do
|
2
|
+
around(:all) do |example|
|
3
|
+
current_default = Timeliness.default_timezone
|
4
|
+
current_zone = Time.zone
|
5
|
+
example.call
|
6
|
+
Time.zone = current_zone
|
7
|
+
Timeliness.default_timezone = current_default
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.timezone_settings(zone: nil, output: nil)
|
11
|
+
before do
|
12
|
+
Time.zone = zone if zone
|
13
|
+
Timeliness.default_timezone = output if output
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
2
17
|
before(:all) do
|
3
18
|
Timecop.freeze(2010,1,1,0,0,0)
|
4
19
|
end
|
@@ -70,10 +85,7 @@ describe Timeliness::Parser do
|
|
70
85
|
|
71
86
|
context "string with zone offset value" do
|
72
87
|
context "when current timezone is earler than string zone" do
|
73
|
-
|
74
|
-
Timeliness.default_timezone = :current
|
75
|
-
Time.zone = 'Australia/Melbourne'
|
76
|
-
end
|
88
|
+
timezone_settings zone: 'Australia/Melbourne', output: :current
|
77
89
|
|
78
90
|
it 'should return value shifted by positive offset in default timezone' do
|
79
91
|
value = parse("2000-06-01T12:00:00+02:00")
|
@@ -86,18 +98,10 @@ describe Timeliness::Parser do
|
|
86
98
|
expect(value).to eq Time.zone.local(2000,6,1,23,0,0)
|
87
99
|
expect(value.utc_offset).to eq 10.hours
|
88
100
|
end
|
89
|
-
|
90
|
-
after(:all) do
|
91
|
-
Time.zone = nil
|
92
|
-
Timeliness.default_timezone = :local
|
93
|
-
end
|
94
101
|
end
|
95
102
|
|
96
103
|
context "when current timezone is later than string zone" do
|
97
|
-
|
98
|
-
Timeliness.default_timezone = :current
|
99
|
-
Time.zone = 'America/Phoenix'
|
100
|
-
end
|
104
|
+
timezone_settings zone: 'America/Phoenix', output: :current
|
101
105
|
|
102
106
|
it 'should return value shifted by positive offset in default timezone' do
|
103
107
|
value = parse("2000-06-01T12:00:00+02:00")
|
@@ -110,18 +114,11 @@ describe Timeliness::Parser do
|
|
110
114
|
expect(value).to eq Time.zone.local(2000,6,1,6,0,0)
|
111
115
|
expect(value.utc_offset).to eq -7.hours
|
112
116
|
end
|
113
|
-
|
114
|
-
after(:all) do
|
115
|
-
Time.zone = nil
|
116
|
-
Timeliness.default_timezone = :local
|
117
|
-
end
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
120
|
context "string with zone abbreviation" do
|
122
|
-
|
123
|
-
Time.zone = 'Australia/Melbourne'
|
124
|
-
end
|
121
|
+
timezone_settings zone: 'Australia/Melbourne'
|
125
122
|
|
126
123
|
it 'should return value using string zone adjusted to default :local timezone' do
|
127
124
|
Timeliness.default_timezone = :local
|
@@ -144,9 +141,17 @@ describe Timeliness::Parser do
|
|
144
141
|
expect(value).to eq Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
|
145
142
|
expect(value.utc_offset).to eq 8.hours
|
146
143
|
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "string with zulu time abbreviation 'Z'" do
|
147
|
+
timezone_settings zone: 'Australia/Melbourne'
|
148
|
+
|
149
|
+
it 'should return value using string zone adjusted to default :current timezone' do
|
150
|
+
Timeliness.default_timezone = :current
|
147
151
|
|
148
|
-
|
149
|
-
Time.zone
|
152
|
+
value = parse("2000-06-01T12:00:00Z")
|
153
|
+
expect(value).to eq Time.zone.local(2000,6,1,22,0,0)
|
154
|
+
expect(value.utc_offset).to eq 10.hours
|
150
155
|
end
|
151
156
|
end
|
152
157
|
|
@@ -226,8 +231,9 @@ describe Timeliness::Parser do
|
|
226
231
|
end
|
227
232
|
|
228
233
|
context ":current" do
|
234
|
+
timezone_settings zone: 'Adelaide'
|
235
|
+
|
229
236
|
it "should return time object in current timezone" do
|
230
|
-
Time.zone = 'Adelaide'
|
231
237
|
time = parse("2000-06-01 12:13:14", :datetime, :zone => :current)
|
232
238
|
expect(time.utc_offset).to eq 9.5.hours
|
233
239
|
end
|
@@ -469,19 +475,11 @@ describe Timeliness::Parser do
|
|
469
475
|
end
|
470
476
|
|
471
477
|
context "default timezone" do
|
472
|
-
before do
|
473
|
-
@default_timezone = Timeliness.default_timezone
|
474
|
-
end
|
475
|
-
|
476
478
|
it "should be used if no zone value" do
|
477
479
|
Timeliness.default_timezone = :utc
|
478
480
|
time = parser.make_time([2000,6,1,12,0,0])
|
479
481
|
expect(time.utc_offset).to eq 0
|
480
482
|
end
|
481
|
-
|
482
|
-
after do
|
483
|
-
Timeliness.default_timezone = @default_timezone
|
484
|
-
end
|
485
483
|
end
|
486
484
|
|
487
485
|
context "with zone value" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project: timeliness
|
135
|
-
rubygems_version: 2.7.6
|
135
|
+
rubygems_version: 2.7.6.2
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Date/time parsing for the control freak.
|