chronic 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/HISTORY.md +76 -0
  2. data/LICENSE +21 -0
  3. data/README.md +165 -0
  4. data/Rakefile +145 -18
  5. data/benchmark/benchmark.rb +13 -0
  6. data/chronic.gemspec +85 -0
  7. data/lib/chronic.rb +21 -19
  8. data/lib/chronic/chronic.rb +59 -49
  9. data/lib/chronic/grabber.rb +2 -2
  10. data/lib/chronic/handlers.rb +167 -112
  11. data/lib/{numerizer → chronic/numerizer}/numerizer.rb +17 -23
  12. data/lib/chronic/ordinal.rb +6 -6
  13. data/lib/chronic/pointer.rb +3 -3
  14. data/lib/chronic/repeater.rb +26 -12
  15. data/lib/chronic/repeaters/repeater_day.rb +17 -12
  16. data/lib/chronic/repeaters/repeater_day_name.rb +17 -12
  17. data/lib/chronic/repeaters/repeater_day_portion.rb +13 -12
  18. data/lib/chronic/repeaters/repeater_fortnight.rb +14 -9
  19. data/lib/chronic/repeaters/repeater_hour.rb +15 -10
  20. data/lib/chronic/repeaters/repeater_minute.rb +15 -10
  21. data/lib/chronic/repeaters/repeater_month.rb +20 -15
  22. data/lib/chronic/repeaters/repeater_month_name.rb +21 -16
  23. data/lib/chronic/repeaters/repeater_season.rb +136 -9
  24. data/lib/chronic/repeaters/repeater_season_name.rb +38 -17
  25. data/lib/chronic/repeaters/repeater_second.rb +15 -10
  26. data/lib/chronic/repeaters/repeater_time.rb +49 -42
  27. data/lib/chronic/repeaters/repeater_week.rb +16 -11
  28. data/lib/chronic/repeaters/repeater_weekday.rb +77 -0
  29. data/lib/chronic/repeaters/repeater_weekend.rb +14 -9
  30. data/lib/chronic/repeaters/repeater_year.rb +19 -13
  31. data/lib/chronic/scalar.rb +16 -14
  32. data/lib/chronic/separator.rb +25 -10
  33. data/lib/chronic/time_zone.rb +4 -3
  34. data/test/helper.rb +7 -0
  35. data/test/test_Chronic.rb +17 -18
  36. data/test/test_DaylightSavings.rb +118 -0
  37. data/test/test_Handler.rb +37 -38
  38. data/test/test_Numerizer.rb +8 -5
  39. data/test/test_RepeaterDayName.rb +15 -16
  40. data/test/test_RepeaterFortnight.rb +16 -17
  41. data/test/test_RepeaterHour.rb +18 -19
  42. data/test/test_RepeaterMinute.rb +34 -0
  43. data/test/test_RepeaterMonth.rb +16 -17
  44. data/test/test_RepeaterMonthName.rb +17 -18
  45. data/test/test_RepeaterTime.rb +20 -22
  46. data/test/test_RepeaterWeek.rb +16 -17
  47. data/test/test_RepeaterWeekday.rb +55 -0
  48. data/test/test_RepeaterWeekend.rb +21 -22
  49. data/test/test_RepeaterYear.rb +17 -18
  50. data/test/test_Span.rb +5 -6
  51. data/test/test_Time.rb +11 -12
  52. data/test/test_Token.rb +5 -6
  53. data/test/test_parsing.rb +300 -204
  54. metadata +74 -52
  55. data/History.txt +0 -53
  56. data/README.txt +0 -149
  57. data/test/suite.rb +0 -9
@@ -1,57 +1,56 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
3
2
 
4
3
  class TestRepeaterMonthName < Test::Unit::TestCase
5
-
4
+
6
5
  def setup
7
6
  # Wed Aug 16 14:00:00 2006
8
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
8
  end
10
-
9
+
11
10
  def test_next
12
11
  # future
13
-
12
+
14
13
  mays = Chronic::RepeaterMonthName.new(:may)
15
14
  mays.start = @now
16
-
15
+
17
16
  next_may = mays.next(:future)
18
17
  assert_equal Time.local(2007, 5), next_may.begin
19
18
  assert_equal Time.local(2007, 6), next_may.end
20
-
19
+
21
20
  next_next_may = mays.next(:future)
