pangel-chronic 0.3.0.3 → 0.3.10

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/{README.rdoc → README.txt} +7 -22
  2. data/lib/chronic.rb +89 -12
  3. data/lib/chronic/chronic.rb +260 -301
  4. data/lib/chronic/grabber.rb +23 -23
  5. data/lib/chronic/handlers.rb +538 -557
  6. data/lib/chronic/ordinal.rb +36 -35
  7. data/lib/chronic/pointer.rb +24 -26
  8. data/lib/chronic/repeater.rb +128 -138
  9. data/lib/chronic/repeaters/repeater_day.rb +51 -51
  10. data/lib/chronic/repeaters/repeater_day_name.rb +50 -52
  11. data/lib/chronic/repeaters/repeater_day_portion.rb +93 -93
  12. data/lib/chronic/repeaters/repeater_fortnight.rb +66 -66
  13. data/lib/chronic/repeaters/repeater_hour.rb +56 -57
  14. data/lib/chronic/repeaters/repeater_minute.rb +56 -56
  15. data/lib/chronic/repeaters/repeater_month.rb +71 -62
  16. data/lib/chronic/repeaters/repeater_month_name.rb +95 -95
  17. data/lib/chronic/repeaters/repeater_season.rb +142 -142
  18. data/lib/chronic/repeaters/repeater_season_name.rb +42 -42
  19. data/lib/chronic/repeaters/repeater_second.rb +40 -40
  20. data/lib/chronic/repeaters/repeater_time.rb +124 -123
  21. data/lib/chronic/repeaters/repeater_week.rb +70 -70
  22. data/lib/chronic/repeaters/repeater_weekday.rb +76 -76
  23. data/lib/chronic/repeaters/repeater_weekend.rb +63 -63
  24. data/lib/chronic/repeaters/repeater_year.rb +63 -63
  25. data/lib/chronic/scalar.rb +89 -70
  26. data/lib/chronic/separator.rb +88 -88
  27. data/lib/chronic/time_zone.rb +23 -20
  28. data/lib/numerizer/numerizer.rb +93 -94
  29. data/test/suite.rb +2 -2
  30. data/test/test_Chronic.rb +47 -47
  31. data/test/test_Handler.rb +106 -106
  32. data/test/test_Numerizer.rb +47 -49
  33. data/test/test_RepeaterDayName.rb +48 -48
  34. data/test/test_RepeaterFortnight.rb +59 -59
  35. data/test/test_RepeaterHour.rb +61 -64
  36. data/test/test_RepeaterMonth.rb +43 -43
  37. data/test/test_RepeaterMonthName.rb +53 -53
  38. data/test/test_RepeaterTime.rb +68 -68
  39. data/test/test_RepeaterWeek.rb +59 -59
  40. data/test/test_RepeaterWeekday.rb +53 -53
  41. data/test/test_RepeaterWeekend.rb +71 -71
  42. data/test/test_RepeaterYear.rb +59 -59
  43. data/test/test_Span.rb +19 -28
  44. data/test/test_Time.rb +46 -46
  45. data/test/test_Token.rb +22 -22
  46. data/test/test_parsing.rb +726 -792
  47. metadata +6 -10
@@ -2,62 +2,62 @@ require 'chronic'
2
2
  require 'test/unit'
3
3
 
4
4
  class TestRepeaterWeek < Test::Unit::TestCase
