chronic 0.1.5 → 0.6.5

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 (68) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +5 -0
  3. data/.yardopts +3 -0
  4. data/HISTORY.md +180 -0
  5. data/LICENSE +21 -0
  6. data/README.md +176 -0
  7. data/Rakefile +39 -32
  8. data/chronic.gemspec +17 -0
  9. data/lib/chronic/chronic.rb +294 -208
  10. data/lib/chronic/grabber.rb +22 -17
  11. data/lib/chronic/handler.rb +90 -0
  12. data/lib/chronic/handlers.rb +365 -278
  13. data/lib/chronic/mini_date.rb +38 -0
  14. data/lib/chronic/numerizer.rb +121 -0
  15. data/lib/chronic/ordinal.rb +23 -19
  16. data/lib/chronic/pointer.rb +20 -17
  17. data/lib/chronic/repeater.rb +126 -105
  18. data/lib/chronic/repeaters/repeater_day.rb +49 -43
  19. data/lib/chronic/repeaters/repeater_day_name.rb +48 -42
  20. data/lib/chronic/repeaters/repeater_day_portion.rb +81 -80
  21. data/lib/chronic/repeaters/repeater_fortnight.rb +59 -53
  22. data/lib/chronic/repeaters/repeater_hour.rb +49 -43
  23. data/lib/chronic/repeaters/repeater_minute.rb +55 -39
  24. data/lib/chronic/repeaters/repeater_month.rb +77 -55
  25. data/lib/chronic/repeaters/repeater_month_name.rb +83 -82
  26. data/lib/chronic/repeaters/repeater_season.rb +107 -21
  27. data/lib/chronic/repeaters/repeater_season_name.rb +41 -22
  28. data/lib/chronic/repeaters/repeater_second.rb +39 -33
  29. data/lib/chronic/repeaters/repeater_time.rb +117 -103
  30. data/lib/chronic/repeaters/repeater_week.rb +63 -57
  31. data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  32. data/lib/chronic/repeaters/repeater_weekend.rb +64 -9
  33. data/lib/chronic/repeaters/repeater_year.rb +70 -51
  34. data/lib/chronic/scalar.rb +64 -29
  35. data/lib/chronic/season.rb +37 -0
  36. data/lib/chronic/separator.rb +50 -38
  37. data/lib/chronic/span.rb +31 -0
  38. data/lib/chronic/tag.rb +42 -0
  39. data/lib/chronic/time_zone.rb +30 -0
  40. data/lib/chronic/token.rb +45 -0
  41. data/lib/chronic.rb +86 -22
  42. data/test/helper.rb +6 -0
  43. data/test/test_Chronic.rb +118 -20
  44. data/test/test_DaylightSavings.rb +118 -0
  45. data/test/test_Handler.rb +36 -42
  46. data/test/test_MiniDate.rb +32 -0
  47. data/test/test_Numerizer.rb +72 -0
  48. data/test/test_RepeaterDayName.rb +15 -16
  49. data/test/test_RepeaterFortnight.rb +16 -17
  50. data/test/test_RepeaterHour.rb +22 -19
  51. data/test/test_RepeaterMinute.rb +34 -0
  52. data/test/test_RepeaterMonth.rb +20 -17
  53. data/test/test_RepeaterMonthName.rb +17 -18
  54. data/test/test_RepeaterSeason.rb +40 -0
  55. data/test/test_RepeaterTime.rb +20 -22
  56. data/test/test_RepeaterWeek.rb +16 -17
  57. data/test/test_RepeaterWeekday.rb +55 -0
  58. data/test/test_RepeaterWeekend.rb +74 -0
  59. data/test/test_RepeaterYear.rb +24 -18
  60. data/test/test_Span.rb +5 -6
  61. data/test/test_Token.rb +5 -6
  62. data/test/test_parsing.rb +743 -338
  63. metadata +81 -54
  64. data/History.txt +0 -29
  65. data/Manifest.txt +0 -43
  66. data/README.txt +0 -149
  67. data/test/parse_numbers.rb +0 -50
  68. data/test/suite.rb +0 -9
@@ -1,8 +1,7 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
3
2
 
4
3
  class TestRepeaterHour < 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,56 +9,60 @@ class TestRepeaterHour < Test::Unit::TestCase
10
9
  def test_next_future
11
10
  hours = Chronic::RepeaterHour.new(:hour)
12
11
  hours.start = @now
13
-
12
+
14
13
  next_hour = hours.next(:future)
15
14
  assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
16
15
  assert_equal Time.local(2006, 8, 16, 16), next_hour.end
17
-
16
+
18
17
  next_next_hour = hours.next(:future)
19
18
  assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
20
19
  assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
21
20
  end
22
-
21
+
23
22
  def test_next_past
24
23
  hours = Chronic::RepeaterHour.new(:hour)
25
24
  hours.start = @now
26
-
25
+
27
26
  past_hour = hours.next(:past)
28
27
  assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
29
28
  assert_equal Time.local(2006, 8, 16, 14), past_hour.end
30
-
29
+
31
30
  past_past_hour = hours.next(:past)
32
31
  assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
33
32
  assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
34
33
  end