22
21
  assert_equal Time.local(2008, 5), next_next_may.begin
23
22
  assert_equal Time.local(2008, 6), next_next_may.end
24
-
23
+
25
24
  decembers = Chronic::RepeaterMonthName.new(:december)
26
25
  decembers.start = @now
27
-
26
+
28
27
  next_december = decembers.next(:future)
29
28
  assert_equal Time.local(2006, 12), next_december.begin
30
29
  assert_equal Time.local(2007, 1), next_december.end
31
-
30
+
32
31
  # past
33
-
32
+
34
33
  mays = Chronic::RepeaterMonthName.new(:may)
35
34
  mays.start = @now
36
-
35
+
37
36
  assert_equal Time.local(2006, 5), mays.next(:past).begin
38
37
  assert_equal Time.local(2005, 5), mays.next(:past).begin
39
38
  end
40
-
39
+
41
40
  def test_this
42
41
  octobers = Chronic::RepeaterMonthName.new(:october)
43
42
  octobers.start = @now
44
-
43
+
45
44
  this_october = octobers.this(:future)
46
45
  assert_equal Time.local(2006, 10, 1), this_october.begin
47
46
  assert_equal Time.local(2006, 11, 1), this_october.end
48
-
47
+
49
48
  aprils = Chronic::RepeaterMonthName.new(:april)
50
49
  aprils.start = @now
51
-
50
+
52
51
  this_april = aprils.this(:past)
53
52
  assert_equal Time.local(2006, 4, 1), this_april.begin
54
53
  assert_equal Time.local(2006, 5, 1), this_april.end
55
54
  end
56
-
57
- end
55
+
56
+ end
@@ -1,43 +1,42 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
3
2
 
4
3
  class TestRepeaterTime < Test::Unit::TestCase
5
-
4
+
6
5
  def setup
7
6
  # Wed Aug 16 14:00:00 2006
8
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
8
  end
10
-
9
+
11
10
  def test_next_future
12
11
  t = Chronic::RepeaterTime.new('4:00')
13
12
  t.start = @now
14
-
13
+
15
14
  assert_equal Time.local(2006, 8, 16, 16), t.next(:future).begin
16
15
  assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
17
-
16
+
18
17
  t = Chronic::RepeaterTime.new('13:00')
19
18
  t.start = @now
20
-
19
+
21
20
  assert_equal Time.local(2006, 8, 17, 13), t.next(:future).begin
22
21
  assert_equal Time.local(2006, 8, 18, 13), t.next(:future).begin
23
-
22
+
24
23
  t = Chronic::RepeaterTime.new('0400')
25
24
  t.start = @now
26
-
25
+
27
26
  assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
28
27
  assert_equal Time.local(2006, 8, 18, 4), t.next(:future).begin
29
28
  end
30
-
29
+
31
30
  def test_next_past
32
31
  t = Chronic::RepeaterTime.new('4:00')
33
32
  t.start = @now
34
-
33
+
35
34
  assert_equal Time.local(2006, 8, 16, 4), t.next(:past).begin
36
35
  assert_equal Time.local(2006, 8, 15, 16), t.next(:past).begin
37
-
36
+
38
37
  t = Chronic::RepeaterTime.new('13:00')
39
38
  t.start = @now
40
-
39
+
41
40
  assert_equal Time.local(2006, 8, 16, 13), t.next(:past).begin
42
41
  assert_equal Time.local(2006, 8, 15, 13), t.next(:past).begin
43
42
  end
@@ -45,28 +44,27 @@ class TestRepeaterTime < Test::Unit::TestCase
45
44
  def test_type
46
45
  t1 = Chronic::RepeaterTime.new('4')
47
46
  assert_equal 14_400, t1.type.time
48
-
47
+
49
48
  t1 = Chronic::RepeaterTime.new('14')
50
49
  assert_equal 50_400, t1.type.time
51
-
50
+
52
51
  t1 = Chronic::RepeaterTime.new('4:00')
53
52
  assert_equal 14_400, t1.type.time
54
-
53
+
55
54
  t1 = Chronic::RepeaterTime.new('4:30')
56
55
  assert_equal 16_200, t1.type.time
57
-
56
+
58
57
  t1 = Chronic::RepeaterTime.new('1400')
59
58
  assert_equal 50_400, t1.type.time