5
-
6
- def setup
7
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
- end
9
-
10
- def test_next_future
11
- weeks = Chronic::RepeaterWeek.new(:week)
12
- weeks.start = @now
13
-
14
- next_week = weeks.next(:future)
15
- assert_equal Time.local(2006, 8, 20), next_week.begin
16
- assert_equal Time.local(2006, 8, 27), next_week.end
17
-
18
- next_next_week = weeks.next(:future)
19
- assert_equal Time.local(2006, 8, 27), next_next_week.begin
20
- assert_equal Time.local(2006, 9, 3), next_next_week.end
21
- end
22
-
23
- def test_next_past
24
- weeks = Chronic::RepeaterWeek.new(:week)
25
- weeks.start = @now
26
-
27
- last_week = weeks.next(:past)
28
- assert_equal Time.local(2006, 8, 6), last_week.begin
29
- assert_equal Time.local(2006, 8, 13), last_week.end
30
-
31
- last_last_week = weeks.next(:past)
32
- assert_equal Time.local(2006, 7, 30), last_last_week.begin
33
- assert_equal Time.local(2006, 8, 6), last_last_week.end
34
- end
35
-
36
- def test_this_future
37
- weeks = Chronic::RepeaterWeek.new(:week)
38
- weeks.start = @now
39
-
40
- this_week = weeks.this(:future)
41
- assert_equal Time.local(2006, 8, 16, 15), this_week.begin
42
- assert_equal Time.local(2006, 8, 20), this_week.end
43
- end
44
-
45
- def test_this_past
46
- weeks = Chronic::RepeaterWeek.new(:week)
47
- weeks.start = @now
48
-
49
- this_week = weeks.this(:past)
50
- assert_equal Time.local(2006, 8, 13, 0), this_week.begin
51
- assert_equal Time.local(2006, 8, 16, 14), this_week.end
52
- end
53
-
54
- def test_offset
55
- span = Chronic::Span.new(@now, @now + 1)
56
-
57
- offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
58
-
59
- assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
60
- assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
61
- end
62
-
63
- end
5
+
6
+ def setup
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_next_future
11
+ weeks = Chronic::RepeaterWeek.new(:week)
12
+ weeks.start = @now
13
+
14
+ next_week = weeks.next(:future)
15
+ assert_equal Time.local(2006, 8, 20), next_week.begin
16
+ assert_equal Time.local(2006, 8, 27), next_week.end
17
+
18
+ next_next_week = weeks.next(:future)
19
+ assert_equal Time.local(2006, 8, 27), next_next_week.begin
20
+ assert_equal Time.local(2006, 9, 3), next_next_week.end
21
+ end
22
+
23
+ def test_next_past
24
+ weeks = Chronic::RepeaterWeek.new(:week)
25
+ weeks.start = @now
26
+
27
+ last_week = weeks.next(:past)
28
+ assert_equal Time.local(2006, 8, 6), last_week.begin
29
+ assert_equal Time.local(2006, 8, 13), last_week.end
30
+
31
+ last_last_week = weeks.next(:past)
32
+ assert_equal Time.local(2006, 7, 30), last_last_week.begin
33
+ assert_equal Time.local(2006, 8, 6), last_last_week.end
34
+ end
35
+
36
+ def test_this_future
37
+ weeks = Chronic::RepeaterWeek.new(:week)
38
+ weeks.start = @now
39
+
40
+ this_week = weeks.this(:future)
41
+ assert_equal Time.local(2006, 8, 16, 15), this_week.begin
42
+ assert_equal Time.local(2006, 8, 20), this_week.end
43
+ end
44
+
45
+ def test_this_past
46
+ weeks = Chronic::RepeaterWeek.new(:week)
47
+ weeks.start = @now
48
+
49
+ this_week = weeks.this(:past)
50
+ assert_equal Time.local(2006, 8, 13, 0), this_week.begin
51
+ assert_equal Time.local(2006, 8, 16, 14), this_week.end
52
+ end
53
+
54
+ def test_offset
55
+ span = Chronic::Span.new(@now, @now + 1)
56
+
57
+ offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
58
+
59
+ assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
60
+ assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
61
+ end
62
+
63
+ end
@@ -1,56 +1,56 @@
1
- require 'chronic'
1
+ require 'lib/chronic'
2
2
  require 'test/unit'
3
3
 
4
4
  class TestRepeaterWeekday < Test::Unit::TestCase
