timeliness 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09a4713be8da3195a5d92e1cfbd2bfda98f35ff922674fd12339bcecc562e366'
4
- data.tar.gz: d645f22bed3e99b5e2ebf971304e6f6acc6b657339f3d3d651ea67902258fb24
3
+ metadata.gz: 0b1224a95afa47942b2118db304f6b00f741748e129243fe277ccb45127b9804
4
+ data.tar.gz: 320e9633f0769274f57bcca370e1a839abf62039df963af1d4cb35757b9f03fc
5
5
  SHA512:
6
- metadata.gz: 346644804949fc5398084ff04feecca71b6a415908433520932ff7f38985bcf6bb2c8db0dd048f3939286ebdf9d01fab4544ab9c45e5d2a6549984231f0ec329
7
- data.tar.gz: 39b7862378f626fb7f361769deb81488cd7d5c3c86a61a81dff199ea4b6abc07d29422f64a16e8220085a49fc25c45216259c1e49d5a371533ac4255257fb25f
6
+ metadata.gz: 593b8a2649f97b485a94f205c2e500ca38c31d4db734d46962c4224f12df47fe6679a111d1a950e1794f46065a9e922eafbada8a8dc617ac68a250a1249fba1c
7
+ data.tar.gz: 3b8705a405281a0d4bb2c56f436a6e016bae0f83ed8f61700fc6553d37ed53614b85b56d818063bc4aaa5dc96360426e762da038ed30374473448c621a18e07b
@@ -1,3 +1,7 @@
1
+ = 0.4.4 - 2019-08-06
2
+ * Raise compilation error if token with capturing arg is used more than once in a format
3
+ * Some small internal refactorings in format compilation
4
+
1
5
  = 0.4.3 - 2019-06-16
2
6
  * Fixed `Timeliness.ambiguous_date_format` being used in new threads if custom value set
3
7
  * Moved all config from Timeliness to new Configuration class. Delegated all
@@ -41,9 +41,9 @@ the value for that type.
41
41
 
42
42
  Now let's get strict. Pass the :strict option with true and things get finicky
43
43
 
44
- Timeliness.parse('2010-09-08 12:13:14', :date, :strict => true) #=> nil
45
- Timeliness.parse('2010-09-08 12:13:14', :time, :strict => true) #=> nil
46
- Timeliness.parse('2010-09-08 12:13:14', :datetime, :strict => true) #=> Wed Sep 08 12:13:14 1000 2010 i.e. the whole string is used
44
+ Timeliness.parse('2010-09-08 12:13:14', :date, strict: true) #=> nil
45
+ Timeliness.parse('2010-09-08 12:13:14', :time, strict: true) #=> nil
46
+ Timeliness.parse('2010-09-08 12:13:14', :datetime, strict: true) #=> Wed Sep 08 12:13:14 1000 2010 i.e. the whole string is used
47
47
 
48
48
  The date and time strings are not accepted for a datetime type. The strict option without a type is
49
49
  ignored.
@@ -62,7 +62,7 @@ or using a lambda thats evaluated when parsed
62
62
 
63
63
  It can also be specified with :now option:
64
64
 
65
- Timeliness.parse('12:13:14', :now => Time.mktime(2010,9,8)) #=> Wed Sep 08 12:13:14 1000 2010
65
+ Timeliness.parse('12:13:14', now: Time.mktime(2010,9,8)) #=> Wed Sep 08 12:13:14 1000 2010
66
66
 
67
67
  As well conforming to the Ruby Time class style.
68
68
 
@@ -82,10 +82,10 @@ The last two options require that you have ActiveSupport timezone extension load
82
82
 
83
83
  You can also use the :zone option to control it for a single parse call:
84
84
 
