chronic 0.6.0 → 0.7.0

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.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.md +45 -0
  3. data/README.md +7 -3
  4. data/Rakefile +3 -5
  5. data/chronic.gemspec +3 -0
  6. data/lib/chronic/chronic.rb +99 -77
  7. data/lib/chronic/grabber.rb +9 -7
  8. data/lib/chronic/handler.rb +10 -12
  9. data/lib/chronic/handlers.rb +130 -3
  10. data/lib/chronic/ordinal.rb +12 -9
  11. data/lib/chronic/pointer.rb +9 -7
  12. data/lib/chronic/repeater.rb +29 -19
  13. data/lib/chronic/repeaters/repeater_day_portion.rb +29 -15
  14. data/lib/chronic/repeaters/repeater_time.rb +19 -19
  15. data/lib/chronic/repeaters/repeater_year.rb +1 -1
  16. data/lib/chronic/scalar.rb +30 -23
  17. data/lib/chronic/season.rb +1 -12
  18. data/lib/chronic/separator.rb +21 -15
  19. data/lib/chronic/tag.rb +5 -11
  20. data/lib/chronic/time_zone.rb +11 -9
  21. data/lib/chronic/token.rb +12 -10
  22. data/lib/chronic.rb +50 -44
  23. data/test/helper.rb +8 -2
  24. data/test/{test_Chronic.rb → test_chronic.rb} +6 -6
  25. data/test/{test_DaylightSavings.rb → test_daylight_savings.rb} +1 -1
  26. data/test/{test_Handler.rb → test_handler.rb} +1 -1
  27. data/test/{test_MiniDate.rb → test_mini_date.rb} +9 -9
  28. data/test/{test_Numerizer.rb → test_numerizer.rb} +1 -1
  29. data/test/test_parsing.rb +185 -14
  30. data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +1 -1
  31. data/test/test_repeater_day_portion.rb +254 -0
  32. data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +1 -1
  33. data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +1 -1
  34. data/test/{test_RepeaterMinute.rb → test_repeater_minute.rb} +1 -1
  35. data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +1 -1
  36. data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +1 -1
  37. data/test/{test_RepeaterSeason.rb → test_repeater_season.rb} +1 -1
  38. data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +1 -1
  39. data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +1 -1
  40. data/test/{test_RepeaterWeekday.rb → test_repeater_weekday.rb} +1 -1
  41. data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +1 -1
  42. data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +1 -1
  43. data/test/{test_Span.rb → test_span.rb} +1 -1
  44. data/test/{test_Token.rb → test_token.rb} +1 -1
  45. metadata +76 -46
  46. data/.gemtest +0 -0
  47. data/.yardopts +0 -3
data/lib/chronic.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'time'
2
2
  require 'date'
3
3
 
4
- # Parse natural language dates and times into Time or {Chronic::Span} objects
4
+ # Parse natural language dates and times into Time or Chronic::Span objects.
5
+ #
6
+ # Examples:
5
7
  #
6
- # @example
7
8
  # require 'chronic'
8
9
  #
9
10
  # Time.now #=> Sun Aug 27 23:18:25 PDT 2006
@@ -25,17 +26,16 @@ require 'date'
25
26
  #
26
27
  # Chronic.parse('may 27th', :guess => false)
27
28
  # #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
28
- #
29
- # @author Tom Preston-Werner, Lee Jarvis
30
29
  module Chronic
31
- VERSION = "0.6.0"
30
+ VERSION = "0.7.0"
32
31
 
33
32
  class << self
34
33
 
35
- # @return [Boolean] true when debug mode is enabled
34
+ # Returns true when debug mode is enabled.
36
35
  attr_accessor :debug
37
36
 
38
- # @example
37
+ # Examples:
38
+ #
39
39
  # require 'chronic'
40
40
  # require 'active_support/time'
41
41
  #