5
-
6
- def setup
7
- @now = Time.local(2007, 6, 11, 14, 0, 0, 0) # Mon
8
- end
9
-
10
- def test_next_future
11
- weekdays = Chronic::RepeaterWeekday.new(:weekday)
12
- weekdays.start = @now
13
-
14
- next1_weekday = weekdays.next(:future) # Tues
15
- assert_equal Time.local(2007, 6, 12), next1_weekday.begin
16
- assert_equal Time.local(2007, 6, 13), next1_weekday.end
17
-
18
- next2_weekday = weekdays.next(:future) # Wed
19
- assert_equal Time.local(2007, 6, 13), next2_weekday.begin
20
- assert_equal Time.local(2007, 6, 14), next2_weekday.end
21
-
22
- next3_weekday = weekdays.next(:future) # Thurs
23
- assert_equal Time.local(2007, 6, 14), next3_weekday.begin
24
- assert_equal Time.local(2007, 6, 15), next3_weekday.end
25
-
26
- next4_weekday = weekdays.next(:future) # Fri
27
- assert_equal Time.local(2007, 6, 15), next4_weekday.begin
28
- assert_equal Time.local(2007, 6, 16), next4_weekday.end
29
-
30
- next5_weekday = weekdays.next(:future) # Mon
31
- assert_equal Time.local(2007, 6, 18), next5_weekday.begin
32
- assert_equal Time.local(2007, 6, 19), next5_weekday.end
33
- end
34
-
35
- def test_next_past
36
- weekdays = Chronic::RepeaterWeekday.new(:weekday)
37
- weekdays.start = @now
38
-
39
- last1_weekday = weekdays.next(:past) # Fri
40
- assert_equal Time.local(2007, 6, 8), last1_weekday.begin
41
- assert_equal Time.local(2007, 6, 9), last1_weekday.end
42
-
43
- last2_weekday = weekdays.next(:past) # Thurs
44
- assert_equal Time.local(2007, 6, 7), last2_weekday.begin
45
- assert_equal Time.local(2007, 6, 8), last2_weekday.end
46
- end
47
-
48
- def test_offset
49
- span = Chronic::Span.new(@now, @now + 1)
50
-
51
- offset_span = Chronic::RepeaterWeekday.new(:weekday).offset(span, 5, :future)
52
-
53
- assert_equal Time.local(2007, 6, 18, 14), offset_span.begin
54
- assert_equal Time.local(2007, 6, 18, 14, 0, 1), offset_span.end
55
- end
56
- end
5
+
6
+ def setup
7
+ @now = Time.local(2007, 6, 11, 14, 0, 0, 0) # Mon
8
+ end
9
+
10
+ def test_next_future
11
+ weekdays = Chronic::RepeaterWeekday.new(:weekday)
12
+ weekdays.start = @now
13
+
14
+ next1_weekday = weekdays.next(:future) # Tues
15
+ assert_equal Time.local(2007, 6, 12), next1_weekday.begin
16
+ assert_equal Time.local(2007, 6, 13), next1_weekday.end
17
+
18
+ next2_weekday = weekdays.next(:future) # Wed
19
+ assert_equal Time.local(2007, 6, 13), next2_weekday.begin
20
+ assert_equal Time.local(2007, 6, 14), next2_weekday.end
21
+
22
+ next3_weekday = weekdays.next(:future) # Thurs
23
+ assert_equal Time.local(2007, 6, 14), next3_weekday.begin
24
+ assert_equal Time.local(2007, 6, 15), next3_weekday.end
25
+
26
+ next4_weekday = weekdays.next(:future) # Fri
27
+ assert_equal Time.local(2007, 6, 15), next4_weekday.begin
28
+ assert_equal Time.local(2007, 6, 16), next4_weekday.end
29
+
30
+ next5_weekday = weekdays.next(:future) # Mon
31
+ assert_equal Time.local(2007, 6, 18), next5_weekday.begin
32
+ assert_equal Time.local(2007, 6, 19), next5_weekday.end
33
+ end
34
+
35
+ def test_next_past
36
+ weekdays = Chronic::RepeaterWeekday.new(:weekday)
37
+ weekdays.start = @now
38
+
39
+ last1_weekday = weekdays.next(:past) # Fri
40
+ assert_equal Time.local(2007, 6, 8), last1_weekday.begin
41
+ assert_equal Time.local(2007, 6, 9), last1_weekday.end
42
+
43
+ last2_weekday = weekdays.next(:past) # Thurs
44
+ assert_equal Time.local(2007, 6, 7), last2_weekday.begin
45
+ assert_equal Time.local(2007, 6, 8), last2_weekday.end
46
+ end
47
+
48
+ def test_offset
49
+ span = Chronic::Span.new(@now, @now + 1)
50
+
51
+ offset_span = Chronic::RepeaterWeekday.new(:weekday).offset(span, 5, :future)
52
+
53
+ assert_equal Time.local(2007, 6, 18, 14), offset_span.begin
54
+ assert_equal Time.local(2007, 6, 18, 14, 0, 1), offset_span.end
55
+ end
56
+ end
@@ -2,74 +2,74 @@ require 'chronic'
2
2
  require 'test/unit'
