chronic_2011 0.1.0
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.
- data/.gitignore +6 -0
- data/HISTORY.md +4 -0
- data/LICENSE +21 -0
- data/README.md +180 -0
- data/Rakefile +46 -0
- data/chronic.gemspec +18 -0
- data/lib/chronic.rb +117 -0
- data/lib/chronic/chronic.rb +346 -0
- data/lib/chronic/grabber.rb +33 -0
- data/lib/chronic/handler.rb +88 -0
- data/lib/chronic/handlers.rb +553 -0
- data/lib/chronic/mini_date.rb +38 -0
- data/lib/chronic/numerizer.rb +121 -0
- data/lib/chronic/ordinal.rb +47 -0
- data/lib/chronic/pointer.rb +32 -0
- data/lib/chronic/repeater.rb +142 -0
- data/lib/chronic/repeaters/repeater_day.rb +53 -0
- data/lib/chronic/repeaters/repeater_day_name.rb +52 -0
- data/lib/chronic/repeaters/repeater_day_portion.rb +108 -0
- data/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
- data/lib/chronic/repeaters/repeater_hour.rb +58 -0
- data/lib/chronic/repeaters/repeater_minute.rb +58 -0
- data/lib/chronic/repeaters/repeater_month.rb +79 -0
- data/lib/chronic/repeaters/repeater_month_name.rb +94 -0
- data/lib/chronic/repeaters/repeater_season.rb +109 -0
- data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
- data/lib/chronic/repeaters/repeater_second.rb +42 -0
- data/lib/chronic/repeaters/repeater_time.rb +128 -0
- data/lib/chronic/repeaters/repeater_week.rb +74 -0
- data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +66 -0
- data/lib/chronic/repeaters/repeater_year.rb +77 -0
- data/lib/chronic/scalar.rb +116 -0
- data/lib/chronic/season.rb +26 -0
- data/lib/chronic/separator.rb +94 -0
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +36 -0
- data/lib/chronic/time_zone.rb +32 -0
- data/lib/chronic/token.rb +47 -0
- data/test/helper.rb +12 -0
- data/test/test_chronic.rb +148 -0
- data/test/test_daylight_savings.rb +118 -0
- data/test/test_handler.rb +104 -0
- data/test/test_mini_date.rb +32 -0
- data/test/test_numerizer.rb +72 -0
- data/test/test_parsing.rb +977 -0
- data/test/test_repeater_day_name.rb +51 -0
- data/test/test_repeater_day_portion.rb +254 -0
- data/test/test_repeater_fortnight.rb +62 -0
- data/test/test_repeater_hour.rb +68 -0
- data/test/test_repeater_minute.rb +34 -0
- data/test/test_repeater_month.rb +50 -0
- data/test/test_repeater_month_name.rb +56 -0
- data/test/test_repeater_season.rb +40 -0
- data/test/test_repeater_time.rb +70 -0
- data/test/test_repeater_week.rb +62 -0
- data/test/test_repeater_weekday.rb +55 -0
- data/test/test_repeater_weekend.rb +74 -0
- data/test/test_repeater_year.rb +69 -0
- data/test/test_span.rb +23 -0
- data/test/test_token.rb +25 -0
- metadata +156 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterMonth < 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_offset_by
|
11
|
+
# future
|
12
|
+
|
13
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
|
14
|
+
assert_equal Time.local(2006, 9, 16, 14), time
|
15
|
+
|
16
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
|
17
|
+
assert_equal Time.local(2007, 1, 16, 14), time
|
18
|
+
|
19
|
+
# past
|
20
|
+
|
21
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
|
22
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
23
|
+
|
24
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
|
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
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_offset
|
33
|
+
# future
|
34
|
+
|
35
|
+
span = Chronic::Span.new(@now, @now + 60)
|
36
|
+
offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
|
37
|
+
|
38
|
+
assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
|
39
|
+
assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
|
40
|
+
|
41
|
+
# past
|
42
|
+
|
43
|
+
span = Chronic::Span.new(@now, @now + 60)
|
44
|
+
offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
|
45
|
+
|
46
|
+
assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
|
47
|
+
assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterMonthName < 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
|
11
|
+
# future
|
12
|
+
|
13
|
+
mays = Chronic::RepeaterMonthName.new(:may)
|
14
|
+
mays.start = @now
|
15
|
+
|
16
|
+
next_may = mays.next(:future)
|
17
|
+
assert_equal Time.local(2007, 5), next_may.begin
|
18
|
+
assert_equal Time.local(2007, 6), next_may.end
|
19
|
+
|
20
|
+
next_next_may = mays.next(:future)
|
21
|
+
assert_equal Time.local(2008, 5), next_next_may.begin
|
22
|
+
assert_equal Time.local(2008, 6), next_next_may.end
|
23
|
+
|
24
|
+
decembers = Chronic::RepeaterMonthName.new(:december)
|
25
|
+
decembers.start = @now
|
26
|
+
|
27
|
+
next_december = decembers.next(:future)
|
28
|
+
assert_equal Time.local(2006, 12), next_december.begin
|
29
|
+
assert_equal Time.local(2007, 1), next_december.end
|
30
|
+
|
31
|
+
# past
|
32
|
+
|
33
|
+
mays = Chronic::RepeaterMonthName.new(:may)
|
34
|
+
mays.start = @now
|
35
|
+
|
36
|
+
assert_equal Time.local(2006, 5), mays.next(:past).begin
|
37
|
+
assert_equal Time.local(2005, 5), mays.next(:past).begin
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_this
|
41
|
+
octobers = Chronic::RepeaterMonthName.new(:october)
|
42
|
+
octobers.start = @now
|
43
|
+
|
44
|
+
this_october = octobers.this(:future)
|
45
|
+
assert_equal Time.local(2006, 10, 1), this_october.begin
|
46
|
+
assert_equal Time.local(2006, 11, 1), this_october.end
|
47
|
+
|
48
|
+
aprils = Chronic::RepeaterMonthName.new(:april)
|
49
|
+
aprils.start = @now
|
50
|
+
|
51
|
+
this_april = aprils.this(:past)
|
52
|
+
assert_equal Time.local(2006, 4, 1), this_april.begin
|
53
|
+
assert_equal Time.local(2006, 5, 1), this_april.end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterSeason < 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
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterTime < 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 < 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 < 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 < 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 < 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
|