@@ -44,63 +44,68 @@ module Chronic
44
44
  # Chronic.parse('June 15 2006 at 5:54 AM')
45
45
  # # => Thu, 15 Jun 2006 05:45:00 UTC +00:00
46
46
  #
47
- # @return [Time] The time class Chronic uses internally
47
+ # Returns The Time class Chronic uses internally.
48
48
  attr_accessor :time_class
49
49
 
50
- # The current Time Chronic is using to base from
50
+ # The current Time Chronic is using to base from.
51
+ #
52
+ # Examples:
51
53
  #
52
- # @example
53
54
  # Time.now #=> 2011-06-06 14:13:43 +0100
54
55
  # Chronic.parse('yesterday') #=> 2011-06-05 12:00:00 +0100
55
56
  #
56
57
  # now = Time.local(2025, 12, 24)
57
58
  # Chronic.parse('tomorrow', :now => now) #=> 2025-12-25 12:00:00 +0000
58
59
  #
59
- # @return [Time, nil]
60
+ # Returns a Time object.
60
61
  attr_accessor :now
61
62
  end
62
63
 
63
64
  self.debug = false
64
65
  self.time_class = Time
66
+
67
+ autoload :Handler, 'chronic/handler'
68
+ autoload :Handlers, 'chronic/handlers'
69
+ autoload :MiniDate, 'chronic/mini_date'
70
+ autoload :Tag, 'chronic/tag'
71
+ autoload :Span, 'chronic/span'
72
+ autoload :Token, 'chronic/token'
73
+ autoload :Grabber, 'chronic/grabber'
74
+ autoload :Pointer, 'chronic/pointer'
75
+ autoload :Scalar, 'chronic/scalar'
76
+ autoload :Ordinal, 'chronic/ordinal'
77
+ autoload :OrdinalDay, 'chronic/ordinal'
78
+ autoload :Separator, 'chronic/separator'
79
+ autoload :TimeZone, 'chronic/time_zone'
80
+ autoload :Numerizer, 'chronic/numerizer'
81
+ autoload :Season, 'chronic/season'
82
+
83
+ autoload :Repeater, 'chronic/repeater'
84
+ autoload :RepeaterYear, 'chronic/repeaters/repeater_year'
85
+ autoload :RepeaterSeason, 'chronic/repeaters/repeater_season'
86
+ autoload :RepeaterSeasonName, 'chronic/repeaters/repeater_season_name'
87
+ autoload :RepeaterMonth, 'chronic/repeaters/repeater_month'
88
+ autoload :RepeaterMonthName, 'chronic/repeaters/repeater_month_name'
89
+ autoload :RepeaterFortnight, 'chronic/repeaters/repeater_fortnight'
90
+ autoload :RepeaterWeek, 'chronic/repeaters/repeater_week'
91
+ autoload :RepeaterWeekend, 'chronic/repeaters/repeater_weekend'
92
+ autoload :RepeaterWeekday, 'chronic/repeaters/repeater_weekday'
93
+ autoload :RepeaterDay, 'chronic/repeaters/repeater_day'
94
+ autoload :RepeaterDayName, 'chronic/repeaters/repeater_day_name'
95
+ autoload :RepeaterDayPortion, 'chronic/repeaters/repeater_day_portion'
96
+ autoload :RepeaterHour, 'chronic/repeaters/repeater_hour'
97
+ autoload :RepeaterMinute, 'chronic/repeaters/repeater_minute'
98
+ autoload :RepeaterSecond, 'chronic/repeaters/repeater_second'
99
+ autoload :RepeaterTime, 'chronic/repeaters/repeater_time'
100
+
65
101
  end
66
102
 
67
103
  require 'chronic/chronic'