3
3
 
4
4
  class TestRepeaterWeekend < Test::Unit::TestCase
5
-
6
- def setup
7
- # Wed Aug 16 14:00:00 2006
8
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
- end
10
-
11
- def test_next_future
12
- weekend = Chronic::RepeaterWeekend.new(:weekend)
13
- weekend.start = @now
14
-
15
- next_weekend = weekend.next(:future)
16
- assert_equal Time.local(2006, 8, 19), next_weekend.begin
17
- assert_equal Time.local(2006, 8, 21), next_weekend.end
18
- end
19
-
20
- def test_next_past
21
- weekend = Chronic::RepeaterWeekend.new(:weekend)
22
- weekend.start = @now
23
-
24
- next_weekend = weekend.next(:past)
25
- assert_equal Time.local(2006, 8, 12), next_weekend.begin
26
- assert_equal Time.local(2006, 8, 14), next_weekend.end
27
- end
28
-
29
- def test_this_future
30
- weekend = Chronic::RepeaterWeekend.new(:weekend)
31
- weekend.start = @now
32
-
33
- next_weekend = weekend.this(:future)
34
- assert_equal Time.local(2006, 8, 19), next_weekend.begin
35
- assert_equal Time.local(2006, 8, 21), next_weekend.end
36
- end
37
-
38
- def test_this_past
39
- weekend = Chronic::RepeaterWeekend.new(:weekend)
40
- weekend.start = @now
41
-
42
- next_weekend = weekend.this(:past)
43
- assert_equal Time.local(2006, 8, 12), next_weekend.begin
44
- assert_equal Time.local(2006, 8, 14), next_weekend.end
45
- end
46
-
47
- def test_this_none
48
- weekend = Chronic::RepeaterWeekend.new(:weekend)
49
- weekend.start = @now
50
-
51
- next_weekend = weekend.this(:future)
52
- assert_equal Time.local(2006, 8, 19), next_weekend.begin
53
- assert_equal Time.local(2006, 8, 21), next_weekend.end
54
- end
55
-
56
- def test_offset
57
- span = Chronic::Span.new(@now, @now + 1)
58
-
59
- offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
60
-
61
- assert_equal Time.local(2006, 9, 2), offset_span.begin
62
- assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
63
-
64
- offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
65
-
66
- assert_equal Time.local(2006, 8, 12), offset_span.begin
67
- assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
68
-
69
- offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
70
-
71
- assert_equal Time.local(2006, 8, 12), offset_span.begin
72
- assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
73
- end
74
-
75
- end
5
+
6
+ def setup
7
+ # Wed Aug 16 14:00:00 2006
8
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
+ end
10
+
11
+ def test_next_future
12
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
13
+ weekend.start = @now
14
+
15
+ next_weekend = weekend.next(:future)
16
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
17
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
18
+ end
19
+
20
+ def test_next_past
21
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
22
+ weekend.start = @now
23
+
24
+ next_weekend = weekend.next(:past)
25
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
26
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
27
+ end
28
+
29
+ def test_this_future
30
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
31
+ weekend.start = @now
32
+
33
+ next_weekend = weekend.this(:future)
34
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
35
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
36
+ end
37
+
38
+ def test_this_past
39
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
40
+ weekend.start = @now
41
+
42
+ next_weekend = weekend.this(:past)
43
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
44
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
45
+ end
46
+
47
+ def test_this_none
48
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
49
+ weekend.start = @now
50
+
51
+ next_weekend = weekend.this(:future)
52
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
53
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
54
+ end
55
+
56
+ def test_offset
57
+ span = Chronic::Span.new(@now, @now + 1)
58
+
59
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
60
+
61
+ assert_equal Time.local(2006, 9, 2), offset_span.begin
62
+ assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
63
+
64
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
65
+
66
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
67
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
68
+
69
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
70
+
71
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
72
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
73
+ end
74
+
75
+ end
@@ -2,62 +2,62 @@ require 'chronic'
2
2
  require 'test/unit'