60
-
59
+
61
60
  t1 = Chronic::RepeaterTime.new('0400')
62
61
  assert_equal 14_400, t1.type.time
63
-
62
+
64
63
  t1 = Chronic::RepeaterTime.new('04')
65
64
  assert_equal 14_400, t1.type.time
66
-
65
+
67
66
  t1 = Chronic::RepeaterTime.new('400')
68
67
  assert_equal 14_400, t1.type.time
69
68
  end
70
69
 
71
-
72
- end
70
+ end
@@ -1,8 +1,7 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
3
2
 
4
3
  class TestRepeaterWeek < Test::Unit::TestCase
5
-
4
+
6
5
  def setup
7
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
7
  end
@@ -10,54 +9,54 @@ class TestRepeaterWeek < Test::Unit::TestCase
10
9
  def test_next_future
11
10
  weeks = Chronic::RepeaterWeek.new(:week)
12
11
  weeks.start = @now
13
-
12
+
14
13
  next_week = weeks.next(:future)
15
14
  assert_equal Time.local(2006, 8, 20), next_week.begin
16
15
  assert_equal Time.local(2006, 8, 27), next_week.end
17
-
16
+
18
17
  next_next_week = weeks.next(:future)
19
18
  assert_equal Time.local(2006, 8, 27), next_next_week.begin
20
19
  assert_equal Time.local(2006, 9, 3), next_next_week.end
21
20
  end
22
-
21
+
23
22
  def test_next_past
24
23
  weeks = Chronic::RepeaterWeek.new(:week)
25
24
  weeks.start = @now
26
-
25
+
27
26
  last_week = weeks.next(:past)
28
27
  assert_equal Time.local(2006, 8, 6), last_week.begin
29
28
  assert_equal Time.local(2006, 8, 13), last_week.end
30
-
29
+
31
30
  last_last_week = weeks.next(:past)
32
31
  assert_equal Time.local(2006, 7, 30), last_last_week.begin
33
32
  assert_equal Time.local(2006, 8, 6), last_last_week.end
34
33
  end
35
-
34
+
36
35
  def test_this_future
37
36
  weeks = Chronic::RepeaterWeek.new(:week)
38
37
  weeks.start = @now
39
-
38
+
40
39
  this_week = weeks.this(:future)
41
40
  assert_equal Time.local(2006, 8, 16, 15), this_week.begin
42
41
  assert_equal Time.local(2006, 8, 20), this_week.end
43
42
  end
44
-
43
+
45
44
  def test_this_past
46
45
  weeks = Chronic::RepeaterWeek.new(:week)
47
46
  weeks.start = @now
48
-
47
+
49
48
  this_week = weeks.this(:past)
50
49
  assert_equal Time.local(2006, 8, 13, 0), this_week.begin
51
50
  assert_equal Time.local(2006, 8, 16, 14), this_week.end
52
51
  end
53
-
52
+
54
53
  def test_offset
55
54
  span = Chronic::Span.new(@now, @now + 1)
56
-
55
+
57
56
  offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
58
-
57
+
59
58
  assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
60
59
  assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
61
60
  end
62
-
63
- 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
@@ -1,75 +1,74 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
3
2
 
4
3
  class TestRepeaterWeekend < Test::Unit::TestCase
5
-
4
+
6
5
  def setup
7
6
  # Wed Aug 16 14:00:00 2006
8
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
8
  end
10
-
9
+
11
10
  def test_next_future
12
11
  weekend = Chronic::RepeaterWeekend.new(:weekend)
13
12
  weekend.start = @now
14
-
13
+
15
14
  next_weekend = weekend.next(:future)
16
15
  assert_equal Time.local(2006, 8, 19), next_weekend.begin
17
16
  assert_equal Time.local(2006, 8, 21), next_weekend.end
18
17
  end
19
-
18
+
20
19
  def test_next_past
21
20
  weekend = Chronic::RepeaterWeekend.new(:weekend)
22
21
  weekend.start = @now
23
-
22
+
24
23
  next_weekend = weekend.next(:past)
25
24
  assert_equal Time.local(2006, 8, 12), next_weekend.begin
26
25
  assert_equal Time.local(2006, 8, 14), next_weekend.end
27
26
  end
28
-
27
+
29
28
  def test_this_future
30
29
  weekend = Chronic::RepeaterWeekend.new(:weekend)