85
- Timeliness.parse('2010-09-08 12:13:14', :zone => :utc) #=> Wed Sep 08 12:13:14 UTC 2010
86
- Timeliness.parse('2010-09-08 12:13:14', :zone => :local) #=> Wed Sep 08 12:13:14 1000 2010
87
- Timeliness.parse('2010-09-08 12:13:14', :zone => :current) #=> Wed Sep 08 12:13:14 1000 2010, with Time.zone = 'Melbourne'
88
- Timeliness.parse('2010-09-08 12:13:14', :zone => 'Melbourne') #=> Wed Sep 08 12:13:14 1000 2010
85
+ Timeliness.parse('2010-09-08 12:13:14', zone: :utc) #=> Wed Sep 08 12:13:14 UTC 2010
86
+ Timeliness.parse('2010-09-08 12:13:14', zone: :local) #=> Wed Sep 08 12:13:14 1000 2010
87
+ Timeliness.parse('2010-09-08 12:13:14', zone: :current) #=> Wed Sep 08 12:13:14 1000 2010, with Time.zone = 'Melbourne'
88
+ Timeliness.parse('2010-09-08 12:13:14', zone: 'Melbourne') #=> Wed Sep 08 12:13:14 1000 2010
89
89
 
90
90
  Remember, you must have ActiveSupport timezone extension loaded to use the last two examples.
91
91
 
@@ -94,8 +94,8 @@ Remember, you must have ActiveSupport timezone extension loaded to use the last
94
94
 
95
95
  To get super finicky, you can restrict the parsing to a single format with the :format option
96
96
 
97
- Timeliness.parse('2010-09-08 12:13:14', :format => 'yyyy-mm-dd hh:nn:ss') #=> Wed Sep 08 12:13:14 UTC 2010
98
- Timeliness.parse('08/09/2010 12:13:14', :format => 'yyyy-mm-dd hh:nn:ss') #=> nil
97
+ Timeliness.parse('2010-09-08 12:13:14', format: 'yyyy-mm-dd hh:nn:ss') #=> Wed Sep 08 12:13:14 UTC 2010
98
+ Timeliness.parse('08/09/2010 12:13:14', format: 'yyyy-mm-dd hh:nn:ss') #=> nil
99
99
 
100
100
 
101
101
  === String with Offset or Zone Abbreviations
@@ -280,7 +280,7 @@ Because formats are evaluated in order, adding a format which may be ambiguous w
280
280
  format, will mean your format is ignored. If you need to make your new format higher precedence than
281
281
  an existing format, you can include the before option like so
282
282
 
283
- Timeliness.add_formats(:time, 'ss:nn:hh', :before => 'hh:nn:ss')
283
+ Timeliness.add_formats(:time, 'ss:nn:hh', before: 'hh:nn:ss')
284
284
 
285
285
  Now a time of '59:30:23' will be interpreted as 11:30:59 pm. This option saves you adding a new one
286
286
  and deleting an old one to get it to work.
data/Rakefile CHANGED
@@ -23,4 +23,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
23
23
  end
24
24
 
25
25
  desc 'Default: run specs.'
26
- task :default => :spec
26
+ task default: :spec
@@ -13,7 +13,7 @@ if defined?(JRUBY_VERSION)
13
13
  end
14
14
 
15
15
  n = 10_000
