chronic 0.9.0 → 0.9.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7033fa51e89c8552e935aab7ee0bb5673338d063
4
+ data.tar.gz: 21a09efad9e8da2dcd3ed32a5c8605707f36abc7
5
+ SHA512:
6
+ metadata.gz: f3d63e888e712dad2b0d4c70d11688607e56a3d1b4ac11632e14b3f23a57f21a2fd32403f50cf13002a9859607a89e6521b5c39f4ec003edd5631791cf7cf409
7
+ data.tar.gz: 9e2d80dcf087643ce865ede613dbd2d006942b1986e46c02f75b012711ee79bb74f0b576ba812d8b54ab599411213548effc036cc888c97b82c70fdf21627365
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
6
+ - jruby-19mode
7
+ - jruby-18mode
8
+ - rbx-19mode
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.9.1 / 2013-02-25
2
+
3
+ * Ensure Chronic strips periods from day portions (#173)
4
+ * Properly numerize "twelfth", "twentieth" etc. (#172, James McKinney)
5
+ * Ensure Chronic is compatible with Ruby 2.0.0 (#165, Ravil Bayramgalin)
6
+
1
7
  # 0.9.0 / 2012-12-21
2
8
 
3
9
  * Implement Chronic::Parser class and create an instance of this class
@@ -13,7 +13,6 @@ require 'chronic/grabber'
13
13
  require 'chronic/pointer'
14
14
  require 'chronic/scalar'
15
15
  require 'chronic/ordinal'
16
- require 'chronic/ordinal'
17
16
  require 'chronic/separator'
18
17
  require 'chronic/time_zone'
19
18
  require 'chronic/numerizer'
@@ -51,7 +50,7 @@ require 'chronic/repeaters/repeater_time'
51
50
  # Chronic.parse('monday', :context => :past)
52
51
  # #=> Mon Aug 21 12:00:00 PDT 2006
53
52
  module Chronic
54
- VERSION = "0.9.0"
53
+ VERSION = "0.9.1"
55
54
 
56
55
  class << self
57
56
 
@@ -250,11 +250,7 @@ module Chronic
250
250
  handle_sm_sd(new_tokens + time_tokens, options)
251
251
  end
252
252
 
253
- # Handle scalar-month/scalar-year
254
- def handle_sm_sy(tokens, options)
255
- month = tokens[0].get_tag(ScalarMonth).type
256
- year = tokens[1].get_tag(ScalarYear).type
257
-
253
+ def handle_year_and_month(year, month)
258
254
  if month == 12
259
255
  next_month_year = year + 1
260
256
  next_month_month = 1
@@ -271,6 +267,20 @@ module Chronic
271
267
  end
272
268
  end
273
269
 
270
+ # Handle scalar-month/scalar-year
271
+ def handle_sm_sy(tokens, options)
272
+ month = tokens[0].get_tag(ScalarMonth).type
273
+ year = tokens[1].get_tag(ScalarYear).type
274
+ handle_year_and_month(year, month)
275
+ end
276
+
277
+ # Handle scalar-year/scalar-month
278
+ def handle_sy_sm(tokens, options)
279
+ year = tokens[0].get_tag(ScalarYear).type
280
+ month = tokens[1].get_tag(ScalarMonth).type
281
+ handle_year_and_month(year, month)
282
+ end
283
+
274
284
  # Handle RepeaterDayName RepeaterMonthName OrdinalDay
275
285
  def handle_rdn_rmn_od(tokens, options)
276
286
  month = tokens[1].get_tag(RepeaterMonthName)
@@ -404,7 +414,6 @@ module Chronic
404
414
 
405
415
  # Handle scalar/repeater/pointer
406
416
  def handle_s_r_p(tokens, options)
407
- repeater = tokens[1].get_tag(Repeater)
408
417
  span = Span.new(self.now, self.now + 1)
409
418
 
410
419
  handle_srp(tokens, span, options)
@@ -37,7 +37,16 @@ module Chronic
37
37
  ['seventh', '7'],
38
38
  ['eighth', '8'],
39
39
  ['ninth', '9'],
40
- ['tenth', '10']
40
+ ['tenth', '10'],
41
+ ['twelfth', '12'],
42
+ ['twentieth', '20'],
43
+ ['thirtieth', '30'],
44
+ ['fourtieth', '40'],
45
+ ['fiftieth', '50'],
46
+ ['sixtieth', '60'],
47
+ ['seventieth', '70'],
48
+ ['eightieth', '80'],
49
+ ['ninetieth', '90']
41
50
  ]
42
51
 
43
52
  TEN_PREFIXES = [
@@ -90,7 +99,7 @@ module Chronic
90
99
  # hundreds, thousands, millions, etc.
91
100
 
92
101
  BIG_PREFIXES.each do |bp|
93
- string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { '<num>' + (bp[1] * $1.to_i).to_s}
102
+ string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { $1.empty? ? bp[1] : '<num>' + (bp[1] * $1.to_i).to_s}
94
103
  andition(string)
95
104
  end
96
105
 
@@ -86,6 +86,7 @@ module Chronic
86
86
  # Returns a new String ready for Chronic to parse.
87
87
  def pre_normalize(text)
88
88
  text = text.to_s.downcase
89
+ text.gsub!(/\b([ap])\.m\.?/, '\1m')
89
90
  text.gsub!(/\./, ':')
90
91
  text.gsub!(/['"]/, '')
91
92
  text.gsub!(/,/, ' ')
@@ -116,6 +117,7 @@ module Chronic
116
117
  text.gsub!(/\b(hence|after|from)\b/, 'future')
117
118
  text.gsub!(/^\s?an? /i, '1 ')
118
119
  text.gsub!(/\b(\d{4}):(\d{2}):(\d{2})\b/, '\1 / \2 / \3') # DTOriginal
120
+ text.gsub!(/\b0(\d+):(\d{2}):(\d{2}) ([ap]m)\b/, '\1:\2:\3 \4')
119
121
  text
120
122
  end
121
123
 
@@ -171,6 +173,7 @@ module Chronic
171
173
  Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
172
174
  Handler.new([:scalar_day, :separator_slash_or_dash?, :repeater_month_name, :separator_at?, 'time?'], :handle_sd_rmn),
173
175
  Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
176
+ Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month], :handle_sy_sm),
174
177
  Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_year], :handle_sm_sy),
175
178
  Handler.new([:scalar_day, :separator_slash_or_dash, :repeater_month_name, :separator_slash_or_dash, :scalar_year, :repeater_time?], :handle_sm_rmn_sy),
176
179
  Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar?, :time_zone], :handle_generic),
