pangel-chronic 0.3.0.2
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/README.rdoc +182 -0
- data/lib/chronic/chronic.rb +303 -0
- data/lib/chronic/grabber.rb +26 -0
- data/lib/chronic/handlers.rb +560 -0
- data/lib/chronic/ordinal.rb +39 -0
- data/lib/chronic/pointer.rb +29 -0
- data/lib/chronic/repeater.rb +139 -0
- data/lib/chronic/repeaters/repeater_day.rb +52 -0
- data/lib/chronic/repeaters/repeater_day_name.rb +53 -0
- data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
- data/lib/chronic/repeaters/repeater_fortnight.rb +70 -0
- data/lib/chronic/repeaters/repeater_hour.rb +58 -0
- data/lib/chronic/repeaters/repeater_minute.rb +57 -0
- data/lib/chronic/repeaters/repeater_month.rb +66 -0
- data/lib/chronic/repeaters/repeater_month_name.rb +98 -0
- data/lib/chronic/repeaters/repeater_season.rb +150 -0
- data/lib/chronic/repeaters/repeater_season_name.rb +45 -0
- data/lib/chronic/repeaters/repeater_second.rb +41 -0
- data/lib/chronic/repeaters/repeater_time.rb +124 -0
- data/lib/chronic/repeaters/repeater_week.rb +73 -0
- data/lib/chronic/repeaters/repeater_weekday.rb +77 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +65 -0
- data/lib/chronic/repeaters/repeater_year.rb +64 -0
- data/lib/chronic/scalar.rb +76 -0
- data/lib/chronic/separator.rb +91 -0
- data/lib/chronic/time_zone.rb +23 -0
- data/lib/chronic.rb +57 -0
- data/lib/numerizer/numerizer.rb +98 -0
- data/test/suite.rb +9 -0
- data/test/test_Chronic.rb +50 -0
- data/test/test_Handler.rb +110 -0
- data/test/test_Numerizer.rb +54 -0
- data/test/test_RepeaterDayName.rb +52 -0
- data/test/test_RepeaterFortnight.rb +63 -0
- data/test/test_RepeaterHour.rb +68 -0
- data/test/test_RepeaterMonth.rb +47 -0
- data/test/test_RepeaterMonthName.rb +57 -0
- data/test/test_RepeaterTime.rb +72 -0
- data/test/test_RepeaterWeek.rb +63 -0
- data/test/test_RepeaterWeekday.rb +56 -0
- data/test/test_RepeaterWeekend.rb +75 -0
- data/test/test_RepeaterYear.rb +63 -0
- data/test/test_Span.rb +33 -0
- data/test/test_Time.rb +50 -0
- data/test/test_Token.rb +26 -0
- data/test/test_parsing.rb +797 -0
- metadata +111 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestRepeaterHour < 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
|
+
hours = Chronic::RepeaterHour.new(:hour)
|
12
|
+
hours.start = @now
|
13
|
+
|
14
|
+
next_hour = hours.next(:future)
|
15
|
+
assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
|
16
|
+
assert_equal Time.local(2006, 8, 16, 16), next_hour.end
|
17
|
+
|
18
|
+
next_next_hour = hours.next(:future)
|
19
|
+
assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
|
20
|
+
assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_next_past
|
24
|
+
hours = Chronic::RepeaterHour.new(:hour)
|
25
|
+
hours.start = @now
|
26
|
+
|
27
|
+
past_hour = hours.next(:past)
|
28
|
+
assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
|
29
|
+
assert_equal Time.local(2006, 8, 16, 14), past_hour.end
|
30
|
+
|
31
|
+
past_past_hour = hours.next(:past)
|
32
|
+
assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
|
33
|
+
assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_this
|
37
|
+
@now = Time.local(2006, 8, 16, 14, 30)
|
38
|
+
|
39
|
+
hours = Chronic::RepeaterHour.new(:hour)
|
40
|
+
hours.start = @now
|
41
|
+
|
42
|
+
this_hour = hours.this(:future)
|
43
|
+
assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
|
44
|
+
assert_equal Time.local(2006, 8, 16, 15), this_hour.end
|
45
|
+
|
46
|
+
this_hour = hours.this(:past)
|
47
|
+
assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
|
48
|
+
assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_offset
|
52
|
+
span = Chronic::Span.new(@now, @now + 1)
|
53
|
+
|
54
|
+
offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
|
55
|
+
|
56
|
+
assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
|
57
|
+
assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
|
58
|
+
|
59
|
+
offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
|
60
|
+
|
61
|
+
assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
|
62
|
+
assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
|
63
|
+
end
|
64
|
+
def test_sanity
|
65
|
+
assert_not_nil Chronic.parse '2 hours ago'
|
66
|
+
# assert_not_nil Chronic.parse '2 hours' # FIXME: this fails
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestRepeaterMonth < 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_offset_by
|
12
|
+
# future
|
13
|
+
|
14
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
|
15
|
+
assert_equal Time.local(2006, 9, 16, 14), time
|
16
|
+
|
17
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
|
18
|
+
assert_equal Time.local(2007, 1, 16, 14), time
|
19
|
+
|
20
|
+
# past
|
21
|
+
|
22
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
|
23
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
24
|
+
|
25
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
|
26
|
+
assert_equal Time.local(2005, 10, 16, 14), time
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_offset
|
30
|
+
# future
|
31
|
+
|
32
|
+
span = Chronic::Span.new(@now, @now + 60)
|
33
|
+
offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
|
34
|
+
|
35
|
+
assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
|
36
|
+
assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
|
37
|
+
|
38
|
+
# past
|
39
|
+
|
40
|
+
span = Chronic::Span.new(@now, @now + 60)
|
41
|
+
offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
|
42
|
+
|
43
|
+
assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
|
44
|
+
assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestRepeaterMonthName < 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
|
12
|
+
# future
|
13
|
+
|
14
|
+
mays = Chronic::RepeaterMonthName.new(:may)
|
15
|
+
mays.start = @now
|
16
|
+
|
17
|
+
next_may = mays.next(:future)
|
18
|
+
assert_equal Time.local(2007, 5), next_may.begin
|
19
|
+
assert_equal Time.local(2007, 6), next_may.end
|
20
|
+
|
21
|
+
next_next_may = mays.next(:future)
|
22
|
+
assert_equal Time.local(2008, 5), next_next_may.begin
|
23
|
+
assert_equal Time.local(2008, 6), next_next_may.end
|
24
|
+
|
25
|
+
decembers = Chronic::RepeaterMonthName.new(:december)
|
26
|
+
decembers.start = @now
|
27
|
+
|
28
|
+
next_december = decembers.next(:future)
|
29
|
+
assert_equal Time.local(2006, 12), next_december.begin
|
30
|
+
assert_equal Time.local(2007, 1), next_december.end
|
31
|
+
|
32
|
+
# past
|
33
|
+
|
34
|
+
mays = Chronic::RepeaterMonthName.new(:may)
|
35
|
+
mays.start = @now
|
36
|
+
|
37
|
+
assert_equal Time.local(2006, 5), mays.next(:past).begin
|
38
|
+
assert_equal Time.local(2005, 5), mays.next(:past).begin
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_this
|
42
|
+
octobers = Chronic::RepeaterMonthName.new(:october)
|
43
|
+
octobers.start = @now
|
44
|
+
|
45
|
+
this_october = octobers.this(:future)
|
46
|
+
assert_equal Time.local(2006, 10, 1), this_october.begin
|
47
|
+
assert_equal Time.local(2006, 11, 1), this_october.end
|
48
|
+
|
49
|
+
aprils = Chronic::RepeaterMonthName.new(:april)
|
50
|
+
aprils.start = @now
|
51
|
+
|
52
|
+
this_april = aprils.this(:past)
|
53
|
+
assert_equal Time.local(2006, 4, 1), this_april.begin
|
54
|
+
assert_equal Time.local(2006, 5, 1), this_april.end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestRepeaterTime < 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
|
+
t = Chronic::RepeaterTime.new('4:00')
|
13
|
+
t.start = @now
|
14
|
+
|
15
|
+
assert_equal Time.local(2006, 8, 16, 16), t.next(:future).begin
|
16
|
+
assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
|
17
|
+
|
18
|
+
t = Chronic::RepeaterTime.new('13:00')
|
19
|
+
t.start = @now
|
20
|
+
|
21
|
+
assert_equal Time.local(2006, 8, 17, 13), t.next(:future).begin
|
22
|
+
assert_equal Time.local(2006, 8, 18, 13), t.next(:future).begin
|
23
|
+
|
24
|
+
t = Chronic::RepeaterTime.new('0400')
|
25
|
+
t.start = @now
|
26
|
+
|
27
|
+
assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
|
28
|
+
assert_equal Time.local(2006, 8, 18, 4), t.next(:future).begin
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_next_past
|
32
|
+
t = Chronic::RepeaterTime.new('4:00')
|
33
|
+
t.start = @now
|
34
|
+
|
35
|
+
assert_equal Time.local(2006, 8, 16, 4), t.next(:past).begin
|
36
|
+
assert_equal Time.local(2006, 8, 15, 16), t.next(:past).begin
|
37
|
+
|
38
|
+
t = Chronic::RepeaterTime.new('13:00')
|
39
|
+
t.start = @now
|
40
|
+
|
41
|
+
assert_equal Time.local(2006, 8, 16, 13), t.next(:past).begin
|
42
|
+
assert_equal Time.local(2006, 8, 15, 13), t.next(:past).begin
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_type
|
46
|
+
t1 = Chronic::RepeaterTime.new('4')
|
47
|
+
assert_equal 14_400, t1.type.time
|
48
|
+
|
49
|
+
t1 = Chronic::RepeaterTime.new('14')
|
50
|
+
assert_equal 50_400, t1.type.time
|
51
|
+
|
52
|
+
t1 = Chronic::RepeaterTime.new('4:00')
|
53
|
+
assert_equal 14_400, t1.type.time
|
54
|
+
|
55
|
+
t1 = Chronic::RepeaterTime.new('4:30')
|
56
|
+
assert_equal 16_200, t1.type.time
|
57
|
+
|
58
|
+
t1 = Chronic::RepeaterTime.new('1400')
|
59
|
+
assert_equal 50_400, t1.type.time
|
60
|
+
|
61
|
+
t1 = Chronic::RepeaterTime.new('0400')
|
62
|
+
assert_equal 14_400, t1.type.time
|
63
|
+
|
64
|
+
t1 = Chronic::RepeaterTime.new('04')
|
65
|
+
assert_equal 14_400, t1.type.time
|
66
|
+
|
67
|
+
t1 = Chronic::RepeaterTime.new('400')
|
68
|
+
assert_equal 14_400, t1.type.time
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
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
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
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
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
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
|
data/test/test_Span.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestSpan < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
# Wed Aug 16 14:00:00 UTC 2006
|
8
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_span_width
|
12
|
+
span = Chronic::Span.new(Time.local(2006, 8, 16, 0), Time.local(2006, 8, 17, 0))
|
13
|
+
assert_equal (60 * 60 * 24), span.width
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_span_math
|
17
|
+
s = Chronic::Span.new(1, 2)
|
18
|
+
assert_equal 2, (s + 1).begin
|
19
|
+
assert_equal 3, (s + 1).end
|
20
|
+
assert_equal 0, (s - 1).begin
|
21
|
+
assert_equal 1, (s - 1).end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_span_exclusive
|
25
|
+
s = Chronic::Span.new(1, 4)
|
26
|
+
assert s.include?(3)
|
27
|
+
assert !s.include?(4)
|
28
|
+
t = Chronic::Span.new(Time.local(1980, 03, 01, 0), Time.local(1980, 04, 01, 0))
|
29
|
+
assert t.include?(Time.local(1980, 03, 31, 0))
|
30
|
+
assert !t.include?(Time.local(1980, 04, 01, 0))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/test_Time.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestTime < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_normal
|
10
|
+
assert_equal Time.local(2006, 1, 2, 0, 0, 0), Time.construct(2006, 1, 2, 0, 0, 0)
|
11
|
+
assert_equal Time.local(2006, 1, 2, 3, 0, 0), Time.construct(2006, 1, 2, 3, 0, 0)
|
12
|
+
assert_equal Time.local(2006, 1, 2, 3, 4, 0), Time.construct(2006, 1, 2, 3, 4, 0)
|
13
|
+
assert_equal Time.local(2006, 1, 2, 3, 4, 5), Time.construct(2006, 1, 2, 3, 4, 5)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_second_overflow
|
17
|
+
assert_equal Time.local(2006, 1, 1, 0, 1, 30), Time.construct(2006, 1, 1, 0, 0, 90)
|
18
|
+
assert_equal Time.local(2006, 1, 1, 0, 5, 0), Time.construct(2006, 1, 1, 0, 0, 300)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_minute_overflow
|
22
|
+
assert_equal Time.local(2006, 1, 1, 1, 30), Time.construct(2006, 1, 1, 0, 90)
|
23
|
+
assert_equal Time.local(2006, 1, 1, 5), Time.construct(2006, 1, 1, 0, 300)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_hour_overflow
|
27
|
+
assert_equal Time.local(2006, 1, 2, 12), Time.construct(2006, 1, 1, 36)
|
28
|
+
assert_equal Time.local(2006, 1, 7), Time.construct(2006, 1, 1, 144)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_day_overflow
|
32
|
+
assert_equal Time.local(2006, 2, 1), Time.construct(2006, 1, 32)
|
33
|
+
assert_equal Time.local(2006, 3, 5), Time.construct(2006, 2, 33)
|
34
|
+
assert_equal Time.local(2004, 3, 4), Time.construct(2004, 2, 33)
|
35
|
+
assert_equal Time.local(2000, 3, 5), Time.construct(2000, 2, 33)
|
36
|
+
|
37
|
+
assert_nothing_raised do
|
38
|
+
Time.construct(2006, 1, 56)
|
39
|
+
end
|
40
|
+
|
41
|
+
assert_raise(RuntimeError) do
|
42
|
+
Time.construct(2006, 1, 57)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_month_overflow
|
47
|
+
assert_equal Time.local(2006, 1), Time.construct(2005, 13)
|
48
|
+
assert_equal Time.local(2005, 12), Time.construct(2000, 72)
|
49
|
+
end
|
50
|
+
end
|
data/test/test_Token.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestToken < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
# Wed Aug 16 14:00:00 UTC 2006
|
8
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_token
|
12
|
+
token = Chronic::Token.new('foo')
|
13
|
+
assert_equal 0, token.tags.size
|
14
|
+
assert !token.tagged?
|
15
|
+
token.tag("mytag")
|
16
|
+
assert_equal 1, token.tags.size
|
17
|
+
assert token.tagged?
|
18
|
+
assert_equal String, token.get_tag(String).class
|
19
|
+
token.tag(5)
|
20
|
+
assert_equal 2, token.tags.size
|
21
|
+
token.untag(String)
|
22
|
+
assert_equal 1, token.tags.size
|
23
|
+
assert_equal 'foo', token.word
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|