35
-
34
+
36
35
  def test_this
37
36
  @now = Time.local(2006, 8, 16, 14, 30)
38
-
37
+
39
38
  hours = Chronic::RepeaterHour.new(:hour)
40
39
  hours.start = @now
41
-
40
+
42
41
  this_hour = hours.this(:future)
43
42
  assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
44
43
  assert_equal Time.local(2006, 8, 16, 15), this_hour.end
45
-
44
+
46
45
  this_hour = hours.this(:past)
47
46
  assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
48
47
  assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
48
+
49
+ this_hour = hours.this(:none)
50
+ assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
51
+ assert_equal Time.local(2006, 8, 16, 15), this_hour.end
49
52
  end
50
-
53
+
51
54
  def test_offset
52
55
  span = Chronic::Span.new(@now, @now + 1)
53
-
56
+
54
57
  offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
55
-
58
+
56
59
  assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
57
60
  assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
58
-
61
+
59
62
  offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
60
-
63
+
61
64
  assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
62
65
  assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
63
66
  end
64
-
65
- end
67
+
68
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterMinute < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2008, 6, 25, 7, 15, 30, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ minutes = Chronic::RepeaterMinute.new(:minute)
11
+ minutes.start = @now
12
+
13
+ next_minute = minutes.next(:future)
14
+ assert_equal Time.local(2008, 6, 25, 7, 16), next_minute.begin
15
+ assert_equal Time.local(2008, 6, 25, 7, 17), next_minute.end
16
+
17
+ next_next_minute = minutes.next(:future)
18
+ assert_equal Time.local(2008, 6, 25, 7, 17), next_next_minute.begin
19
+ assert_equal Time.local(2008, 6, 25, 7, 18), next_next_minute.end
20
+ end
21
+
22
+ def test_next_past
23
+ minutes = Chronic::RepeaterMinute.new(:minute)
24
+ minutes.start = @now
25
+
26
+ prev_minute = minutes.next(:past)
27
+ assert_equal Time.local(2008, 6, 25, 7, 14), prev_minute.begin
28
+ assert_equal Time.local(2008, 6, 25, 7, 15), prev_minute.end
29
+
30
+ prev_prev_minute = minutes.next(:past)
31
+ assert_equal Time.local(2008, 6, 25, 7, 13), prev_prev_minute.begin
32
+ assert_equal Time.local(2008, 6, 25, 7, 14), prev_prev_minute.end
33
+ end
34
+ end
@@ -1,47 +1,50 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
3
2
 
4
3
  class TestRepeaterMonth < 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_offset_by
12
11
  # future
13
-
12
+
14
13
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
15
14
  assert_equal Time.local(2006, 9, 16, 14), time
16
-
15
+
17
16
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
18
17
  assert_equal Time.local(2007, 1, 16, 14), time
19
-
18
+
20
19
  # past
21
-
20
+
22
21
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
23
22
  assert_equal Time.local(2006, 7, 16, 14), time
24
-
23
+
25
24
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
26
25
  assert_equal Time.local(2005, 10, 16, 14), time
26
+
27
+ time = Chronic::RepeaterMonth.new(:month).offset_by(Time.local(2010, 3, 29), 1, :past)
28
+ assert_equal 2, time.month
29
+ assert_equal 28, time.day
27
30
  end
28
-
31
+
29
32
  def test_offset
30
33
  # future
31
-
34
+
32
35
  span = Chronic::Span.new(@now, @now + 60)
33
36
  offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
34
-
37
+
35
38
  assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
36
39
  assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
37
-
40
+
38
41
  # past
39
-
42
+
40
43
  span = Chronic::Span.new(@now, @now + 60)
41
44
  offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
42
-
45
+
43
46
  assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
44
47
  assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
45
48
  end
46
-
47
- end
49
+
50
+ end
@@ -1,57 +1,56 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require '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
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterSeason < 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
+ seasons = Chronic::RepeaterSeason.new(:season)
11
+ seasons.start = @now
12
+
13
+ next_season = seasons.next(:future)
14
+ assert_equal Time.local(2006, 9, 23), next_season.begin
15
+ assert_equal Time.local(2006, 12, 21), next_season.end
16
+ end
17
+
18
+ def test_next_past
19
+ seasons = Chronic::RepeaterSeason.new(:season)
20
+ seasons.start = @now
21
+
22
+ last_season = seasons.next(:past)
23
+ assert_equal Time.local(2006, 3, 20), last_season.begin
24
+ assert_equal Time.local(2006, 6, 20), last_season.end
25
+ end
26
+
27
+ def test_this
28
+ seasons = Chronic::RepeaterSeason.new(:season)
29
+ seasons.start = @now
30
+
31
+ this_season = seasons.this(:future)
32
+ assert_equal Time.local(2006, 8, 17), this_season.begin
33
+ assert_equal Time.local(2006, 9, 22), this_season.end
34
+
35
+ this_season = seasons.this(:past)
36
+ assert_equal Time.local(2006, 6, 21), this_season.begin
37
+ assert_equal Time.local(2006, 8, 16), this_season.end
38
+ end
39
+
40
+ end
@@ -1,43 +1,42 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require '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 '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 '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