chronic-mmlac 0.6.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +5 -0
  4. data/.yardopts +3 -0
  5. data/HISTORY.md +174 -0
  6. data/LICENSE +21 -0
  7. data/README.md +177 -0
  8. data/Rakefile +46 -0
  9. data/chronic.gemspec +17 -0
  10. data/lib/chronic/chronic.rb +325 -0
  11. data/lib/chronic/grabber.rb +31 -0
  12. data/lib/chronic/handler.rb +90 -0
  13. data/lib/chronic/handlers.rb +465 -0
  14. data/lib/chronic/mini_date.rb +38 -0
  15. data/lib/chronic/numerizer.rb +121 -0
  16. data/lib/chronic/ordinal.rb +44 -0
  17. data/lib/chronic/pointer.rb +30 -0
  18. data/lib/chronic/repeater.rb +135 -0
  19. data/lib/chronic/repeaters/repeater_day.rb +53 -0
  20. data/lib/chronic/repeaters/repeater_day_name.rb +52 -0
  21. data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
  22. data/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
  23. data/lib/chronic/repeaters/repeater_hour.rb +58 -0
  24. data/lib/chronic/repeaters/repeater_minute.rb +58 -0
  25. data/lib/chronic/repeaters/repeater_month.rb +79 -0
  26. data/lib/chronic/repeaters/repeater_month_name.rb +94 -0
  27. data/lib/chronic/repeaters/repeater_season.rb +109 -0
  28. data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
  29. data/lib/chronic/repeaters/repeater_second.rb +42 -0
  30. data/lib/chronic/repeaters/repeater_time.rb +128 -0
  31. data/lib/chronic/repeaters/repeater_week.rb +74 -0
  32. data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  33. data/lib/chronic/repeaters/repeater_weekend.rb +66 -0
  34. data/lib/chronic/repeaters/repeater_year.rb +77 -0
  35. data/lib/chronic/scalar.rb +109 -0
  36. data/lib/chronic/season.rb +37 -0
  37. data/lib/chronic/separator.rb +88 -0
  38. data/lib/chronic/span.rb +31 -0
  39. data/lib/chronic/tag.rb +42 -0
  40. data/lib/chronic/time_zone.rb +30 -0
  41. data/lib/chronic/token.rb +45 -0
  42. data/lib/chronic.rb +118 -0
  43. data/test/helper.rb +6 -0
  44. data/test/test_Chronic.rb +148 -0
  45. data/test/test_DaylightSavings.rb +118 -0
  46. data/test/test_Handler.rb +104 -0
  47. data/test/test_MiniDate.rb +32 -0
  48. data/test/test_Numerizer.rb +72 -0
  49. data/test/test_RepeaterDayName.rb +51 -0
  50. data/test/test_RepeaterFortnight.rb +62 -0
  51. data/test/test_RepeaterHour.rb +68 -0
  52. data/test/test_RepeaterMinute.rb +34 -0
  53. data/test/test_RepeaterMonth.rb +50 -0
  54. data/test/test_RepeaterMonthName.rb +56 -0
  55. data/test/test_RepeaterSeason.rb +40 -0
  56. data/test/test_RepeaterTime.rb +70 -0
  57. data/test/test_RepeaterWeek.rb +62 -0
  58. data/test/test_RepeaterWeekday.rb +55 -0
  59. data/test/test_RepeaterWeekend.rb +74 -0
  60. data/test/test_RepeaterYear.rb +69 -0
  61. data/test/test_Span.rb +23 -0
  62. data/test/test_Token.rb +25 -0
  63. data/test/test_parsing.rb +886 -0
  64. metadata +132 -0
@@ -0,0 +1,70 @@
1
+ require '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 '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 '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 '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,69 @@
1
+ require '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
+
61
+ now = Time.local(2008, 2, 29)
62
+ span = Chronic::Span.new(now, now + 1)
63
+ offset_span = Chronic::RepeaterYear.new(:year).offset(span, 1, :past)
64
+
65
+ assert_equal Time.local(2007, 2, 28), offset_span.begin
66
+ assert_equal Time.local(2007, 2, 28, 0, 0, 1), offset_span.end
67
+ end
68
+
69
+ end
data/test/test_Span.rb ADDED
@@ -0,0 +1,23 @@
1
+ require '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
@@ -0,0 +1,25 @@
1
+ require '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