3
3
 
4
4
  class TestRepeaterYear < Test::Unit::TestCase
5
-
6
- def setup
7
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
- end
9
-
10
- def test_next_future
11
- years = Chronic::RepeaterYear.new(:year)
12
- years.start = @now
13
-
14
- next_year = years.next(:future)
15
- assert_equal Time.local(2007, 1, 1), next_year.begin
16
- assert_equal Time.local(2008, 1, 1), next_year.end
17
-
18
- next_next_year = years.next(:future)
19
- assert_equal Time.local(2008, 1, 1), next_next_year.begin
20
- assert_equal Time.local(2009, 1, 1), next_next_year.end
21
- end
22
-
23
- def test_next_past
24
- years = Chronic::RepeaterYear.new(:year)
25
- years.start = @now
26
-
27
- last_year = years.next(:past)
28
- assert_equal Time.local(2005, 1, 1), last_year.begin
29
- assert_equal Time.local(2006, 1, 1), last_year.end
30
-
31
- last_last_year = years.next(:past)
32
- assert_equal Time.local(2004, 1, 1), last_last_year.begin
33
- assert_equal Time.local(2005, 1, 1), last_last_year.end
34
- end
35
-
36
- def test_this
37
- years = Chronic::RepeaterYear.new(:year)
38
- years.start = @now
39
-
40
- this_year = years.this(:future)
41
- assert_equal Time.local(2006, 8, 17), this_year.begin
42
- assert_equal Time.local(2007, 1, 1), this_year.end
43
-
44
- this_year = years.this(:past)
45
- assert_equal Time.local(2006, 1, 1), this_year.begin
46
- assert_equal Time.local(2006, 8, 16), this_year.end
47
- end
48
-
49
- def test_offset
50
- span = Chronic::Span.new(@now, @now + 1)
51
-
52
- offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
53
-
54
- assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
55
- assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
56
-
57
- offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
58
-
59
- assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
60
- assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
61
- end
62
-
63
- end
5
+
6
+ def setup
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_next_future
11
+ years = Chronic::RepeaterYear.new(:year)
12
+ years.start = @now
13
+
14
+ next_year = years.next(:future)
15
+ assert_equal Time.local(2007, 1, 1), next_year.begin
16
+ assert_equal Time.local(2008, 1, 1), next_year.end
17
+
18
+ next_next_year = years.next(:future)
19
+ assert_equal Time.local(2008, 1, 1), next_next_year.begin
20
+ assert_equal Time.local(2009, 1, 1), next_next_year.end
21
+ end
22
+
23
+ def test_next_past
24
+ years = Chronic::RepeaterYear.new(:year)
25
+ years.start = @now
26
+
27
+ last_year = years.next(:past)
28
+ assert_equal Time.local(2005, 1, 1), last_year.begin
29
+ assert_equal Time.local(2006, 1, 1), last_year.end
30
+
31
+ last_last_year = years.next(:past)
32
+ assert_equal Time.local(2004, 1, 1), last_last_year.begin
33
+ assert_equal Time.local(2005, 1, 1), last_last_year.end
34
+ end
35
+
36
+ def test_this
37
+ years = Chronic::RepeaterYear.new(:year)
38
+ years.start = @now
39
+
40
+ this_year = years.this(:future)
41
+ assert_equal Time.local(2006, 8, 17), this_year.begin
42
+ assert_equal Time.local(2007, 1, 1), this_year.end
43
+
44
+ this_year = years.this(:past)
45
+ assert_equal Time.local(2006, 1, 1), this_year.begin
46
+ assert_equal Time.local(2006, 8, 16), this_year.end
47
+ end
48
+
49
+ def test_offset
50
+ span = Chronic::Span.new(@now, @now + 1)
51
+
52
+ offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
53
+
54
+ assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
55
+ assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
56
+
57
+ offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
58
+
59
+ assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
60
+ assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
61
+ end
62
+
63
+ end