pangel-chronic 0.3.0.3 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.txt} +7 -22
- data/lib/chronic.rb +89 -12
- data/lib/chronic/chronic.rb +260 -301
- data/lib/chronic/grabber.rb +23 -23
- data/lib/chronic/handlers.rb +538 -557
- data/lib/chronic/ordinal.rb +36 -35
- data/lib/chronic/pointer.rb +24 -26
- data/lib/chronic/repeater.rb +128 -138
- data/lib/chronic/repeaters/repeater_day.rb +51 -51
- data/lib/chronic/repeaters/repeater_day_name.rb +50 -52
- data/lib/chronic/repeaters/repeater_day_portion.rb +93 -93
- data/lib/chronic/repeaters/repeater_fortnight.rb +66 -66
- data/lib/chronic/repeaters/repeater_hour.rb +56 -57
- data/lib/chronic/repeaters/repeater_minute.rb +56 -56
- data/lib/chronic/repeaters/repeater_month.rb +71 -62
- data/lib/chronic/repeaters/repeater_month_name.rb +95 -95
- data/lib/chronic/repeaters/repeater_season.rb +142 -142
- data/lib/chronic/repeaters/repeater_season_name.rb +42 -42
- data/lib/chronic/repeaters/repeater_second.rb +40 -40
- data/lib/chronic/repeaters/repeater_time.rb +124 -123
- data/lib/chronic/repeaters/repeater_week.rb +70 -70
- data/lib/chronic/repeaters/repeater_weekday.rb +76 -76
- data/lib/chronic/repeaters/repeater_weekend.rb +63 -63
- data/lib/chronic/repeaters/repeater_year.rb +63 -63
- data/lib/chronic/scalar.rb +89 -70
- data/lib/chronic/separator.rb +88 -88
- data/lib/chronic/time_zone.rb +23 -20
- data/lib/numerizer/numerizer.rb +93 -94
- data/test/suite.rb +2 -2
- data/test/test_Chronic.rb +47 -47
- data/test/test_Handler.rb +106 -106
- data/test/test_Numerizer.rb +47 -49
- data/test/test_RepeaterDayName.rb +48 -48
- data/test/test_RepeaterFortnight.rb +59 -59
- data/test/test_RepeaterHour.rb +61 -64
- data/test/test_RepeaterMonth.rb +43 -43
- data/test/test_RepeaterMonthName.rb +53 -53
- data/test/test_RepeaterTime.rb +68 -68
- data/test/test_RepeaterWeek.rb +59 -59
- data/test/test_RepeaterWeekday.rb +53 -53
- data/test/test_RepeaterWeekend.rb +71 -71
- data/test/test_RepeaterYear.rb +59 -59
- data/test/test_Span.rb +19 -28
- data/test/test_Time.rb +46 -46
- data/test/test_Token.rb +22 -22
- data/test/test_parsing.rb +726 -792
- metadata +6 -10
data/test/test_RepeaterHour.rb
CHANGED
@@ -2,67 +2,64 @@ require 'chronic'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestRepeaterHour < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# assert_not_nil Chronic.parse '2 hours' # FIXME: this fails
|
67
|
-
end
|
68
|
-
end
|
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
|
+
|
65
|
+
end
|
data/test/test_RepeaterMonth.rb
CHANGED
@@ -2,46 +2,46 @@ require 'chronic'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestRepeaterMonth < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
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
|
@@ -2,56 +2,56 @@ require 'chronic'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestRepeaterMonthName < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
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
|
data/test/test_RepeaterTime.rb
CHANGED
@@ -2,71 +2,71 @@ require 'chronic'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestRepeaterTime < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
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
|