68
- require 'chronic/handler'
69
- require 'chronic/handlers'
70
- require 'chronic/mini_date'
71
- require 'chronic/tag'
72
- require 'chronic/span'
73
- require 'chronic/token'
74
- require 'chronic/grabber'
75
- require 'chronic/pointer'
76
- require 'chronic/scalar'
77
- require 'chronic/ordinal'
78
- require 'chronic/separator'
79
- require 'chronic/time_zone'
80
- require 'chronic/numerizer'
81
- require 'chronic/season'
82
-
83
- require 'chronic/repeater'
84
- require 'chronic/repeaters/repeater_year'
85
- require 'chronic/repeaters/repeater_season'
86
- require 'chronic/repeaters/repeater_season_name'
87
- require 'chronic/repeaters/repeater_month'
88
- require 'chronic/repeaters/repeater_month_name'
89
- require 'chronic/repeaters/repeater_fortnight'
90
- require 'chronic/repeaters/repeater_week'
91
- require 'chronic/repeaters/repeater_weekend'
92
- require 'chronic/repeaters/repeater_weekday'
93
- require 'chronic/repeaters/repeater_day'
94
- require 'chronic/repeaters/repeater_day_name'
95
- require 'chronic/repeaters/repeater_day_portion'
96
- require 'chronic/repeaters/repeater_hour'
97
- require 'chronic/repeaters/repeater_minute'
98
- require 'chronic/repeaters/repeater_second'
99
- require 'chronic/repeaters/repeater_time'
100
104
 
101
105
  class Time
106
+
102
107
  def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0)
103
- warn "Chronic.construct will be deprecated in version 0.7.0. Please use Chronic.construct instead"
108
+ warn "Time.construct will be deprecated in version 0.7.0. Please use Chronic.construct instead"
104
109
  Chronic.construct(year, month, day, hour, minute, second)
105
110
  end
106
111
 
@@ -108,4 +113,5 @@ class Time
108
113
  warn "Time.to_minidate will be deprecated in version 0.7.0. Please use Chronic::MiniDate.from_time(time) instead"
109
114
  Chronic::MiniDate.from_time(self)
110
115
  end
116
+
111
117
  end
data/test/helper.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  unless defined? Chronic
2
- $:.unshift File.expand_path('../../lib')
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'chronic'
4
4
  end
5
5
 
6
- require 'test/unit'
6
+ require 'minitest/autorun'
7
+
8
+ class TestCase < MiniTest::Unit::TestCase
9
+ def self.test(name, &block)
10
+ define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
11
+ end
12
+ end
@@ -1,12 +1,16 @@
1
1
  require 'helper'
2
2
 
3
- class TestChronic < Test::Unit::TestCase
3
+ class TestChronic < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 UTC 2006
7
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
8
  end
9
9
 
10
+ def test_pre_normalize
11
+ assert_equal Chronic.pre_normalize('12:55 pm'), Chronic.pre_normalize('12.55 pm')
12
+ end
13
+
10
14
  def test_pre_normalize_numerized_string
11
15
  string = 'two and a half years'
12
16
  assert_equal Chronic::Numerizer.numerize(string), Chronic.pre_normalize(string)
@@ -131,11 +135,7 @@ class TestChronic < Test::Unit::TestCase
131
135
  assert_equal Time.local(2004, 3, 4), Chronic.construct(2004, 2, 33)
132
136
  assert_equal Time.local(2000, 3, 4), Chronic.construct(2000, 2, 33)
133
137
 
134
- assert_nothing_raised do
135
- Chronic.construct(2006, 1, 56)
136
- end
137
-
138
- assert_raise(RuntimeError) do
138
+ assert_raises(RuntimeError) do
139
139
  Chronic.construct(2006, 1, 57)
140
140
  end
141
141
  end
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestDaylightSavings < Test::Unit::TestCase
3
+ class TestDaylightSavings < TestCase
4
4
 
5
5
  def setup
6
6
  @begin_daylight_savings = Time.local(2008, 3, 9, 5, 0, 0, 0)
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestHandler < Test::Unit::TestCase
3
+ class TestHandler < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 UTC 2006
@@ -1,32 +1,32 @@
1
1
  require 'helper'