@@ -25,7 +25,7 @@ module Chronic
25
25
  '(' << self.begin.to_s << '..' << self.end.to_s << ')'
26
26
  end
27
27
 
28
- alias :cover? :include? unless RUBY_VERSION =~ /^1.9/
28
+ alias :cover? :include? if RUBY_VERSION =~ /^1.8/
29
29
 
30
30
  end
31
- end
31
+ end
@@ -43,5 +43,9 @@ module Chronic
43
43
  def to_s
44
44
  @word << '(' << @tags.join(', ') << ') '
45
45
  end
46
+
47
+ def inspect
48
+ to_s
49
+ end
46
50
  end
47
51
  end
@@ -57,6 +57,20 @@ class ParseNumbersTest < TestCase
57
57
  'second day' => '2nd day',
58
58
  'second of may' => '2nd of may',
59
59
  'fifth' => '5th',
60
+ 'twelfth' => '12th',
61
+ 'twentieth' => '20th',
62
+ 'thirtieth' => '30th',
63
+ 'fourtieth' => '40th',
64
+ 'fiftieth' => '50th',
65
+ 'sixtieth' => '60th',
66
+ 'seventieth' => '70th',
67
+ 'eightieth' => '80th',
68
+ 'ninetieth' => '90th',
69
+ 'hundredth' => '100th',
70
+ 'thousandth' => '1000th',
71
+ 'millionth' => '1000000th',
72
+ 'billionth' => '1000000000th',
73
+ 'trillionth' => '1000000000000th',
60
74
  'twenty third' => '23rd',