31
30
  weekend.start = @now
32
-
31
+
33
32
  next_weekend = weekend.this(:future)
34
33
  assert_equal Time.local(2006, 8, 19), next_weekend.begin
35
34
  assert_equal Time.local(2006, 8, 21), next_weekend.end
36
35
  end
37
-
36
+
38
37
  def test_this_past
39
38
  weekend = Chronic::RepeaterWeekend.new(:weekend)
40
39
  weekend.start = @now
41
-
40
+
42
41
  next_weekend = weekend.this(:past)
43
42
  assert_equal Time.local(2006, 8, 12), next_weekend.begin
44
43
  assert_equal Time.local(2006, 8, 14), next_weekend.end
45
44
  end
46
-
45
+
47
46
  def test_this_none
48
47
  weekend = Chronic::RepeaterWeekend.new(:weekend)
49
48
  weekend.start = @now
50
-
49
+
51
50
  next_weekend = weekend.this(:future)
52
51
  assert_equal Time.local(2006, 8, 19), next_weekend.begin
53
52
  assert_equal Time.local(2006, 8, 21), next_weekend.end
54
53
  end
55
-
54
+
56
55
  def test_offset
57
56
  span = Chronic::Span.new(@now, @now + 1)
58
-
57
+
59
58
  offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
60
-
59
+
61
60
  assert_equal Time.local(2006, 9, 2), offset_span.begin
62
61
  assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
63
-
62
+
64
63
  offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
65
-
64
+
66
65
  assert_equal Time.local(2006, 8, 12), offset_span.begin
67
66
  assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
68
-
67
+
69
68
  offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
70
-
69
+
71
70
  assert_equal Time.local(2006, 8, 12), offset_span.begin
72
71
  assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
73
72
  end
74
-
75
- end
73
+
74
+ end
@@ -1,8 +1,7 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require File.join(File.dirname(__FILE__), *%w[helper])
3
2
 
4
3
  class TestRepeaterYear < Test::Unit::TestCase
5
-
4
+
6
5
  def setup
7
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
7
  end
@@ -10,54 +9,54 @@ class TestRepeaterYear < Test::Unit::TestCase
10
9
  def test_next_future
11
10
  years = Chronic::RepeaterYear.new(:year)
12
11
  years.start = @now
13
-
12
+
14
13
  next_year = years.next(:future)
15
14
  assert_equal Time.local(2007, 1, 1), next_year.begin
16
15
  assert_equal Time.local(2008, 1, 1), next_year.end
17
-
16
+
18
17
  next_next_year = years.next(:future)
19
18
  assert_equal Time.local(2008, 1, 1), next_next_year.begin
20
19
  assert_equal Time.local(2009, 1, 1), next_next_year.end
21
20
  end
22
-
21
+
23
22
  def test_next_past
24
23
  years = Chronic::RepeaterYear.new(:year)
25
24
  years.start = @now
26
-
25
+
27
26
  last_year = years.next(:past)
28
27
  assert_equal Time.local(2005, 1, 1), last_year.begin
29
28
  assert_equal Time.local(2006, 1, 1), last_year.end
30
-
29
+
31
30
  last_last_year = years.next(:past)
32
31
  assert_equal Time.local(2004, 1, 1), last_last_year.begin
33
32
  assert_equal Time.local(2005, 1, 1), last_last_year.end
34
33
  end
35
-
34
+
36
35
  def test_this
37
36
  years = Chronic::RepeaterYear.new(:year)
38
37
  years.start = @now
39
-
38
+
40
39
  this_year = years.this(:future)
41
40
  assert_equal Time.local(2006, 8, 17), this_year.begin
42
41
  assert_equal Time.local(2007, 1, 1), this_year.end
43
-
42
+
44
43
  this_year = years.this(:past)
45
44
  assert_equal Time.local(2006, 1, 1), this_year.begin
46
45
  assert_equal Time.local(2006, 8, 16), this_year.end
47
46
  end
48
-
47
+
49
48
  def test_offset
50
49
  span = Chronic::Span.new(@now, @now + 1)
51
-
50
+
52
51
  offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
53
-
52
+
54
53
  assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
55
54
  assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
56
-
55
+
57
56
  offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
58
-
57
+
59
58
  assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
60
59
  assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
61
60
  end
62
-
63
- end
61
+
62
+ end