2
2
 
3
- class TestMiniDate < Test::Unit::TestCase
3
+ class TestMiniDate < TestCase
4
4
  def test_valid_month
5
- assert_raise(ArgumentError){ Chronic::MiniDate.new(0,12) }
6
- assert_raise(ArgumentError){ Chronic::MiniDate.new(13,1) }
5
+ assert_raises(ArgumentError){ Chronic::MiniDate.new(0,12) }
6
+ assert_raises(ArgumentError){ Chronic::MiniDate.new(13,1) }
7
7
  end
8
-
8
+
9
9
  def test_is_between
10
10
  m=Chronic::MiniDate.new(3,2)
11
11
  assert m.is_between?(Chronic::MiniDate.new(2,4), Chronic::MiniDate.new(4,7))
12
- assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
13
-
12
+ assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
13
+
14
14
  #There was a hang if date tested is in december and outside the testing range
15
15
  m=Chronic::MiniDate.new(12,24)
16
16
  assert !m.is_between?(Chronic::MiniDate.new(10,1), Chronic::MiniDate.new(12,21))
17
17
  end
18
-
18
+
19
19
  def test_is_between_short_range
20
20
  m=Chronic::MiniDate.new(5,10)
21
21
  assert m.is_between?(Chronic::MiniDate.new(5,3), Chronic::MiniDate.new(5,12))
22
22
  assert !m.is_between?(Chronic::MiniDate.new(5,11), Chronic::MiniDate.new(5,15))
23
23
  end
24
-
24
+
25
25
  def test_is_between_wrapping_range
26
26
  m=Chronic::MiniDate.new(1,1)
27
27
  assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(2,2))
28
28
  m=Chronic::MiniDate.new(12,12)
29
29
  assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(1,5))
30
30
  end
31
-
31
+
32
32
  end
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class ParseNumbersTest < Test::Unit::TestCase
3
+ class ParseNumbersTest < TestCase
4
4
 
5
5
  def test_straight_parsing
6
6
  strings = {
data/test/test_parsing.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestParsing < Test::Unit::TestCase
3
+ class TestParsing < TestCase
4
4
  # Wed Aug 16 14:00:00 UTC 2006
5
5
  TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
6
6
 
@@ -76,6 +76,22 @@ class TestParsing < Test::Unit::TestCase
76
76
  assert_equal Time.local(2006, 12, 11, 8), time
77
77
  end
78
78
 
79
+ def test_handle_sy_rmn_od
80
+ time = parse_now("2009 May 22nd")
81
+ assert_equal Time.local(2009, 05, 22, 12), time
82
+ end
83
+
84
+ def test_handle_sd_rmn
85
+ time = parse_now("22 February")
86
+ assert_equal Time.local(2007, 2, 22, 12), time
87
+
88
+ time = parse_now("31 of may at 6:30pm")
89
+ assert_equal Time.local(2007, 5, 31, 18, 30), time
90
+
91
+ time = parse_now("11 december 8am")
92
+ assert_equal Time.local(2006, 12, 11, 8), time
93
+ end
94
+
79
95
  def test_handle_rmn_od_on
80
96
  time = parse_now("5:00 pm may 27th", :context => :past)
81
97
  assert_equal Time.local(2006, 5, 27, 17), time
@@ -109,6 +125,12 @@ class TestParsing < Test::Unit::TestCase
109
125
  def test_handle_sy_sm_sd_t_tz
110
126
  time = parse_now("2011-07-03 22:11:35 +0100")
111
127
  assert_equal 1309727495, time.to_i
128
+
129
+ time = parse_now("2011-07-03 22:11:35 +01:00")
130
+ assert_equal 1309727495, time.to_i
131
+
132
+ time = parse_now("2011-07-03 21:11:35 UTC")
133
+ assert_equal 1309727495, time.to_i
112
134
  end
113
135
 
114
136
  def test_handle_rmn_sd_sy
@@ -210,6 +232,15 @@ class TestParsing < Test::Unit::TestCase
210
232
  time = parse_now("5/27/1979 4am")
211
233
  assert_equal Time.local(1979, 5, 27, 4), time
212
234
 
235
+ time = parse_now("7/12/11")
236
+ assert_equal Time.local(2011, 7, 12, 12), time
237
+
238
+ time = parse_now("7/12/11", :endian_precedence => :little)
239
+ assert_equal Time.local(2011, 12, 7, 12), time
240
+
241
+ time = parse_now("9/19/2011 6:05:57 PM")
242
+ assert_equal Time.local(2011, 9, 19, 18, 05, 57), time
243
+
213
244
  # month day overflows
214
245
  time = parse_now("30/2/2000")
215
246
  assert_nil time
@@ -221,6 +252,9 @@ class TestParsing < Test::Unit::TestCase
221
252
 
222
253
  time = parse_now("27/5/1979 @ 0700")
223
254
  assert_equal Time.local(1979, 5, 27, 7), time
255
+
256
+ time = parse_now("03/18/2012 09:26 pm")
257
+ assert_equal Time.local(2012, 3, 18, 21, 26), time
224
258
  end
225
259
 
226
260
  def test_handle_sy_sm_sd
@@ -247,19 +281,34 @@ class TestParsing < Test::Unit::TestCase
247
281
 
248
282
  time = parse_now("1902-08-20")
249
283
  assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
284
+
285
+ # exif date time original
286
+ time = parse_now("2012:05:25 22:06:50")
287
+ assert_equal Time.local(2012, 5, 25, 22, 6, 50), time
250
288
  end
251
289
 
252
- def test_handle_sm_sy
290
+ def test_handle_sm_sd
253
291
  time = parse_now("05/06")
254
- assert_equal Time.local(2006, 5, 16, 12), time
292
+ assert_equal Time.local(2006, 5, 6, 12), time
255
293
 
256
- time = parse_now("12/06")
257
- assert_equal Time.local(2006, 12, 16, 12), time
294
+ time = parse_now("05/06", :endian_precedence => [:little, :medium])
295
+ assert_equal Time.local(2006, 6, 5, 12), time
258
296
 
259
- time = parse_now("13/06")
260
- assert_equal nil, time
297
+ time = parse_now("13/01")
298
+ assert_nil time
261
299
  end
262
300
 
301
+ # def test_handle_sm_sy
302
+ # time = parse_now("05/06")
303
+ # assert_equal Time.local(2006, 5, 16, 12), time
304
+ #
305
+ # time = parse_now("12/06")
306
+ # assert_equal Time.local(2006, 12, 16, 12), time
307
+ #
308
+ # time = parse_now("13/06")
309
+ # assert_equal nil, time
310
+ # end
311
+
263
312
  def test_handle_r
264
313
  end
265
314
 
@@ -279,6 +328,19 @@ class TestParsing < Test::Unit::TestCase
279
328
  end
280
329
 
281
330
  def test_handle_orr
331
+ time = parse_now("5th tuesday in january")
332
+ assert_equal Time.local(2007, 01, 30, 12), time
333
+
334
+ time = parse_now("5th tuesday in february")
335
+ assert_equal nil, time
336
+
337
+ %W(jan feb march april may june july aug sep oct nov dec).each_with_index do |month, index|
338
+ time = parse_now("5th tuesday in #{month}")
339
+
340
+ if time then
341
+ assert_equal time.month, index+1
342
+ end
343
+ end
282
344
  end
283
345
 
284
346
  def test_handle_o_r_s_r
@@ -310,6 +372,11 @@ class TestParsing < Test::Unit::TestCase
310
372
  assert_equal Time.local(2006, 8, 9, 12), time
311
373
  end
312
374
 
375
+ def test_handle_sm_rmn_sy
376
+ time = parse_now('30-Mar-11')
377
+ assert_equal Time.local(2011, 3, 30, 12), time
378
+ end
379
+
313
380
  # end of testing handlers
314
381
 
315
382
  def test_parse_guess_r
@@ -405,11 +472,11 @@ class TestParsing < Test::Unit::TestCase
405
472
  def test_parse_guess_gr
406
473
  # year
407
474
 
408
- time = parse_now("this year")
409
- assert_equal Time.local(2006, 10, 24, 12, 30), time
475
+ time = parse_now("this year", :guess => false)
476
+ assert_equal Time.local(2006, 8, 17), time.begin
410
477
 
411
- time = parse_now("this year", :context => :past)
412
- assert_equal Time.local(2006, 4, 24, 12, 30), time
478
+ time = parse_now("this year", :context => :past, :guess => false)
479
+ assert_equal Time.local(2006, 1, 1), time.begin
413
480
 
414
481
  # month
415
482
 
@@ -495,6 +562,34 @@ class TestParsing < Test::Unit::TestCase
495
562
  time = parse_now("last wed")
496
563
  assert_equal Time.local(2006, 8, 9, 12), time
497
564
 
565
+ monday = Time.local(2006, 8, 21, 12)
566
+ assert_equal monday, parse_now("mon")
567
+ assert_equal monday, parse_now("mun")
568
+
569
+ tuesday = Time.local(2006, 8, 22, 12)
570
+ assert_equal tuesday, parse_now("tue")
571
+ assert_equal tuesday, parse_now("tus")
572
+
573
+ wednesday = Time.local(2006, 8, 23, 12)
574
+ assert_equal wednesday, parse_now("wed")
575
+ assert_equal wednesday, parse_now("wenns")
576
+
577
+ thursday = Time.local(2006, 8, 17, 12)
578
+ assert_equal thursday, parse_now("thu")
579
+ assert_equal thursday, parse_now("thur")
580
+
581
+ friday = Time.local(2006, 8, 18, 12)
582
+ assert_equal friday, parse_now("fri")
583
+ assert_equal friday, parse_now("fry")
584
+
585
+ saturday = Time.local(2006, 8, 19, 12)
586
+ assert_equal saturday, parse_now("sat")
587
+ assert_equal saturday, parse_now("satterday")
588
+
589
+ sunday = Time.local(2006, 8, 20, 12)
590
+ assert_equal sunday, parse_now("sun")
591
+ assert_equal sunday, parse_now("sum")
592
+
498
593
  # day portion
499
594
 
500
595
  time = parse_now("this morning")
@@ -503,13 +598,33 @@ class TestParsing < Test::Unit::TestCase
503
598
  time = parse_now("tonight")
504
599
  assert_equal Time.local(2006, 8, 16, 22), time
505
600
 
601
+ # hour
602
+
603
+ time = parse_now("next hr")
604
+ assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
605
+
606
+ time = parse_now("next hrs")
607
+ assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
608
+
506
609
  # minute
507
610
 
611
+ time = parse_now("next min")
612
+ assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
613
+
614
+ time = parse_now("next mins")
615
+ assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
616
+
508
617
  time = parse_now("next minute")
509
618
  assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
510
619
 
511
620
  # second
512
621
 
622
+ time = parse_now("next sec")
623
+ assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
624
+
625
+ time = parse_now("next secs")
626
+ assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
627
+
513
628
  time = parse_now("this second")
514
629
  assert_equal Time.local(2006, 8, 16, 14), time
515
630
 
@@ -602,6 +717,20 @@ class TestParsing < Test::Unit::TestCase
602
717
  assert_equal Time.local(2006, 8, 8, 12), time
603
718
  end
604
719
 
720
+ def test_parse_guess_a_ago
721
+ time = parse_now("AN hour ago")
722
+ assert_equal Time.local(2006, 8, 16, 13), time
723
+
724
+ time = parse_now("A day ago")
725
+ assert_equal Time.local(2006, 8, 15, 14), time
726
+
727
+ time = parse_now("a month ago")
728
+ assert_equal Time.local(2006, 7, 16, 14), time
729
+
730
+ time = parse_now("a year ago")
731
+ assert_equal Time.local(2005, 8, 16, 14), time
732
+ end
733
+
605
734
  def test_parse_guess_s_r_p
606
735
  # past
607
736
 
@@ -764,6 +893,7 @@ class TestParsing < Test::Unit::TestCase
764
893
  assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
765
894
  assert_equal parse_now("2867532 seconds from now"), parse_now("two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now")
766
895
  assert_equal parse_now("may 10th"), parse_now("may tenth")
896
+ assert_equal parse_now("second monday in january"), parse_now("2nd monday in january")
767
897
  end
768
898
 
769
899
  def test_parse_only_complete_pointers
@@ -783,11 +913,11 @@ class TestParsing < Test::Unit::TestCase
783
913
  end
784
914
 
785
915
  def test_argument_validation
786
- assert_raise(ArgumentError) do
916
+ assert_raises(ArgumentError) do
787
917
  time = Chronic.parse("may 27", :foo => :bar)
788
918
  end
789
919
 
790
- assert_raise(ArgumentError) do
920
+ assert_raises(ArgumentError) do
791
921
  time = Chronic.parse("may 27", :context => :bar)
792
922
  end
793
923
  end
@@ -843,7 +973,48 @@ class TestParsing < Test::Unit::TestCase
843
973
  t1 = Chronic.parse("now")
844
974
  sleep 0.1
845
975
  t2 = Chronic.parse("now")
846
- assert_not_equal t1, t2
976
+ refute_equal t1, t2
977
+ end
978
+
979
+ def test_noon
980
+ t1 = Chronic.parse('2011-01-01 at noon', :ambiguous_time_range => :none)
981
+ assert_equal Time.local(2011, 1, 1, 12, 0), t1
982
+ end
983
+
984
+ def test_handle_rdn_rmn_sd
985
+ time = parse_now("Thu Aug 10")
986
+ assert_equal Time.local(2006, 8, 10, 12), time
987
+
988
+ time = parse_now("Thursday July 31")
989
+ assert_equal Time.local(2006, 7, 31, 12), time
990
+
991
+ time = parse_now("Thursday December 31")
992
+ assert_equal Time.local(2006, 12, 31, 12), time
993
+ end
994
+
995
+ def test_handle_rdn_rmn_sd_sy
996
+ time = parse_now("Thu Aug 10 2006")
997
+ assert_equal Time.local(2006, 8, 10, 12), time
998
+
999
+ time = parse_now("Thursday July 31 2006")
1000
+ assert_equal Time.local(2006, 7, 31, 12), time
1001
+
1002
+ time = parse_now("Thursday December 31 2006")
1003
+ assert_equal Time.local(2006, 12, 31, 12), time
1004
+
1005
+ time = parse_now("Thursday December 30 2006")
1006
+ assert_equal Time.local(2006, 12, 30, 12), time
1007
+ end
1008
+
1009
+ def test_handle_rdn_rmn_od
1010
+ time = parse_now("Thu Aug 10th")
1011
+ assert_equal Time.local(2006, 8, 10, 12), time
1012
+
1013
+ time = parse_now("Thursday July 31st")
1014
+ assert_equal Time.local(2006, 7, 31, 12), time
1015
+
1016
+ time = parse_now("Thursday December 31st")
1017
+ assert_equal Time.local(2006, 12, 31, 12), time
847
1018
  end
848
1019
 
849
1020
  private
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterDayName < Test::Unit::TestCase
3
+ class TestRepeaterDayName < TestCase
4
4
 
5
5
  def setup
6
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)