61
75
  'first day month two' => '1st day month 2'
62
76
  }.each do |key, val|
@@ -363,12 +363,26 @@ class TestParsing < TestCase
363
363
  # assert_equal nil, time
364
364
  # end
365
365
 
366
+ def test_handle_sy_sm
367
+ time = parse_now("2012-06")
368
+ assert_equal Time.local(2012, 06, 16), time
369
+
370
+ time = parse_now("2013/11")
371
+ assert_equal Time.local(2013, 11, 16), time
372
+ end
373
+
366
374
  def test_handle_r
367
375
  time = parse_now("9am on Saturday")
368
376
  assert_equal Time.local(2006, 8, 19, 9), time
369
377
 
370
378
  time = parse_now("on Tuesday")
371
379
  assert_equal Time.local(2006, 8, 22, 12), time
380
+
381
+ time = parse_now("1:00:00 PM")
382
+ assert_equal Time.local(2006, 8, 16, 13), time
383
+
384
+ time = parse_now("01:00:00 PM")
385
+ assert_equal Time.local(2006, 8, 16, 13), time
372
386
  end
373
387
 
374
388
  def test_handle_r_g_r
@@ -1135,6 +1149,10 @@ class TestParsing < TestCase
1135
1149
  assert_equal Time.local(2006, 12, 31, 12), time
1136
1150
  end
1137
1151
 
1152
+ def test_normalizing_day_portions
1153
+ assert_equal pre_normalize("8:00 pm February 11"), pre_normalize("8:00 p.m. February 11")
1154
+ end
1155
+
1138
1156
  private
1139
1157
  def parse_now(string, options={})
1140
1158
  Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
@@ -9,7 +9,7 @@ class TestSpan < TestCase
9
9
 
10
10
  def test_span_width
11
11
  span = Chronic::Span.new(Time.local(2006, 8, 16, 0), Time.local(2006, 8, 17, 0))
12
- assert_equal (60 * 60 * 24), span.width
12
+ assert_equal((60 * 60 * 24), span.width)
13
13
  end
14
14
 
15
15
  def test_span_math
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
5
- prerelease:
4
+ version: 0.9.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tom Preston-Werner
@@ -10,38 +9,34 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-12-21 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: minitest
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  description: Chronic is a natural language date/time parser written in pure Ruby.
@@ -56,6 +51,7 @@ extra_rdoc_files:
56
51
  - LICENSE
57
52
  files:
58
53
  - .gitignore
54
+ - .travis.yml
59
55
  - HISTORY.md
60
56
  - LICENSE
61
57
  - README.md
@@ -118,28 +114,27 @@ files:
118
114
  - test/test_token.rb
119
115
  homepage: http://github.com/mojombo/chronic
120
116
  licenses: []
117
+ metadata: {}
121
118
  post_install_message:
122
119
  rdoc_options:
123
120
  - --charset=UTF-8
124
121
  require_paths:
125
122
  - lib
126
123
  required_ruby_version: !ruby/object:Gem::Requirement
127
- none: false
128
124
  requirements:
129
- - - ! '>='
125
+ - - '>='
130
126
  - !ruby/object:Gem::Version
131
127
  version: '0'
132
128
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
129
  requirements:
135
- - - ! '>='
130
+ - - '>='
136
131
  - !ruby/object:Gem::Version
137
132
  version: '0'
138
133
  requirements: []
139
134
  rubyforge_project: chronic
140
- rubygems_version: 1.8.23
135
+ rubygems_version: 2.0.0
141
136
  signing_key:
142
- specification_version: 3
137
+ specification_version: 4
143
138
  summary: Natural language date/time parsing.
144
139
  test_files:
145
140
  - test/helper.rb
@@ -164,4 +159,3 @@ test_files:
164
159
  - test/test_repeater_year.rb
165
160
  - test/test_span.rb
166
161
  - test/test_token.rb
167
- has_rdoc: