slaxor-chronic 0.3.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.
Files changed (55) hide show
  1. data/HISTORY.md +76 -0
  2. data/LICENSE +21 -0
  3. data/Manifest.txt +47 -0
  4. data/README.md +165 -0
  5. data/Rakefile +146 -0
  6. data/benchmark/benchmark.rb +13 -0
  7. data/lib/chronic.rb +127 -0
  8. data/lib/chronic/chronic.rb +249 -0
  9. data/lib/chronic/grabber.rb +26 -0
  10. data/lib/chronic/handlers.rb +524 -0
  11. data/lib/chronic/numerizer/numerizer.rb +97 -0
  12. data/lib/chronic/ordinal.rb +40 -0
  13. data/lib/chronic/pointer.rb +27 -0
  14. data/lib/chronic/repeater.rb +129 -0
  15. data/lib/chronic/repeaters/repeater_day.rb +52 -0
  16. data/lib/chronic/repeaters/repeater_day_name.rb +51 -0
  17. data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
  18. data/lib/chronic/repeaters/repeater_fortnight.rb +70 -0
  19. data/lib/chronic/repeaters/repeater_hour.rb +57 -0
  20. data/lib/chronic/repeaters/repeater_minute.rb +57 -0
  21. data/lib/chronic/repeaters/repeater_month.rb +66 -0
  22. data/lib/chronic/repeaters/repeater_month_name.rb +98 -0
  23. data/lib/chronic/repeaters/repeater_season.rb +150 -0
  24. data/lib/chronic/repeaters/repeater_season_name.rb +45 -0
  25. data/lib/chronic/repeaters/repeater_second.rb +41 -0
  26. data/lib/chronic/repeaters/repeater_time.rb +124 -0
  27. data/lib/chronic/repeaters/repeater_week.rb +73 -0
  28. data/lib/chronic/repeaters/repeater_weekday.rb +77 -0
  29. data/lib/chronic/repeaters/repeater_weekend.rb +65 -0
  30. data/lib/chronic/repeaters/repeater_year.rb +64 -0
  31. data/lib/chronic/scalar.rb +76 -0
  32. data/lib/chronic/separator.rb +91 -0
  33. data/lib/chronic/time_zone.rb +23 -0
  34. data/slaxor-chronic.gemspec +85 -0
  35. data/test/helper.rb +7 -0
  36. data/test/test_Chronic.rb +49 -0
  37. data/test/test_DaylightSavings.rb +118 -0
  38. data/test/test_Handler.rb +109 -0
  39. data/test/test_Numerizer.rb +51 -0
  40. data/test/test_RepeaterDayName.rb +51 -0
  41. data/test/test_RepeaterFortnight.rb +62 -0
  42. data/test/test_RepeaterHour.rb +64 -0
  43. data/test/test_RepeaterMinute.rb +34 -0
  44. data/test/test_RepeaterMonth.rb +46 -0
  45. data/test/test_RepeaterMonthName.rb +56 -0
  46. data/test/test_RepeaterTime.rb +70 -0
  47. data/test/test_RepeaterWeek.rb +62 -0
  48. data/test/test_RepeaterWeekday.rb +55 -0
  49. data/test/test_RepeaterWeekend.rb +74 -0
  50. data/test/test_RepeaterYear.rb +62 -0
  51. data/test/test_Span.rb +23 -0
  52. data/test/test_Time.rb +49 -0
  53. data/test/test_Token.rb +25 -0
  54. data/test/test_parsing.rb +710 -0
  55. metadata +138 -0
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestRepeaterTime < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_next_future
11
+ t = Chronic::RepeaterTime.new('4:00')
12
+ t.start = @now
13
+
14
+ assert_equal Time.local(2006, 8, 16, 16), t.next(:future).begin
15
+ assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
16
+
17
+ t = Chronic::RepeaterTime.new('13:00')
18
+ t.start = @now
19
+
20
+ assert_equal Time.local(2006, 8, 17, 13), t.next(:future).begin
21
+ assert_equal Time.local(2006, 8, 18, 13), t.next(:future).begin
22
+
23
+ t = Chronic::RepeaterTime.new('0400')
24
+ t.start = @now
25
+
26
+ assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
27
+ assert_equal Time.local(2006, 8, 18, 4), t.next(:future).begin
28
+ end
29
+
30
+ def test_next_past
31
+ t = Chronic::RepeaterTime.new('4:00')
32
+ t.start = @now
33
+
34
+ assert_equal Time.local(2006, 8, 16, 4), t.next(:past).begin
35
+ assert_equal Time.local(2006, 8, 15, 16), t.next(:past).begin
36
+
37
+ t = Chronic::RepeaterTime.new('13:00')
38
+ t.start = @now
39
+
40
+ assert_equal Time.local(2006, 8, 16, 13), t.next(:past).begin
41
+ assert_equal Time.local(2006, 8, 15, 13), t.next(:past).begin
42
+ end
43
+
44
+ def test_type
45
+ t1 = Chronic::RepeaterTime.new('4')
46
+ assert_equal 14_400, t1.type.time
47
+
48
+ t1 = Chronic::RepeaterTime.new('14')
49
+ assert_equal 50_400, t1.type.time
50
+
51
+ t1 = Chronic::RepeaterTime.new('4:00')
52
+ assert_equal 14_400, t1.type.time
53
+
54
+ t1 = Chronic::RepeaterTime.new('4:30')
55
+ assert_equal 16_200, t1.type.time
56
+
57
+ t1 = Chronic::RepeaterTime.new('1400')
58
+ assert_equal 50_400, t1.type.time
59
+
60
+ t1 = Chronic::RepeaterTime.new('0400')
61
+ assert_equal 14_400, t1.type.time
62
+
63
+ t1 = Chronic::RepeaterTime.new('04')
64
+ assert_equal 14_400, t1.type.time
65
+
66
+ t1 = Chronic::RepeaterTime.new('400')
67
+ assert_equal 14_400, t1.type.time
68
+ end
69
+
70
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestRepeaterWeek < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ weeks = Chronic::RepeaterWeek.new(:week)
11
+ weeks.start = @now
12
+
13
+ next_week = weeks.next(:future)
14
+ assert_equal Time.local(2006, 8, 20), next_week.begin
15
+ assert_equal Time.local(2006, 8, 27), next_week.end
16
+
17
+ next_next_week = weeks.next(:future)
18
+ assert_equal Time.local(2006, 8, 27), next_next_week.begin
19
+ assert_equal Time.local(2006, 9, 3), next_next_week.end
20
+ end
21
+
22
+ def test_next_past
23
+ weeks = Chronic::RepeaterWeek.new(:week)
24
+ weeks.start = @now
25
+
26
+ last_week = weeks.next(:past)
27
+ assert_equal Time.local(2006, 8, 6), last_week.begin
28
+ assert_equal Time.local(2006, 8, 13), last_week.end
29
+
30
+ last_last_week = weeks.next(:past)
31
+ assert_equal Time.local(2006, 7, 30), last_last_week.begin
32
+ assert_equal Time.local(2006, 8, 6), last_last_week.end
33
+ end
34
+
35
+ def test_this_future
36
+ weeks = Chronic::RepeaterWeek.new(:week)
37
+ weeks.start = @now
38
+
39
+ this_week = weeks.this(:future)
40
+ assert_equal Time.local(2006, 8, 16, 15), this_week.begin
41
+ assert_equal Time.local(2006, 8, 20), this_week.end
42
+ end
43
+
44
+ def test_this_past
45
+ weeks = Chronic::RepeaterWeek.new(:week)
46
+ weeks.start = @now
47
+
48
+ this_week = weeks.this(:past)
49
+ assert_equal Time.local(2006, 8, 13, 0), this_week.begin
50
+ assert_equal Time.local(2006, 8, 16, 14), this_week.end
51
+ end
52
+
53
+ def test_offset
54
+ span = Chronic::Span.new(@now, @now + 1)
55
+
56
+ offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
57
+
58
+ assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
59
+ assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
60
+ end
61
+
62
+ end
@@ -0,0 +1,55 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestRepeaterWeekday < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2007, 6, 11, 14, 0, 0, 0) # Mon
7
+ end
8
+
9
+ def test_next_future
10
+ weekdays = Chronic::RepeaterWeekday.new(:weekday)
11
+ weekdays.start = @now
12
+
13
+ next1_weekday = weekdays.next(:future) # Tues
14
+ assert_equal Time.local(2007, 6, 12), next1_weekday.begin
15
+ assert_equal Time.local(2007, 6, 13), next1_weekday.end
16
+
17
+ next2_weekday = weekdays.next(:future) # Wed
18
+ assert_equal Time.local(2007, 6, 13), next2_weekday.begin
19
+ assert_equal Time.local(2007, 6, 14), next2_weekday.end
20
+
21
+ next3_weekday = weekdays.next(:future) # Thurs
22
+ assert_equal Time.local(2007, 6, 14), next3_weekday.begin
23
+ assert_equal Time.local(2007, 6, 15), next3_weekday.end
24
+
25
+ next4_weekday = weekdays.next(:future) # Fri
26
+ assert_equal Time.local(2007, 6, 15), next4_weekday.begin
27
+ assert_equal Time.local(2007, 6, 16), next4_weekday.end
28
+
29
+ next5_weekday = weekdays.next(:future) # Mon
30
+ assert_equal Time.local(2007, 6, 18), next5_weekday.begin
31
+ assert_equal Time.local(2007, 6, 19), next5_weekday.end
32
+ end
33
+
34
+ def test_next_past
35
+ weekdays = Chronic::RepeaterWeekday.new(:weekday)
36
+ weekdays.start = @now
37
+
38
+ last1_weekday = weekdays.next(:past) # Fri
39
+ assert_equal Time.local(2007, 6, 8), last1_weekday.begin
40
+ assert_equal Time.local(2007, 6, 9), last1_weekday.end
41
+
42
+ last2_weekday = weekdays.next(:past) # Thurs
43
+ assert_equal Time.local(2007, 6, 7), last2_weekday.begin
44
+ assert_equal Time.local(2007, 6, 8), last2_weekday.end
45
+ end
46
+
47
+ def test_offset
48
+ span = Chronic::Span.new(@now, @now + 1)
49
+
50
+ offset_span = Chronic::RepeaterWeekday.new(:weekday).offset(span, 5, :future)
51
+
52
+ assert_equal Time.local(2007, 6, 18, 14), offset_span.begin
53
+ assert_equal Time.local(2007, 6, 18, 14, 0, 1), offset_span.end
54
+ end
55
+ end
@@ -0,0 +1,74 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestRepeaterWeekend < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_next_future
11
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
12
+ weekend.start = @now
13
+
14
+ next_weekend = weekend.next(:future)
15
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
16
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
17
+ end
18
+
19
+ def test_next_past
20
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
21
+ weekend.start = @now
22
+
23
+ next_weekend = weekend.next(:past)
24
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
25
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
26
+ end
27
+
28
+ def test_this_future
29
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
30
+ weekend.start = @now
31
+
32
+ next_weekend = weekend.this(:future)
33
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
34
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
35
+ end
36
+
37
+ def test_this_past
38
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
39
+ weekend.start = @now
40
+
41
+ next_weekend = weekend.this(:past)
42
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
43
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
44
+ end
45
+
46
+ def test_this_none
47
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
48
+ weekend.start = @now
49
+
50
+ next_weekend = weekend.this(:future)
51
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
52
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
53
+ end
54
+
55
+ def test_offset
56
+ span = Chronic::Span.new(@now, @now + 1)
57
+
58
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
59
+
60
+ assert_equal Time.local(2006, 9, 2), offset_span.begin
61
+ assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
62
+
63
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
64
+
65
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
66
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
67
+
68
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
69
+
70
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
71
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
72
+ end
73
+
74
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestRepeaterYear < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ years = Chronic::RepeaterYear.new(:year)
11
+ years.start = @now
12
+
13
+ next_year = years.next(:future)
14
+ assert_equal Time.local(2007, 1, 1), next_year.begin
15
+ assert_equal Time.local(2008, 1, 1), next_year.end
16
+
17
+ next_next_year = years.next(:future)
18
+ assert_equal Time.local(2008, 1, 1), next_next_year.begin
19
+ assert_equal Time.local(2009, 1, 1), next_next_year.end
20
+ end
21
+
22
+ def test_next_past
23
+ years = Chronic::RepeaterYear.new(:year)
24
+ years.start = @now
25
+
26
+ last_year = years.next(:past)
27
+ assert_equal Time.local(2005, 1, 1), last_year.begin
28
+ assert_equal Time.local(2006, 1, 1), last_year.end
29
+
30
+ last_last_year = years.next(:past)
31
+ assert_equal Time.local(2004, 1, 1), last_last_year.begin
32
+ assert_equal Time.local(2005, 1, 1), last_last_year.end
33
+ end
34
+
35
+ def test_this
36
+ years = Chronic::RepeaterYear.new(:year)
37
+ years.start = @now
38
+
39
+ this_year = years.this(:future)
40
+ assert_equal Time.local(2006, 8, 17), this_year.begin
41
+ assert_equal Time.local(2007, 1, 1), this_year.end
42
+
43
+ this_year = years.this(:past)
44
+ assert_equal Time.local(2006, 1, 1), this_year.begin
45
+ assert_equal Time.local(2006, 8, 16), this_year.end
46
+ end
47
+
48
+ def test_offset
49
+ span = Chronic::Span.new(@now, @now + 1)
50
+
51
+ offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
52
+
53
+ assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
54
+ assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
55
+
56
+ offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
57
+
58
+ assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
59
+ assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
60
+ end
61
+
62
+ end
data/test/test_Span.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestSpan < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 UTC 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_span_width
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
13
+ end
14
+
15
+ def test_span_math
16
+ s = Chronic::Span.new(1, 2)
17
+ assert_equal 2, (s + 1).begin
18
+ assert_equal 3, (s + 1).end
19
+ assert_equal 0, (s - 1).begin
20
+ assert_equal 1, (s - 1).end
21
+ end
22
+
23
+ end
data/test/test_Time.rb ADDED
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestTime < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_normal
9
+ assert_equal Time.local(2006, 1, 2, 0, 0, 0), Time.construct(2006, 1, 2, 0, 0, 0)
10
+ assert_equal Time.local(2006, 1, 2, 3, 0, 0), Time.construct(2006, 1, 2, 3, 0, 0)
11
+ assert_equal Time.local(2006, 1, 2, 3, 4, 0), Time.construct(2006, 1, 2, 3, 4, 0)
12
+ assert_equal Time.local(2006, 1, 2, 3, 4, 5), Time.construct(2006, 1, 2, 3, 4, 5)
13
+ end
14
+
15
+ def test_second_overflow
16
+ assert_equal Time.local(2006, 1, 1, 0, 1, 30), Time.construct(2006, 1, 1, 0, 0, 90)
17
+ assert_equal Time.local(2006, 1, 1, 0, 5, 0), Time.construct(2006, 1, 1, 0, 0, 300)
18
+ end
19
+
20
+ def test_minute_overflow
21
+ assert_equal Time.local(2006, 1, 1, 1, 30), Time.construct(2006, 1, 1, 0, 90)
22
+ assert_equal Time.local(2006, 1, 1, 5), Time.construct(2006, 1, 1, 0, 300)
23
+ end
24
+
25
+ def test_hour_overflow
26
+ assert_equal Time.local(2006, 1, 2, 12), Time.construct(2006, 1, 1, 36)
27
+ assert_equal Time.local(2006, 1, 7), Time.construct(2006, 1, 1, 144)
28
+ end
29
+
30
+ def test_day_overflow
31
+ assert_equal Time.local(2006, 2, 1), Time.construct(2006, 1, 32)
32
+ assert_equal Time.local(2006, 3, 5), Time.construct(2006, 2, 33)
33
+ assert_equal Time.local(2004, 3, 4), Time.construct(2004, 2, 33)
34
+ assert_equal Time.local(2000, 3, 5), Time.construct(2000, 2, 33)
35
+
36
+ assert_nothing_raised do
37
+ Time.construct(2006, 1, 56)
38
+ end
39
+
40
+ assert_raise(RuntimeError) do
41
+ Time.construct(2006, 1, 57)
42
+ end
43
+ end
44
+
45
+ def test_month_overflow
46
+ assert_equal Time.local(2006, 1), Time.construct(2005, 13)
47
+ assert_equal Time.local(2005, 12), Time.construct(2000, 72)
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestToken < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 UTC 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_token
11
+ token = Chronic::Token.new('foo')
12
+ assert_equal 0, token.tags.size
13
+ assert !token.tagged?
14
+ token.tag("mytag")
15
+ assert_equal 1, token.tags.size
16
+ assert token.tagged?
17
+ assert_equal String, token.get_tag(String).class
18
+ token.tag(5)
19
+ assert_equal 2, token.tags.size
20
+ token.untag(String)
21
+ assert_equal 1, token.tags.size
22
+ assert_equal 'foo', token.word
23
+ end
24
+
25
+ end
@@ -0,0 +1,710 @@
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
2
+
3
+ class TestParsing < Test::Unit::TestCase
4
+ # Wed Aug 16 14:00:00 UTC 2006
5
+ TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
6
+
7
+ def setup
8
+ @time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
9
+ end
10
+
11
+ def test_parse_guess_dates
12
+ # rm_sd
13
+
14
+ time = parse_now("may 27")
15
+ assert_equal Time.local(2007, 5, 27, 12), time
16
+
17
+ time = parse_now("may 28", :context => :past)
18
+ assert_equal Time.local(2006, 5, 28, 12), time
19
+
20
+ time = parse_now("may 28 5pm", :context => :past)
21
+ assert_equal Time.local(2006, 5, 28, 17), time
22
+
23
+ time = parse_now("may 28 at 5pm", :context => :past)
24
+ assert_equal Time.local(2006, 5, 28, 17), time
25
+
26
+ time = parse_now("may 28 at 5:32.19pm", :context => :past)
27
+ assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
28
+
29
+ # rm_sd_on
30
+
31
+ time = parse_now("5pm on may 28")
32
+ assert_equal Time.local(2007, 5, 28, 17), time
33
+
34
+ time = parse_now("5pm may 28")
35
+ assert_equal Time.local(2007, 5, 28, 17), time
36
+
37
+ time = parse_now("5 on may 28", :ambiguous_time_range => :none)
38
+ assert_equal Time.local(2007, 5, 28, 05), time
39
+
40
+ # rm_od
41
+
42
+ time = parse_now("may 27th")
43
+ assert_equal Time.local(2007, 5, 27, 12), time
44
+
45
+ time = parse_now("may 27th", :context => :past)
46
+ assert_equal Time.local(2006, 5, 27, 12), time
47
+
48
+ time = parse_now("may 27th 5:00 pm", :context => :past)
49
+ assert_equal Time.local(2006, 5, 27, 17), time
50
+
51
+ time = parse_now("may 27th at 5pm", :context => :past)
52
+ assert_equal Time.local(2006, 5, 27, 17), time
53
+
54
+ time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
55
+ assert_equal Time.local(2007, 5, 27, 5), time
56
+
57
+ # rm_od_on
58
+
59
+ time = parse_now("5:00 pm may 27th", :context => :past)
60
+ assert_equal Time.local(2006, 5, 27, 17), time
61
+
62
+ time = parse_now("5pm on may 27th", :context => :past)
63
+ assert_equal Time.local(2006, 5, 27, 17), time
64
+
65
+ time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
66
+ assert_equal Time.local(2007, 5, 27, 5), time
67
+
68
+ # rm_sy
69
+
70
+ time = parse_now("June 1979")
71
+ assert_equal Time.local(1979, 6, 16, 0), time
72
+
73
+ time = parse_now("dec 79")
74
+ assert_equal Time.local(1979, 12, 16, 12), time
75
+
76
+ # rm_sd_sy
77
+
78
+ time = parse_now("jan 3 2010")
79
+ assert_equal Time.local(2010, 1, 3, 12), time
80
+
81
+ time = parse_now("jan 3 2010 midnight")
82
+ assert_equal Time.local(2010, 1, 4, 0), time
83
+
84
+ time = parse_now("jan 3 2010 at midnight")
85
+ assert_equal Time.local(2010, 1, 4, 0), time
86
+
87
+ time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
88
+ assert_equal Time.local(2010, 1, 3, 4), time
89
+
90
+ #time = parse_now("January 12, '00")
91
+ #assert_equal Time.local(2000, 1, 12, 12), time
92
+
93
+ time = parse_now("may 27, 1979")
94
+ assert_equal Time.local(1979, 5, 27, 12), time
95
+
96
+ time = parse_now("may 27 79")
97
+ assert_equal Time.local(1979, 5, 27, 12), time
98
+
99
+ time = parse_now("may 27 79 4:30")
100
+ assert_equal Time.local(1979, 5, 27, 16, 30), time
101
+
102
+ time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
103
+ assert_equal Time.local(1979, 5, 27, 4, 30), time
104
+
105
+ # sd_rm_sy
106
+
107
+ time = parse_now("3 jan 2010")
108
+ assert_equal Time.local(2010, 1, 3, 12), time
109
+
110
+ time = parse_now("3 jan 2010 4pm")
111
+ assert_equal Time.local(2010, 1, 3, 16), time
112
+
113
+ time = parse_now("27 Oct 2006 7:30pm")
114
+ assert_equal Time.local(2006, 10, 27, 19, 30), time
115
+
116
+ # sm_sd_sy
117
+
118
+ time = parse_now("5/27/1979")
119
+ assert_equal Time.local(1979, 5, 27, 12), time
120
+
121
+ time = parse_now("5/27/1979 4am")
122
+ assert_equal Time.local(1979, 5, 27, 4), time
123
+
124
+ # sd_sm_sy
125
+
126
+ time = parse_now("27/5/1979")
127
+ assert_equal Time.local(1979, 5, 27, 12), time
128
+
129
+ time = parse_now("27/5/1979 @ 0700")
130
+ assert_equal Time.local(1979, 5, 27, 7), time
131
+
132
+ # sm_sy
133
+
134
+ time = parse_now("05/06")
135
+ assert_equal Time.local(2006, 5, 16, 12), time
136
+
137
+ time = parse_now("12/06")
138
+ assert_equal Time.local(2006, 12, 16, 12), time
139
+
140
+ time = parse_now("13/06")
141
+ assert_equal nil, time
142
+
143
+ # sy_sm_sd
144
+
145
+ time = parse_now("2000-1-1")
146
+ assert_equal Time.local(2000, 1, 1, 12), time
147
+
148
+ time = parse_now("2006-08-20")
149
+ assert_equal Time.local(2006, 8, 20, 12), time
150
+
151
+ time = parse_now("2006-08-20 7pm")
152
+ assert_equal Time.local(2006, 8, 20, 19), time
153
+
154
+ time = parse_now("2006-08-20 03:00")
155
+ assert_equal Time.local(2006, 8, 20, 3), time
156
+
157
+ time = parse_now("2006-08-20 03:30:30")
158
+ assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
159
+
160
+ time = parse_now("2006-08-20 15:30:30")
161
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
162
+
163
+ time = parse_now("2006-08-20 15:30.30")
164
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
165
+
166
+ # rdn_rm_rd_rt_rtz_ry
167
+
168
+ time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
169
+ assert_equal 1175558400, time.to_i
170
+
171
+ now = Time.now
172
+ time = parse_now(now.to_s)
173
+ assert_equal now.to_s, time.to_s
174
+
175
+ # rm_sd_rt
176
+
177
+ #time = parse_now("jan 5 13:00")
178
+ #assert_equal Time.local(2007, 1, 5, 13), time
179
+
180
+ # old dates
181
+
182
+ time = parse_now("may 40")
183
+ assert_equal Time.local(40, 5, 16, 12, 0, 0), time
184
+
185
+ time = parse_now("may 27 40")
186
+ assert_equal Time.local(40, 5, 27, 12, 0, 0), time
187
+
188
+ time = parse_now("1800-08-20")
189
+ assert_equal Time.local(1800, 8, 20, 12, 0, 0), time
190
+ end
191
+
192
+ def test_parse_guess_r
193
+ time = parse_now("friday")
194
+ assert_equal Time.local(2006, 8, 18, 12), time
195
+
196
+ time = parse_now("tue")
197
+ assert_equal Time.local(2006, 8, 22, 12), time
198
+
199
+ time = parse_now("5")
200
+ assert_equal Time.local(2006, 8, 16, 17), time
201
+
202
+ time = Chronic.parse("5", :now => Time.local(2006, 8, 16, 3, 0, 0, 0), :ambiguous_time_range => :none)
203
+ assert_equal Time.local(2006, 8, 16, 5), time
204
+
205
+ time = parse_now("13:00")
206
+ assert_equal Time.local(2006, 8, 17, 13), time
207
+
208
+ time = parse_now("13:45")
209
+ assert_equal Time.local(2006, 8, 17, 13, 45), time
210
+
211
+ time = parse_now("november")
212
+ assert_equal Time.local(2006, 11, 16), time
213
+ end
214
+
215
+ def test_parse_guess_rr
216
+ time = parse_now("friday 13:00")
217
+ assert_equal Time.local(2006, 8, 18, 13), time
218
+
219
+ time = parse_now("monday 4:00")
220
+ assert_equal Time.local(2006, 8, 21, 16), time
221
+
222
+ time = parse_now("sat 4:00", :ambiguous_time_range => :none)
223
+ assert_equal Time.local(2006, 8, 19, 4), time
224
+
225
+ time = parse_now("sunday 4:20", :ambiguous_time_range => :none)
226
+ assert_equal Time.local(2006, 8, 20, 4, 20), time
227
+
228
+ time = parse_now("4 pm")
229
+ assert_equal Time.local(2006, 8, 16, 16), time
230
+
231
+ time = parse_now("4 am", :ambiguous_time_range => :none)
232
+ assert_equal Time.local(2006, 8, 16, 4), time
233
+
234
+ time = parse_now("12 pm")
235
+ assert_equal Time.local(2006, 8, 16, 12), time
236
+
237
+ time = parse_now("12:01 pm")
238
+ assert_equal Time.local(2006, 8, 16, 12, 1), time
239
+
240
+ time = parse_now("12:01 am")
241
+ assert_equal Time.local(2006, 8, 16, 0, 1), time
242
+
243
+ time = parse_now("12 am")
244
+ assert_equal Time.local(2006, 8, 16), time
245
+
246
+ time = parse_now("4:00 in the morning")
247
+ assert_equal Time.local(2006, 8, 16, 4), time
248
+
249
+ time = parse_now("november 4")
250
+ assert_equal Time.local(2006, 11, 4, 12), time
251
+
252
+ time = parse_now("aug 24")
253
+ assert_equal Time.local(2006, 8, 24, 12), time
254
+ end
255
+
256
+ def test_parse_guess_rrr
257
+ time = parse_now("friday 1 pm")
258
+ assert_equal Time.local(2006, 8, 18, 13), time
259
+
260
+ time = parse_now("friday 11 at night")
261
+ assert_equal Time.local(2006, 8, 18, 23), time
262
+
263
+ time = parse_now("friday 11 in the evening")
264
+ assert_equal Time.local(2006, 8, 18, 23), time
265
+
266
+ time = parse_now("sunday 6am")
267
+ assert_equal Time.local(2006, 8, 20, 6), time
268
+
269
+ time = parse_now("friday evening at 7")
270
+ assert_equal Time.local(2006, 8, 18, 19), time
271
+ end
272
+
273
+ def test_parse_guess_gr
274
+ # year
275
+
276
+ time = parse_now("this year")
277
+ assert_equal Time.local(2006, 10, 24, 12, 30), time
278
+
279
+ time = parse_now("this year", :context => :past)
280
+ assert_equal Time.local(2006, 4, 24, 12, 30), time
281
+
282
+ # month
283
+
284
+ time = parse_now("this month")
285
+ assert_equal Time.local(2006, 8, 24, 12), time
286
+
287
+ time = parse_now("this month", :context => :past)
288
+ assert_equal Time.local(2006, 8, 8, 12), time
289
+
290
+ time = Chronic.parse("next month", :now => Time.local(2006, 11, 15))
291
+ assert_equal Time.local(2006, 12, 16, 12), time
292
+
293
+ # month name
294
+
295
+ time = parse_now("last november")
296
+ assert_equal Time.local(2005, 11, 16), time
297
+
298
+ # fortnight
299
+
300
+ time = parse_now("this fortnight")
301
+ assert_equal Time.local(2006, 8, 21, 19, 30), time
302
+
303
+ time = parse_now("this fortnight", :context => :past)
304
+ assert_equal Time.local(2006, 8, 14, 19), time
305
+
306
+ # week
307
+
308
+ time = parse_now("this week")
309
+ assert_equal Time.local(2006, 8, 18, 7, 30), time
310
+
311
+ time = parse_now("this week", :context => :past)
312
+ assert_equal Time.local(2006, 8, 14, 19), time
313
+
314
+ # weekend
315
+
316
+ time = parse_now("this weekend")
317
+ assert_equal Time.local(2006, 8, 20), time
318
+
319
+ time = parse_now("this weekend", :context => :past)
320
+ assert_equal Time.local(2006, 8, 13), time
321
+
322
+ time = parse_now("last weekend")
323
+ assert_equal Time.local(2006, 8, 13), time
324
+
325
+ # day
326
+
327
+ time = parse_now("this day")
328
+ assert_equal Time.local(2006, 8, 16, 19, 30), time
329
+
330
+ time = parse_now("this day", :context => :past)
331
+ assert_equal Time.local(2006, 8, 16, 7), time
332
+
333
+ time = parse_now("today")
334
+ assert_equal Time.local(2006, 8, 16, 19, 30), time
335
+
336
+ time = parse_now("yesterday")
337
+ assert_equal Time.local(2006, 8, 15, 12), time
338
+
339
+ time = parse_now("tomorrow")
340
+ assert_equal Time.local(2006, 8, 17, 12), time
341
+
342
+ # day name
343
+
344
+ time = parse_now("this tuesday")
345
+ assert_equal Time.local(2006, 8, 22, 12), time
346
+
347
+ time = parse_now("next tuesday")
348
+ assert_equal Time.local(2006, 8, 22, 12), time
349
+
350
+ time = parse_now("last tuesday")
351
+ assert_equal Time.local(2006, 8, 15, 12), time
352
+
353
+ time = parse_now("this wed")
354
+ assert_equal Time.local(2006, 8, 23, 12), time
355
+
356
+ time = parse_now("next wed")
357
+ assert_equal Time.local(2006, 8, 23, 12), time
358
+
359
+ time = parse_now("last wed")
360
+ assert_equal Time.local(2006, 8, 9, 12), time
361
+
362
+ # day portion
363
+
364
+ time = parse_now("this morning")
365
+ assert_equal Time.local(2006, 8, 16, 9), time
366
+
367
+ time = parse_now("tonight")
368
+ assert_equal Time.local(2006, 8, 16, 22), time
369
+
370
+ # minute
371
+
372
+ time = parse_now("next minute")
373
+ assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
374
+
375
+ # second
376
+
377
+ time = parse_now("this second")
378
+ assert_equal Time.local(2006, 8, 16, 14), time
379
+
380
+ time = parse_now("this second", :context => :past)
381
+ assert_equal Time.local(2006, 8, 16, 14), time
382
+
383
+ time = parse_now("next second")
384
+ assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
385
+
386
+ time = parse_now("last second")
387
+ assert_equal Time.local(2006, 8, 16, 13, 59, 59), time
388
+ end
389
+
390
+ def test_parse_guess_grr
391
+ time = parse_now("yesterday at 4:00")
392
+ assert_equal Time.local(2006, 8, 15, 16), time
393
+
394
+ time = parse_now("today at 9:00")
395
+ assert_equal Time.local(2006, 8, 16, 9), time
396
+
397
+ time = parse_now("today at 2100")
398
+ assert_equal Time.local(2006, 8, 16, 21), time
399
+
400
+ time = parse_now("this day at 0900")
401
+ assert_equal Time.local(2006, 8, 16, 9), time
402
+
403
+ time = parse_now("tomorrow at 0900")
404
+ assert_equal Time.local(2006, 8, 17, 9), time
405
+
406
+ time = parse_now("yesterday at 4:00", :ambiguous_time_range => :none)
407
+ assert_equal Time.local(2006, 8, 15, 4), time
408
+
409
+ time = parse_now("last friday at 4:00")
410
+ assert_equal Time.local(2006, 8, 11, 16), time
411
+
412
+ time = parse_now("next wed 4:00")
413
+ assert_equal Time.local(2006, 8, 23, 16), time
414
+
415
+ time = parse_now("yesterday afternoon")
416
+ assert_equal Time.local(2006, 8, 15, 15), time
417
+
418
+ time = parse_now("last week tuesday")
419
+ assert_equal Time.local(2006, 8, 8, 12), time
420
+
421
+ time = parse_now("tonight at 7")
422
+ assert_equal Time.local(2006, 8, 16, 19), time
423
+
424
+ time = parse_now("tonight 7")
425
+ assert_equal Time.local(2006, 8, 16, 19), time
426
+
427
+ time = parse_now("7 tonight")
428
+ assert_equal Time.local(2006, 8, 16, 19), time
429
+ end
430
+
431
+ def test_parse_guess_grrr
432
+ time = parse_now("today at 6:00pm")
433
+ assert_equal Time.local(2006, 8, 16, 18), time
434
+
435
+ time = parse_now("today at 6:00am")
436
+ assert_equal Time.local(2006, 8, 16, 6), time
437
+
438
+ time = parse_now("this day 1800")
439
+ assert_equal Time.local(2006, 8, 16, 18), time
440
+
441
+ time = parse_now("yesterday at 4:00pm")
442
+ assert_equal Time.local(2006, 8, 15, 16), time
443
+
444
+ time = parse_now("tomorrow evening at 7")
445
+ assert_equal Time.local(2006, 8, 17, 19), time
446
+
447
+ time = parse_now("tomorrow morning at 5:30")
448
+ assert_equal Time.local(2006, 8, 17, 5, 30), time
449
+
450
+ time = parse_now("next monday at 12:01 am")
451
+ assert_equal Time.local(2006, 8, 21, 00, 1), time
452
+
453
+ time = parse_now("next monday at 12:01 pm")
454
+ assert_equal Time.local(2006, 8, 21, 12, 1), time
455
+ end
456
+
457
+ def test_parse_guess_rgr
458
+ time = parse_now("afternoon yesterday")
459
+ assert_equal Time.local(2006, 8, 15, 15), time
460
+
461
+ time = parse_now("tuesday last week")
462
+ assert_equal Time.local(2006, 8, 8, 12), time
463
+ end
464
+
465
+ def test_parse_guess_s_r_p
466
+ # past
467
+
468
+ time = parse_now("3 years ago")
469
+ assert_equal Time.local(2003, 8, 16, 14), time
470
+
471
+ time = parse_now("1 month ago")
472
+ assert_equal Time.local(2006, 7, 16, 14), time
473
+
474
+ time = parse_now("1 fortnight ago")
475
+ assert_equal Time.local(2006, 8, 2, 14), time
476
+
477
+ time = parse_now("2 fortnights ago")
478
+ assert_equal Time.local(2006, 7, 19, 14), time
479
+
480
+ time = parse_now("3 weeks ago")
481
+ assert_equal Time.local(2006, 7, 26, 14), time
482
+
483
+ time = parse_now("2 weekends ago")
484
+ assert_equal Time.local(2006, 8, 5), time
485
+
486
+ time = parse_now("3 days ago")
487
+ assert_equal Time.local(2006, 8, 13, 14), time
488
+
489
+ #time = parse_now("1 monday ago")
490
+ #assert_equal Time.local(2006, 8, 14, 12), time
491
+
492
+ time = parse_now("5 mornings ago")
493
+ assert_equal Time.local(2006, 8, 12, 9), time
494
+
495
+ time = parse_now("7 hours ago")
496
+ assert_equal Time.local(2006, 8, 16, 7), time
497
+
498
+ time = parse_now("3 minutes ago")
499
+ assert_equal Time.local(2006, 8, 16, 13, 57), time
500
+
501
+ time = parse_now("20 seconds before now")
502
+ assert_equal Time.local(2006, 8, 16, 13, 59, 40), time
503
+
504
+ # future
505
+
506
+ time = parse_now("3 years from now")
507
+ assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
508
+
509
+ time = parse_now("6 months hence")
510
+ assert_equal Time.local(2007, 2, 16, 14), time
511
+
512
+ time = parse_now("3 fortnights hence")
513
+ assert_equal Time.local(2006, 9, 27, 14), time
514
+
515
+ time = parse_now("1 week from now")
516
+ assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
517
+
518
+ time = parse_now("1 weekend from now")
519
+ assert_equal Time.local(2006, 8, 19), time
520
+
521
+ time = parse_now("2 weekends from now")
522
+ assert_equal Time.local(2006, 8, 26), time
523
+
524
+ time = parse_now("1 day hence")
525
+ assert_equal Time.local(2006, 8, 17, 14), time
526
+
527
+ time = parse_now("5 mornings hence")
528
+ assert_equal Time.local(2006, 8, 21, 9), time
529
+
530
+ time = parse_now("1 hour from now")
531
+ assert_equal Time.local(2006, 8, 16, 15), time
532
+
533
+ time = parse_now("20 minutes hence")
534
+ assert_equal Time.local(2006, 8, 16, 14, 20), time
535
+
536
+ time = parse_now("20 seconds from now")
537
+ assert_equal Time.local(2006, 8, 16, 14, 0, 20), time
538
+
539
+ time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"))
540
+ assert_equal Time.local(2007, 1, 7, 23, 30), time
541
+ end
542
+
543
+ def test_parse_guess_p_s_r
544
+ time = parse_now("in 3 hours")
545
+ assert_equal Time.local(2006, 8, 16, 17), time
546
+ end
547
+
548
+ def test_parse_guess_s_r_p_a
549
+ # past
550
+
551
+ time = parse_now("3 years ago tomorrow")
552
+ assert_equal Time.local(2003, 8, 17, 12), time
553
+
554
+ time = parse_now("3 years ago this friday")
555
+ assert_equal Time.local(2003, 8, 18, 12), time
556
+
557
+ time = parse_now("3 months ago saturday at 5:00 pm")
558
+ assert_equal Time.local(2006, 5, 19, 17), time
559
+
560
+ time = parse_now("2 days from this second")
561
+ assert_equal Time.local(2006, 8, 18, 14), time
562
+
563
+ time = parse_now("7 hours before tomorrow at midnight")
564
+ assert_equal Time.local(2006, 8, 17, 17), time
565
+
566
+ # future
567
+ end
568
+
569
+ def test_parse_guess_o_r_s_r
570
+ time = parse_now("3rd wednesday in november")
571
+ assert_equal Time.local(2006, 11, 15, 12), time
572
+
573
+ time = parse_now("10th wednesday in november")
574
+ assert_equal nil, time
575
+
576
+ # time = parse_now("3rd wednesday in 2007")
577
+ # assert_equal Time.local(2007, 1, 20, 12), time
578
+ end
579
+
580
+ def test_parse_guess_o_r_g_r
581
+ time = parse_now("3rd month next year")
582
+ assert_equal Time.local(2007, 3, 16, 12, 30), time
583
+
584
+ time = parse_now("3rd thursday this september")
585
+ assert_equal Time.local(2006, 9, 21, 12), time
586
+
587
+ time = parse_now("4th day last week")
588
+ assert_equal Time.local(2006, 8, 9, 12), time
589
+ end
590
+
591
+ def test_parse_guess_nonsense
592
+ time = parse_now("some stupid nonsense")
593
+ assert_equal nil, time
594
+
595
+ time = parse_now("Ham Sandwich")
596
+ assert_equal nil, time
597
+ end
598
+
599
+ def test_parse_span
600
+ span = parse_now("friday", :guess => false)
601
+ assert_equal Time.local(2006, 8, 18), span.begin
602
+ assert_equal Time.local(2006, 8, 19), span.end
603
+
604
+ span = parse_now("november", :guess => false)
605
+ assert_equal Time.local(2006, 11), span.begin
606
+ assert_equal Time.local(2006, 12), span.end
607
+
608
+ span = Chronic.parse("weekend" , :now => @time_2006_08_16_14_00_00, :guess => false)
609
+ assert_equal Time.local(2006, 8, 19), span.begin
610
+ assert_equal Time.local(2006, 8, 21), span.end
611
+ end
612
+
613
+ def test_parse_with_endian_precedence
614
+ date = '11/02/2007'
615
+
616
+ expect_for_middle_endian = Time.local(2007, 11, 2, 12)
617
+ expect_for_little_endian = Time.local(2007, 2, 11, 12)
618
+
619
+ # default precedence should be toward middle endianness
620
+ assert_equal expect_for_middle_endian, Chronic.parse(date)
621
+
622
+ assert_equal expect_for_middle_endian, Chronic.parse(date, :endian_precedence => [:middle, :little])
623
+
624
+ assert_equal expect_for_little_endian, Chronic.parse(date, :endian_precedence => [:little, :middle])
625
+ end
626
+
627
+ def test_parse_words
628
+ assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
629
+ 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")
630
+ assert_equal parse_now("may 10th"), parse_now("may tenth")
631
+ end
632
+
633
+ def test_parse_only_complete_pointers
634
+ assert_equal parse_now("eat pasty buns today at 2pm"), @time_2006_08_16_14_00_00
635
+ assert_equal parse_now("futuristically speaking today at 2pm"), @time_2006_08_16_14_00_00
636
+ assert_equal parse_now("meeting today at 2pm"), @time_2006_08_16_14_00_00
637
+ end
638
+
639
+ def test_am_pm
640
+ assert_equal Time.local(2006, 8, 16), parse_now("8/16/2006 at 12am")
641
+ assert_equal Time.local(2006, 8, 16, 12), parse_now("8/16/2006 at 12pm")
642
+ end
643
+
644
+ def test_a_p
645
+ assert_equal Time.local(2006, 8, 16, 0, 15), parse_now("8/16/2006 at 12:15a")
646
+ assert_equal Time.local(2006, 8, 16, 18, 30), parse_now("8/16/2006 at 6:30p")
647
+ end
648
+
649
+ def test_argument_validation
650
+ assert_raise(Chronic::InvalidArgumentException) do
651
+ time = Chronic.parse("may 27", :foo => :bar)
652
+ end
653
+
654
+ assert_raise(Chronic::InvalidArgumentException) do
655
+ time = Chronic.parse("may 27", :context => :bar)
656
+ end
657
+ end
658
+
659
+ def test_seasons
660
+ t = parse_now("this spring", :guess => false)
661
+ assert_equal Time.local(2007, 3, 20), t.begin
662
+ assert_equal Time.local(2007, 6, 20), t.end
663
+
664
+ t = parse_now("this winter", :guess => false)
665
+ assert_equal Time.local(2006, 12, 22, 23), t.begin
666
+ assert_equal Time.local(2007, 3, 19), t.end
667
+
668
+ t = parse_now("last spring", :guess => false)
669
+ assert_equal Time.local(2006, 3, 20, 23), t.begin
670
+ assert_equal Time.local(2006, 6, 20), t.end
671
+
672
+ t = parse_now("last winter", :guess => false)
673
+ assert_equal Time.local(2005, 12, 22, 23), t.begin
674
+ assert_equal Time.local(2006, 3, 19, 23), t.end
675
+
676
+ t = parse_now("next spring", :guess => false)
677
+ assert_equal Time.local(2007, 3, 20), t.begin
678
+ assert_equal Time.local(2007, 6, 20), t.end
679
+ end
680
+
681
+ # regression
682
+
683
+ # def test_partial
684
+ # assert_equal '', parse_now("2 hours")
685
+ # end
686
+
687
+ def test_days_in_november
688
+ t1 = Chronic.parse('1st thursday in november', :now => Time.local(2007))
689
+ assert_equal Time.local(2007, 11, 1, 12), t1
690
+
691
+ t1 = Chronic.parse('1st friday in november', :now => Time.local(2007))
692
+ assert_equal Time.local(2007, 11, 2, 12), t1
693
+
694
+ t1 = Chronic.parse('1st saturday in november', :now => Time.local(2007))
695
+ assert_equal Time.local(2007, 11, 3, 12), t1
696
+
697
+ t1 = Chronic.parse('1st sunday in november', :now => Time.local(2007))
698
+ assert_equal Time.local(2007, 11, 4, 11), t1
699
+
700
+ # Chronic.debug = true
701
+ #
702
+ # t1 = Chronic.parse('1st monday in november', :now => Time.local(2007))
703
+ # assert_equal Time.local(2007, 11, 5, 11), t1
704
+ end
705
+
706
+ private
707
+ def parse_now(string, options={})
708
+ Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
709
+ end
710
+ end