16
- Benchmark.bm do |x|
16
+ Benchmark.bm(40) do |x|
17
17
  x.report('timeliness - datetime') {
18
18
  n.times do
19
19
  Timeliness::Parser.parse("2000-01-04 12:12:12", :datetime)
@@ -22,7 +22,7 @@ Benchmark.bm do |x|
22
22
 
23
23
  x.report('timeliness - datetime with :format') {
24
24
  n.times do
25
- Timeliness::Parser.parse("2000-01-04 12:12:12", :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
25
+ Timeliness::Parser.parse("2000-01-04 12:12:12", :datetime, format: 'yyyy-mm-dd hh:nn:ss')
26
26
  end
27
27
  }
28
28
 
@@ -131,22 +131,6 @@ Benchmark.bm do |x|
131
131
  end
132
132
  }
133
133
 
134
- if defined?(ParseDate)
135
- x.report('parsedate - valid') {
136
- n.times do
137
- arr = ParseDate.parsedate("2000-01-04 12:12:12")
138
- Date.new(*arr[0..2])
139
- Time.mktime(*arr)
140
- end
141
- }
142
-
143
- x.report('parsedate - invalid ') {
144
- n.times do
145
- arr = ParseDate.parsedate("2000-00-04 12:12:12")
146
- end
147
- }
148
- end
149
-
150
134
  x.report('strptime - valid') {
151
135
  n.times do
152
136
  DateTime.strptime("2000-01-04 12:12:12", '%Y-%m-%d %H:%M:%s')
@@ -3,7 +3,7 @@ class String
3
3
  # Form can be either :utc (default) or :local.
4
4
  def to_time(form = :utc)
5
5
  return nil if self.blank?
6
- Timeliness::Parser.parse(self, :datetime, :zone => form)
6
+ Timeliness::Parser.parse(self, :datetime, zone: form)
7
7
  end
8
8
 
9
9
  def to_date
@@ -121,17 +121,17 @@ module Timeliness
121
121
  # code is nil, then just the raw value is used.
122
122
  #
123
123
  @format_components = {
124
- :year => [ 0, 'unambiguous_year(year)'],
125
- :month => [ 1, 'month_index(month)'],
126
- :day => [ 2 ],
127
- :hour => [ 3, 'full_hour(hour, meridian ||= nil)'],
128
- :min => [ 4 ],
129
- :sec => [ 5 ],
130
- :usec => [ 6, 'microseconds(usec)'],
131
- :offset => [ 7, 'offset_in_seconds(offset)'],
132
- :zone => [ 7, 'zone'],
133
- :zulu => [ 7, 'offset_in_seconds("00:00")'],
134
- :meridian => [ nil ]
124
+ year: [ 0, 'unambiguous_year(year)'],
125
+ month: [ 1, 'month_index(month)'],
126
+ day: [ 2 ],
127
+ hour: [ 3, 'full_hour(hour, meridian ||= nil)'],
128
+ min: [ 4 ],
129
+ sec: [ 5 ],
130
+ usec: [ 6, 'microseconds(usec)'],
131
+ offset: [ 7, 'offset_in_seconds(offset)'],
132
+ zone: [ 7, 'zone'],
133
+ zulu: [ 7, 'offset_in_seconds("00:00")'],
134
+ meridian: [ nil ]
135
135
  }
136
136
 
137
137
  # Mapping some common timezone abbreviations which are not mapped or
@@ -12,29 +12,37 @@ module Timeliness
12
12
 
13
13
  def compile!
14
14
  @token_count = 0
15
+ found_tokens, token_order = [], []
16
+
15
17
  format = format_string.dup
16
18
  format.gsub!(/([\.\\])/, '\\\\\1') # escapes dots and backslashes
17
- found_tokens, token_order = [], []
18
19
 
19
20
  # Substitute tokens with numbered placeholder
20
21
  Definitions.sorted_token_keys.each do |token|
21
- token_regexp_str, arg_key = Definitions.format_tokens[token]
22
- if format.gsub!(/#{token}/, "%<#{found_tokens.size}>")
22
+ count = 0
23
+ format.gsub!(token) do
24
+ token_regexp_str, arg_key = Definitions.format_tokens[token]
25
+ token_index = found_tokens.size
26
+
23
27
  if arg_key
28
+ raise CompilationFailed, "Token '#{token}' was found more than once in format '#{format_string}'. This has unexpected effects should be removed." if count > 0
29
+ count += 1
30
+
24
31
  token_regexp_str = "(#{token_regexp_str})"
25
32
  @token_count += 1
26
33
  end
27
- found_tokens << [token_regexp_str, arg_key]
34
+ found_tokens << [ token_regexp_str, arg_key ]
35
+
36
+ "%<#{token_index}>"
28
37
  end
29
38
  end
30
39
 
31
40
  # Replace placeholders with token regexps
32
- format.scan(/%<(\d)>/).each {|token_index|
33
- token_index = token_index.first
34
- token_regexp_str, arg_key = found_tokens[token_index.to_i]
35
- format.gsub!("%<#{token_index}>", token_regexp_str)
41
+ format.gsub!(/%<(\d+)>/) do
42
+ token_regexp_str, arg_key = found_tokens[$1.to_i]
36
43
  token_order << arg_key
37
- }
44
+ token_regexp_str
45
+ end
38
46
 
39
47
  define_process_method(token_order.compact)
40
48
  @regexp_string = format
@@ -55,12 +63,11 @@ module Timeliness
55
63
  position, code = Definitions.format_components[component]
56
64
  values[position] = code || "#{component}.to_i" if position
57
65
  end
58
- instance_eval <<-DEF
59
- def process(#{components.join(',')})
60
- [#{values.map {|i| i || 'nil' }.join(',')}]
61
- end
66
+ instance_eval <<~DEF
67
+ def process(#{components.join(',')})
68
+ [#{values.map { |i| i || 'nil' }.join(',')}]
69
+ end
62
70
  DEF
63
71
  end
64
-
65
72
  end
66
73
  end
@@ -1,3 +1,3 @@
1
1
  module Timeliness
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -21,13 +21,13 @@ describe Timeliness::Definitions do
21
21
 
22
22
  context "with :before option" do
23
23
  it "should add new format with higher precedence" do
24
- definitions.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
24
+ definitions.add_formats(:time, "ss:hh:nn", before: 'hh:nn:ss')
25
25
  time_array = parser._parse('59:23:58', :time)
26
26
  expect(time_array).to eq [nil,nil,nil,23,58,59,nil,nil]
27
27
  end
28
28
 
29
29
  it "should raise error if :before format does not exist" do
30
- expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.to raise_error(Timeliness::Definitions::FormatNotFound)
30
+ expect { definitions.add_formats(:time, "ss:hh:nn", before: 'nn:hh:ss') }.to raise_error(Timeliness::Definitions::FormatNotFound)
31
31
  end
32
32
  end
33
33
 
@@ -11,17 +11,17 @@ describe Timeliness::FormatSet do
11
11
  context "compiled regexp" do
12
12
  context "for time formats" do
13
13
  format_tests = {
14
- 'hh:nn:ss' => {:pass => ['12:12:12', '01:01:01'], :fail => ['1:12:12', '12:1:12', '12:12:1', '12-12-12']},
15
- 'hh-nn-ss' => {:pass => ['12-12-12', '01-01-01'], :fail => ['1-12-12', '12-1-12', '12-12-1', '12:12:12']},
16
- 'h:nn' => {:pass => ['12:12', '1:01'], :fail => ['12:2', '12-12']},
17
- 'h.nn' => {:pass => ['2.12', '12.12'], :fail => ['2.1', '12:12']},
18
- 'h nn' => {:pass => ['2 12', '12 12'], :fail => ['2 1', '2.12', '12:12']},
19
- 'h-nn' => {:pass => ['2-12', '12-12'], :fail => ['2-1', '2.12', '12:12']},
20
- 'h:nn_ampm' => {:pass => ['2:12am', '2:12 pm', '2:12 AM', '2:12PM'], :fail => ['1:2am', '1:12 pm', '2.12am']},
21
- 'h.nn_ampm' => {:pass => ['2.12am', '2.12 pm'], :fail => ['1:2am', '1:12 pm', '2:12am']},
22
- 'h nn_ampm' => {:pass => ['2 12am', '2 12 pm'], :fail => ['1 2am', '1 12 pm', '2:12am']},
23
- 'h-nn_ampm' => {:pass => ['2-12am', '2-12 pm'], :fail => ['1-2am', '1-12 pm', '2:12am']},
24
- 'h_ampm' => {:pass => ['2am', '2 am', '12 pm'], :fail => ['1.am', '12 pm', '2:12am']},
14
+ 'hh:nn:ss' => {pass: ['12:12:12', '01:01:01'], fail: ['1:12:12', '12:1:12', '12:12:1', '12-12-12']},
15
+ 'hh-nn-ss' => {pass: ['12-12-12', '01-01-01'], fail: ['1-12-12', '12-1-12', '12-12-1', '12:12:12']},
16
+ 'h:nn' => {pass: ['12:12', '1:01'], fail: ['12:2', '12-12']},
17
+ 'h.nn' => {pass: ['2.12', '12.12'], fail: ['2.1', '12:12']},
18
+ 'h nn' => {pass: ['2 12', '12 12'], fail: ['2 1', '2.12', '12:12']},
19
+ 'h-nn' => {pass: ['2-12', '12-12'], fail: ['2-1', '2.12', '12:12']},
20
+ 'h:nn_ampm' => {pass: ['2:12am', '2:12 pm', '2:12 AM', '2:12PM'], fail: ['1:2am', '1:12 pm', '2.12am']},
21
+ 'h.nn_ampm' => {pass: ['2.12am', '2.12 pm'], fail: ['1:2am', '1:12 pm', '2:12am']},
22
+ 'h nn_ampm' => {pass: ['2 12am', '2 12 pm'], fail: ['1 2am', '1 12 pm', '2:12am']},
23
+ 'h-nn_ampm' => {pass: ['2-12am', '2-12 pm'], fail: ['1-2am', '1-12 pm', '2:12am']},
24
+ 'h_ampm' => {pass: ['2am', '2 am', '12 pm'], fail: ['1.am', '12 pm', '2:12am']},
25
25
  }
26
26
  format_tests.each do |format, values|
27
27
  it "should correctly match times in format '#{format}'" do
@@ -34,17 +34,17 @@ describe Timeliness::FormatSet do
34
34
 
35
35
  context "for date formats" do
36
36
  format_tests = {
37
- 'yyyy/mm/dd' => {:pass => ['2000/02/01'], :fail => ['2000\02\01', '2000/2/1', '00/02/01']},
38
- 'yyyy-mm-dd' => {:pass => ['2000-02-01'], :fail => ['2000\02\01', '2000-2-1', '00-02-01']},
39
- 'yyyy.mm.dd' => {:pass => ['2000.02.01'], :fail => ['2000\02\01', '2000.2.1', '00.02.01']},
40
- 'm/d/yy' => {:pass => ['2/1/01', '02/01/00', '02/01/2000'], :fail => ['2/1/0', '2.1.01']},
41
- 'd/m/yy' => {:pass => ['1/2/01', '01/02/00', '01/02/2000'], :fail => ['1/2/0', '1.2.01']},
42
- 'm\d\yy' => {:pass => ['2\1\01', '2\01\00', '02\01\2000'], :fail => ['2\1\0', '2/1/01']},
43
- 'd\m\yy' => {:pass => ['1\2\01', '1\02\00', '01\02\2000'], :fail => ['1\2\0', '1/2/01']},
44
- 'd-m-yy' => {:pass => ['1-2-01', '1-02-00', '01-02-2000'], :fail => ['1-2-0', '1/2/01']},
45
- 'd.m.yy' => {:pass => ['1.2.01', '1.02.00', '01.02.2000'], :fail => ['1.2.0', '1/2/01']},
46
- 'd mmm yy' => {:pass => ['1 Feb 00', '1 Feb 2000', '1 February 00', '01 February 2000'],
47
- :fail => ['1 Fe 00', 'Feb 1 2000', '1 Feb 0']}
37
+ 'yyyy/mm/dd' => {pass: ['2000/02/01'], fail: ['2000\02\01', '2000/2/1', '00/02/01']},
38
+ 'yyyy-mm-dd' => {pass: ['2000-02-01'], fail: ['2000\02\01', '2000-2-1', '00-02-01']},
39
+ 'yyyy.mm.dd' => {pass: ['2000.02.01'], fail: ['2000\02\01', '2000.2.1', '00.02.01']},
40
+ 'm/d/yy' => {pass: ['2/1/01', '02/01/00', '02/01/2000'], fail: ['2/1/0', '2.1.01']},
41
+ 'd/m/yy' => {pass: ['1/2/01', '01/02/00', '01/02/2000'], fail: ['1/2/0', '1.2.01']},
42
+ 'm\d\yy' => {pass: ['2\1\01', '2\01\00', '02\01\2000'], fail: ['2\1\0', '2/1/01']},
43
+ 'd\m\yy' => {pass: ['1\2\01', '1\02\00', '01\02\2000'], fail: ['1\2\0', '1/2/01']},
44
+ 'd-m-yy' => {pass: ['1-2-01', '1-02-00', '01-02-2000'], fail: ['1-2-0', '1/2/01']},
45
+ 'd.m.yy' => {pass: ['1.2.01', '1.02.00', '01.02.2000'], fail: ['1.2.0', '1/2/01']},
46
+ 'd mmm yy' => {pass: ['1 Feb 00', '1 Feb 2000', '1 February 00', '01 February 2000'],
47
+ fail: ['1 Fe 00', 'Feb 1 2000', '1 Feb 0']}
48
48
  }
49
49
  format_tests.each do |format, values|
50
50
  it "should correctly match dates in format '#{format}'" do
@@ -57,10 +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' => {: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 => []},
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: []},
64
64
  }
65
65
  format_tests.each do |format, values|
66
66
  it "should correctly match datetimes in format '#{format}'" do
@@ -16,6 +16,12 @@ describe Timeliness::Format do
16
16
  Timeliness::Format.new('|--[)').compile!
17
17
  }.to raise_error(Timeliness::Format::CompilationFailed)
18
18
  end
19
+
20
+ it 'should raise compilation error if token with captured arg is present more than once' do
21
+ expect {
22
+ Timeliness::Format.new('dd-mm-yyyy-dd').compile!
23
+ }.to raise_error(Timeliness::Format::CompilationFailed)
24
+ end
19
25
  end
20
26
 
21
27
  describe "#process" do
@@ -73,8 +79,8 @@ describe Timeliness::Format do
73
79
  context "with I18n loaded" do
74
80
  before(:all) do
75
81
  I18n.locale = :es
76
- I18n.backend.store_translations :es, :date => { :month_names => %w{ ~ Enero Febrero Marzo } }
77
- I18n.backend.store_translations :es, :date => { :abbr_month_names => %w{ ~ Ene Feb Mar } }
82
+ I18n.backend.store_translations :es, date: { month_names: %w{ ~ Enero Febrero Marzo } }
83
+ I18n.backend.store_translations :es, date: { abbr_month_names: %w{ ~ Ene Feb Mar } }
78
84
  end
79
85
 
80
86
  it 'should parse abbreviated month for current locale to correct value' do
@@ -138,7 +138,7 @@ describe Timeliness::Parser do
138
138
  it 'should return value using string zone adjusted to :zone option string timezone' do
139
139
  Timeliness.configuration.default_timezone = :local
140
140
 
141
- value = parse("Thu, 01 Jun 2000 03:00:00 MST", :zone => 'Perth')
141
+ value = parse("Thu, 01 Jun 2000 03:00:00 MST", zone: 'Perth')
142
142
  expect(value).to eq Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
143
143
  expect(value.utc_offset).to eq 8.hours
144
144
  end
@@ -196,7 +196,7 @@ describe Timeliness::Parser do
196
196
 
197
197
  context "with :now option" do
198
198
  it 'should use date parts if string does not specify' do
199
- time = parse("12:13:14", :now => Time.local(2010,1,1))
199
+ time = parse("12:13:14", now: Time.local(2010,1,1))
200
200
  expect(time).to eq Time.local(2010,1,1,12,13,14)
201
201
  end
202
202
  end
@@ -211,23 +211,23 @@ describe Timeliness::Parser do
211
211
  context "with :zone option" do
212
212
  context ":utc" do
213
213
  it "should return time object in utc timezone" do
214
- time = parse("2000-06-01 12:13:14", :datetime, :zone => :utc)
214
+ time = parse("2000-06-01 12:13:14", :datetime, zone: :utc)
215
215
  expect(time.utc_offset).to eq 0
216
216
  end
217
217
 
218
218
  it 'should return nil for partial invalid time component' do
219
- expect(parse("2000-06-01 12:60", :datetime, :zone => :utc)).to be_nil
219
+ expect(parse("2000-06-01 12:60", :datetime, zone: :utc)).to be_nil
220
220
  end
221
221
  end
222
222
 
223
223
  context ":local" do
224
224
  it "should return time object in local system timezone" do
225
- time = parse("2000-06-01 12:13:14", :datetime, :zone => :local)
225
+ time = parse("2000-06-01 12:13:14", :datetime, zone: :local)
226
226
  expect(time.utc_offset).to eq Time.mktime(2000, 6, 1, 12, 13, 14).utc_offset
227
227
  end
228
228
 
229
229
  it 'should return nil for partial invalid time component' do
230
- expect(parse("2000-06-01 12:60", :datetime, :zone => :local)).to be_nil
230
+ expect(parse("2000-06-01 12:60", :datetime, zone: :local)).to be_nil
231
231
  end
232
232
  end
233
233
 
@@ -235,23 +235,23 @@ describe Timeliness::Parser do
235
235
  timezone_settings zone: 'Adelaide'
236
236
 
237
237
  it "should return time object in current timezone" do
238
- time = parse("2000-06-01 12:13:14", :datetime, :zone => :current)
238
+ time = parse("2000-06-01 12:13:14", :datetime, zone: :current)
239
239
  expect(time.utc_offset).to eq 9.5.hours
240
240
  end
241
241
 
242
242
  it 'should return nil for partial invalid time component' do
243
- expect(parse("2000-06-01 12:60", :datetime, :zone => :current)).to be_nil
243
+ expect(parse("2000-06-01 12:60", :datetime, zone: :current)).to be_nil
244
244
  end
245
245
  end
246
246
 
247
247
  context "named zone" do
248
248
  it "should return time object in the timezone" do
249
- time = parse("2000-06-01 12:13:14", :datetime, :zone => 'London')
249
+ time = parse("2000-06-01 12:13:14", :datetime, zone: 'London')
250
250
  expect(time.utc_offset).to eq 1.hour
251
251
  end
252
252
 
253
253
  it 'should return nil for partial invalid time component' do
254
- expect(parse("2000-06-01 12:60", :datetime, :zone => 'London')).to be_nil
254
+ expect(parse("2000-06-01 12:60", :datetime, zone: 'London')).to be_nil
255
255
  end
256
256
  end
257
257
 
@@ -259,17 +259,17 @@ describe Timeliness::Parser do
259
259
  it 'should output message' do
260
260
  expect {
261
261
  expect(Time).to receive(:zone).and_raise(NoMethodError.new("undefined method `zone' for Time:Class"))
262
- parse("2000-06-01 12:13:14", :zone => :current)
262
+ parse("2000-06-01 12:13:14", zone: :current)
263
263
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
264
264
 
265
265
  expect {
266
266
  expect(Time).to receive(:current).and_raise(NoMethodError.new("undefined method `current' for Time:Class"))
267
- parse("12:13:14", :zone => :current)
267
+ parse("12:13:14", zone: :current)
268
268
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
269
269
 
270
270
  expect {
271
271
  expect(Time).to receive(:use_zone).and_raise(NoMethodError.new("undefined method `use_zone' for Time:Class"))
272
- parse("2000-06-01 12:13:14", :zone => 'London')
272
+ parse("2000-06-01 12:13:14", zone: 'London')
273
273
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
274
274
  end
275
275
  end
@@ -292,7 +292,7 @@ describe Timeliness::Parser do
292
292
 
293
293
  context "with :now option" do
294
294
  it 'should use date from :now' do
295
- expect(parse('12:13:14', :time, :now => Time.local(2010, 6, 1))).to eq Time.local(2010,6,1,12,13,14)
295
+ expect(parse('12:13:14', :time, now: Time.local(2010, 6, 1))).to eq Time.local(2010,6,1,12,13,14)
296
296
  end
297
297
  end
298
298
 
@@ -304,7 +304,7 @@ describe Timeliness::Parser do
304
304
  end
305
305
 
306
306
  it "should use date from the specified zone" do
307
- time = parse("12:13:14", :time, :zone => :utc)
307
+ time = parse("12:13:14", :time, zone: :utc)
308
308
  expect(time.year).to eq 2009
309
309
  expect(time.month).to eq 12
310
310
  expect(time.day).to eq 31
@@ -374,51 +374,51 @@ describe Timeliness::Parser do
374
374
  end
375
375
  end
376
376
 
377
- context "with :strict => true" do
377
+ context "with strict: true" do
378
378
  it "should return nil from date string when type is datetime" do
379
- time_array = parser._parse('2000-02-01', :datetime, :strict => true)
379
+ time_array = parser._parse('2000-02-01', :datetime, strict: true)
380
380
  expect(time_array).to be_nil
381
381
  end
382
382
 
383
383
  it "should return nil from datetime string when type is date" do
384
- time_array = parser._parse('2000-02-01 12:13:14', :date, :strict => true)
384
+ time_array = parser._parse('2000-02-01 12:13:14', :date, strict: true)
385
385
  expect(time_array).to be_nil
386
386
  end
387
387
 
388
388
  it "should return nil from datetime string when type is time" do
389
- time_array = parser._parse('2000-02-01 12:13:14', :time, :strict => true)
389
+ time_array = parser._parse('2000-02-01 12:13:14', :time, strict: true)
390
390
  expect(time_array).to be_nil
391
391
  end
392
392
 
393
393
  it "should parse date string when type is date" do
394
- time_array = parser._parse('2000-02-01', :date, :strict => true)
394
+ time_array = parser._parse('2000-02-01', :date, strict: true)
395
395
  expect(time_array).not_to be_nil
396
396
  end
397
397
 
398
398
  it "should parse time string when type is time" do
399
- time_array = parser._parse('12:13:14', :time, :strict => true)
399
+ time_array = parser._parse('12:13:14', :time, strict: true)
400
400
  expect(time_array).not_to be_nil
401
401
  end
402
402
 
403
403
  it "should parse datetime string when type is datetime" do
404
- time_array = parser._parse('2000-02-01 12:13:14', :datetime, :strict => true)
404
+ time_array = parser._parse('2000-02-01 12:13:14', :datetime, strict: true)
405
405
  expect(time_array).not_to be_nil
406
406
  end
407
407
 
408
408
  it "should ignore strict parsing if no type specified" do
409
- time_array = parser._parse('2000-02-01', :strict => true)
409
+ time_array = parser._parse('2000-02-01', strict: true)
410
410
  expect(time_array).not_to be_nil
411
411
  end
412
412
  end
413
413
 
414
414
  context "with :format option" do
415
415
  it "should return values if string matches specified format" do
416
- time_array = parser._parse('2000-02-01 12:13:14', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
416
+ time_array = parser._parse('2000-02-01 12:13:14', :datetime, format: 'yyyy-mm-dd hh:nn:ss')
417
417
  expect(time_array).to eq [2000,2,1,12,13,14,nil,nil]
418
418
  end
419
419
 
420
420
  it "should return nil if string does not match specified format" do
421
- time_array = parser._parse('2000-02-01 12:13', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
421
+ time_array = parser._parse('2000-02-01 12:13', :datetime, format: 'yyyy-mm-dd hh:nn:ss')
422
422
  expect(time_array).to be_nil
423
423
  end
424
424
  end
@@ -520,7 +520,7 @@ describe Timeliness::Parser do
520
520
  it 'should return date array from Time value' do
521
521
  time = Time.now
522
522
  date_array = [time.year, time.month, time.day]
523
- expect(current_date(:now => time)).to eq date_array
523
+ expect(current_date(now: time)).to eq date_array
524
524
  end
525
525
  end
526
526
 
@@ -528,26 +528,26 @@ describe Timeliness::Parser do
528
528
  it 'should return date array for utc zone' do
529
529
  time = Time.now.getutc
530
530
  date_array = [time.year, time.month, time.day]
531
- expect(current_date(:zone => :utc)).to eq date_array
531
+ expect(current_date(zone: :utc)).to eq date_array
532
532
  end
533
533
 
534
534
  it 'should return date array for local zone' do
535
535
  time = Time.now
536
536
  date_array = [time.year, time.month, time.day]
537
- expect(current_date(:zone => :local)).to eq date_array
537
+ expect(current_date(zone: :local)).to eq date_array
538
538
  end
539
539
 
540
540
  it 'should return date array for current zone' do
541
541
  Time.zone = 'London'
542
542
  time = Time.current
543
543
  date_array = [time.year, time.month, time.day]
544
- expect(current_date(:zone => :current)).to eq date_array
544
+ expect(current_date(zone: :current)).to eq date_array
545
545
  end
546
546
 
547
547
  it 'should return date array for named zone' do
548
548
  time = Time.use_zone('London') { Time.current }
549
549
  date_array = [time.year, time.month, time.day]
550
- expect(current_date(:zone => 'London')).to eq date_array
550
+ expect(current_date(zone: 'London')).to eq date_array
551
551
  end
552
552
  end
553
553
  end
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.3
4
+ version: 0.4.4
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-06-16 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport