chronic 0.6.7 → 0.8.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/HISTORY.md +16 -0
- data/README.md +5 -0
- data/chronic.gemspec +3 -0
- data/lib/chronic/chronic.rb +81 -67
- data/lib/chronic/grabber.rb +9 -7
- data/lib/chronic/handler.rb +10 -12
- data/lib/chronic/handlers.rb +51 -9
- data/lib/chronic/ordinal.rb +12 -9
- data/lib/chronic/pointer.rb +9 -7
- data/lib/chronic/repeater.rb +29 -19
- data/lib/chronic/repeaters/repeater_day_portion.rb +25 -11
- data/lib/chronic/scalar.rb +30 -23
- data/lib/chronic/season.rb +1 -12
- data/lib/chronic/separator.rb +21 -15
- data/lib/chronic/tag.rb +5 -11
- data/lib/chronic/time_zone.rb +9 -7
- data/lib/chronic/token.rb +12 -10
- data/lib/chronic.rb +49 -43
- data/test/helper.rb +7 -1
- data/test/{test_Chronic.rb → test_chronic.rb} +8 -6
- data/test/{test_DaylightSavings.rb → test_daylight_savings.rb} +1 -1
- data/test/{test_Handler.rb → test_handler.rb} +1 -1
- data/test/{test_MiniDate.rb → test_mini_date.rb} +9 -9
- data/test/{test_Numerizer.rb → test_numerizer.rb} +1 -1
- data/test/test_parsing.rb +95 -10
- data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +1 -1
- data/test/test_repeater_day_portion.rb +254 -0
- data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +1 -1
- data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +1 -1
- data/test/{test_RepeaterMinute.rb → test_repeater_minute.rb} +1 -1
- data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +1 -1
- data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +1 -1
- data/test/{test_RepeaterSeason.rb → test_repeater_season.rb} +1 -1
- data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +1 -1
- data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +1 -1
- data/test/{test_RepeaterWeekday.rb → test_repeater_weekday.rb} +1 -1
- data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +1 -1
- data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +1 -1
- data/test/{test_Span.rb → test_span.rb} +1 -1
- data/test/{test_Token.rb → test_token.rb} +1 -1
- metadata +76 -44
- data/.gemtest +0 -0
- data/.yardopts +0 -3
data/test/test_parsing.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
class TestParsing <
|
|
3
|
+
class TestParsing < TestCase
|
|
4
4
|
# Wed Aug 16 14:00:00 UTC 2006
|
|
5
5
|
TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
6
6
|
|
|
@@ -8,6 +8,14 @@ class TestParsing < Test::Unit::TestCase
|
|
|
8
8
|
@time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
def test_handle_generic
|
|
12
|
+
time = Chronic.parse("2012-08-02T12:00:00+01:00")
|
|
13
|
+
assert_equal Time.local(2012, 8, 2, 12), time
|
|
14
|
+
|
|
15
|
+
time = Chronic.parse("2012-08-02T12:00:00Z")
|
|
16
|
+
assert_equal Time.utc(2012, 8, 2, 12), time
|
|
17
|
+
end
|
|
18
|
+
|
|
11
19
|
def test_handle_rmn_sd
|
|
12
20
|
time = parse_now("aug 3")
|
|
13
21
|
assert_equal Time.local(2006, 8, 3, 12), time
|
|
@@ -65,6 +73,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
65
73
|
assert_equal Time.local(2007, 5, 27, 5), time
|
|
66
74
|
end
|
|
67
75
|
|
|
76
|
+
def test_handle_od_rm
|
|
77
|
+
time = parse_now("fifteenth of this month")
|
|
78
|
+
assert_equal Time.local(2006, 8, 15, 12), time
|
|
79
|
+
end
|
|
80
|
+
|
|
68
81
|
def test_handle_od_rmn
|
|
69
82
|
time = parse_now("22nd February")
|
|
70
83
|
assert_equal Time.local(2007, 2, 22, 12), time
|
|
@@ -252,6 +265,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
252
265
|
|
|
253
266
|
time = parse_now("27/5/1979 @ 0700")
|
|
254
267
|
assert_equal Time.local(1979, 5, 27, 7), time
|
|
268
|
+
|
|
269
|
+
time = parse_now("03/18/2012 09:26 pm")
|
|
270
|
+
assert_equal Time.local(2012, 3, 18, 21, 26), time
|
|
255
271
|
end
|
|
256
272
|
|
|
257
273
|
def test_handle_sy_sm_sd
|
|
@@ -278,20 +294,46 @@ class TestParsing < Test::Unit::TestCase
|
|
|
278
294
|
|
|
279
295
|
time = parse_now("1902-08-20")
|
|
280
296
|
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
|
297
|
+
|
|
298
|
+
# exif date time original
|
|
299
|
+
time = parse_now("2012:05:25 22:06:50")
|
|
300
|
+
assert_equal Time.local(2012, 5, 25, 22, 6, 50), time
|
|
281
301
|
end
|
|
282
302
|
|
|
283
|
-
def
|
|
303
|
+
def test_handle_sm_sd
|
|
284
304
|
time = parse_now("05/06")
|
|
285
|
-
assert_equal Time.local(2006, 5,
|
|
305
|
+
assert_equal Time.local(2006, 5, 6, 12), time
|
|
286
306
|
|
|
287
|
-
time = parse_now("
|
|
288
|
-
assert_equal Time.local(2006,
|
|
307
|
+
time = parse_now("05/06", :endian_precedence => [:little, :medium])
|
|
308
|
+
assert_equal Time.local(2006, 6, 5, 12), time
|
|
289
309
|
|
|
290
|
-
time = parse_now("
|
|
291
|
-
assert_equal
|
|
310
|
+
time = parse_now("05/06 6:05:57 PM")
|
|
311
|
+
assert_equal Time.local(2006, 5, 6, 18, 05, 57), time
|
|
312
|
+
|
|
313
|
+
time = parse_now("05/06 6:05:57 PM", :endian_precedence => [:little, :medium])
|
|
314
|
+
assert_equal Time.local(2006, 6, 5, 18, 05, 57), time
|
|
315
|
+
|
|
316
|
+
time = parse_now("13/01")
|
|
317
|
+
assert_equal Time.local(2006, 1, 13, 12), time
|
|
292
318
|
end
|
|
293
319
|
|
|
320
|
+
# def test_handle_sm_sy
|
|
321
|
+
# time = parse_now("05/06")
|
|
322
|
+
# assert_equal Time.local(2006, 5, 16, 12), time
|
|
323
|
+
#
|
|
324
|
+
# time = parse_now("12/06")
|
|
325
|
+
# assert_equal Time.local(2006, 12, 16, 12), time
|
|
326
|
+
#
|
|
327
|
+
# time = parse_now("13/06")
|
|
328
|
+
# assert_equal nil, time
|
|
329
|
+
# end
|
|
330
|
+
|
|
294
331
|
def test_handle_r
|
|
332
|
+
time = parse_now("9am on Saturday")
|
|
333
|
+
assert_equal Time.local(2006, 8, 19, 9), time
|
|
334
|
+
|
|
335
|
+
time = parse_now("on Tuesday")
|
|
336
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
|
295
337
|
end
|
|
296
338
|
|
|
297
339
|
def test_handle_r_g_r
|
|
@@ -307,6 +349,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
307
349
|
end
|
|
308
350
|
|
|
309
351
|
def test_handle_s_r_p_a
|
|
352
|
+
time1 = parse_now("two days ago 0:0:0am")
|
|
353
|
+
time2 = parse_now("two days ago 00:00:00am")
|
|
354
|
+
assert_equal time1, time2
|
|
310
355
|
end
|
|
311
356
|
|
|
312
357
|
def test_handle_orr
|
|
@@ -354,6 +399,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
354
399
|
assert_equal Time.local(2006, 8, 9, 12), time
|
|
355
400
|
end
|
|
356
401
|
|
|
402
|
+
def test_handle_sm_rmn_sy
|
|
403
|
+
time = parse_now('30-Mar-11')
|
|
404
|
+
assert_equal Time.local(2011, 3, 30, 12), time
|
|
405
|
+
end
|
|
406
|
+
|
|
357
407
|
# end of testing handlers
|
|
358
408
|
|
|
359
409
|
def test_parse_guess_r
|
|
@@ -575,13 +625,33 @@ class TestParsing < Test::Unit::TestCase
|
|
|
575
625
|
time = parse_now("tonight")
|
|
576
626
|
assert_equal Time.local(2006, 8, 16, 22), time
|
|
577
627
|
|
|
628
|
+
# hour
|
|
629
|
+
|
|
630
|
+
time = parse_now("next hr")
|
|
631
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
|
632
|
+
|
|
633
|
+
time = parse_now("next hrs")
|
|
634
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
|
635
|
+
|
|
578
636
|
# minute
|
|
579
637
|
|
|
638
|
+
time = parse_now("next min")
|
|
639
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
640
|
+
|
|
641
|
+
time = parse_now("next mins")
|
|
642
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
643
|
+
|
|
580
644
|
time = parse_now("next minute")
|
|
581
645
|
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
582
646
|
|
|
583
647
|
# second
|
|
584
648
|
|
|
649
|
+
time = parse_now("next sec")
|
|
650
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
|
651
|
+
|
|
652
|
+
time = parse_now("next secs")
|
|
653
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
|
654
|
+
|
|
585
655
|
time = parse_now("this second")
|
|
586
656
|
assert_equal Time.local(2006, 8, 16, 14), time
|
|
587
657
|
|
|
@@ -674,6 +744,20 @@ class TestParsing < Test::Unit::TestCase
|
|
|
674
744
|
assert_equal Time.local(2006, 8, 8, 12), time
|
|
675
745
|
end
|
|
676
746
|
|
|
747
|
+
def test_parse_guess_a_ago
|
|
748
|
+
time = parse_now("AN hour ago")
|
|
749
|
+
assert_equal Time.local(2006, 8, 16, 13), time
|
|
750
|
+
|
|
751
|
+
time = parse_now("A day ago")
|
|
752
|
+
assert_equal Time.local(2006, 8, 15, 14), time
|
|
753
|
+
|
|
754
|
+
time = parse_now("a month ago")
|
|
755
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
|
756
|
+
|
|
757
|
+
time = parse_now("a year ago")
|
|
758
|
+
assert_equal Time.local(2005, 8, 16, 14), time
|
|
759
|
+
end
|
|
760
|
+
|
|
677
761
|
def test_parse_guess_s_r_p
|
|
678
762
|
# past
|
|
679
763
|
|
|
@@ -836,6 +920,7 @@ class TestParsing < Test::Unit::TestCase
|
|
|
836
920
|
assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
|
|
837
921
|
assert_equal parse_now("2867532 seconds from now"), parse_now("two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now")
|
|
838
922
|
assert_equal parse_now("may 10th"), parse_now("may tenth")
|
|
923
|
+
assert_equal parse_now("second monday in january"), parse_now("2nd monday in january")
|
|
839
924
|
end
|
|
840
925
|
|
|
841
926
|
def test_parse_only_complete_pointers
|
|
@@ -855,11 +940,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
855
940
|
end
|
|
856
941
|
|
|
857
942
|
def test_argument_validation
|
|
858
|
-
|
|
943
|
+
assert_raises(ArgumentError) do
|
|
859
944
|
time = Chronic.parse("may 27", :foo => :bar)
|
|
860
945
|
end
|
|
861
946
|
|
|
862
|
-
|
|
947
|
+
assert_raises(ArgumentError) do
|
|
863
948
|
time = Chronic.parse("may 27", :context => :bar)
|
|
864
949
|
end
|
|
865
950
|
end
|
|
@@ -915,7 +1000,7 @@ class TestParsing < Test::Unit::TestCase
|
|
|
915
1000
|
t1 = Chronic.parse("now")
|
|
916
1001
|
sleep 0.1
|
|
917
1002
|
t2 = Chronic.parse("now")
|
|
918
|
-
|
|
1003
|
+
refute_equal t1, t2
|
|
919
1004
|
end
|
|
920
1005
|
|
|
921
1006
|
def test_noon
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class TestRepeaterDayPortion < TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_am_future
|
|
10
|
+
day_portion = Chronic::RepeaterDayPortion.new(:am)
|
|
11
|
+
day_portion.start = @now
|
|
12
|
+
|
|
13
|
+
next_time = day_portion.next(:future)
|
|
14
|
+
assert_equal Time.local(2006, 8, 17, 00), next_time.begin
|
|
15
|
+
assert_equal Time.local(2006, 8, 17, 11, 59, 59), next_time.end
|
|
16
|
+
|
|
17
|
+
next_next_time = day_portion.next(:future)
|
|
18
|
+
assert_equal Time.local(2006, 8, 18, 00), next_next_time.begin
|
|
19
|
+
assert_equal Time.local(2006, 8, 18, 11, 59, 59), next_next_time.end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_am_past
|
|
23
|
+
day_portion = Chronic::RepeaterDayPortion.new(:am)
|
|
24
|
+
day_portion.start = @now
|
|
25
|
+
|
|
26
|
+
next_time = day_portion.next(:past)
|
|
27
|
+
assert_equal Time.local(2006, 8, 16, 00), next_time.begin
|
|
28
|
+
assert_equal Time.local(2006, 8, 16, 11, 59, 59), next_time.end
|
|
29
|
+
|
|
30
|
+
next_next_time = day_portion.next(:past)
|
|
31
|
+
assert_equal Time.local(2006, 8, 15, 00), next_next_time.begin
|
|
32
|
+
assert_equal Time.local(2006, 8, 15, 11, 59, 59), next_next_time.end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_am_future_with_daylight_savings_time_boundary
|
|
36
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
37
|
+
day_portion = Chronic::RepeaterDayPortion.new(:am)
|
|
38
|
+
day_portion.start = @now
|
|
39
|
+
|
|
40
|
+
next_time = day_portion.next(:future)
|
|
41
|
+
assert_equal Time.local(2012, 11, 4, 00), next_time.begin
|
|
42
|
+
assert_equal Time.local(2012, 11, 4, 11, 59, 59), next_time.end
|
|
43
|
+
|
|
44
|
+
next_next_time = day_portion.next(:future)
|
|
45
|
+
|
|
46
|
+
assert_equal Time.local(2012, 11, 5, 00), next_next_time.begin
|
|
47
|
+
assert_equal Time.local(2012, 11, 5, 11, 59, 59), next_next_time.end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_pm_future
|
|
51
|
+
day_portion = Chronic::RepeaterDayPortion.new(:pm)
|
|
52
|
+
day_portion.start = @now
|
|
53
|
+
|
|
54
|
+
next_time = day_portion.next(:future)
|
|
55
|
+
assert_equal Time.local(2006, 8, 17, 12), next_time.begin
|
|
56
|
+
assert_equal Time.local(2006, 8, 17, 23, 59, 59), next_time.end
|
|
57
|
+
|
|
58
|
+
next_next_time = day_portion.next(:future)
|
|
59
|
+
assert_equal Time.local(2006, 8, 18, 12), next_next_time.begin
|
|
60
|
+
assert_equal Time.local(2006, 8, 18, 23, 59, 59), next_next_time.end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_pm_past
|
|
64
|
+
day_portion = Chronic::RepeaterDayPortion.new(:pm)
|
|
65
|
+
day_portion.start = @now
|
|
66
|
+
|
|
67
|
+
next_time = day_portion.next(:past)
|
|
68
|
+
assert_equal Time.local(2006, 8, 15, 12), next_time.begin
|
|
69
|
+
assert_equal Time.local(2006, 8, 15, 23, 59, 59), next_time.end
|
|
70
|
+
|
|
71
|
+
next_next_time = day_portion.next(:past)
|
|
72
|
+
assert_equal Time.local(2006, 8, 14, 12), next_next_time.begin
|
|
73
|
+
assert_equal Time.local(2006, 8, 14, 23, 59, 59), next_next_time.end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_pm_future_with_daylight_savings_time_boundary
|
|
77
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
78
|
+
day_portion = Chronic::RepeaterDayPortion.new(:pm)
|
|
79
|
+
day_portion.start = @now
|
|
80
|
+
|
|
81
|
+
next_time = day_portion.next(:future)
|
|
82
|
+
assert_equal Time.local(2012, 11, 3, 12), next_time.begin
|
|
83
|
+
assert_equal Time.local(2012, 11, 3, 23, 59, 59), next_time.end
|
|
84
|
+
|
|
85
|
+
next_next_time = day_portion.next(:future)
|
|
86
|
+
|
|
87
|
+
assert_equal Time.local(2012, 11, 4, 12), next_next_time.begin
|
|
88
|
+
assert_equal Time.local(2012, 11, 4, 23, 59, 59), next_next_time.end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_morning_future
|
|
92
|
+
day_portion = Chronic::RepeaterDayPortion.new(:morning)
|
|
93
|
+
day_portion.start = @now
|
|
94
|
+
|
|
95
|
+
next_time = day_portion.next(:future)
|
|
96
|
+
assert_equal Time.local(2006, 8, 17, 6), next_time.begin
|
|
97
|
+
assert_equal Time.local(2006, 8, 17, 12), next_time.end
|
|
98
|
+
|
|
99
|
+
next_next_time = day_portion.next(:future)
|
|
100
|
+
assert_equal Time.local(2006, 8, 18, 6), next_next_time.begin
|
|
101
|
+
assert_equal Time.local(2006, 8, 18, 12), next_next_time.end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_morning_past
|
|
105
|
+
day_portion = Chronic::RepeaterDayPortion.new(:morning)
|
|
106
|
+
day_portion.start = @now
|
|
107
|
+
|
|
108
|
+
next_time = day_portion.next(:past)
|
|
109
|
+
assert_equal Time.local(2006, 8, 16, 6), next_time.begin
|
|
110
|
+
assert_equal Time.local(2006, 8, 16, 12), next_time.end
|
|
111
|
+
|
|
112
|
+
next_next_time = day_portion.next(:past)
|
|
113
|
+
assert_equal Time.local(2006, 8, 15, 6), next_next_time.begin
|
|
114
|
+
assert_equal Time.local(2006, 8, 15, 12), next_next_time.end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_morning_future_with_daylight_savings_time_boundary
|
|
118
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
119
|
+
day_portion = Chronic::RepeaterDayPortion.new(:morning)
|
|
120
|
+
day_portion.start = @now
|
|
121
|
+
|
|
122
|
+
next_time = day_portion.next(:future)
|
|
123
|
+
assert_equal Time.local(2012, 11, 3, 6), next_time.begin
|
|
124
|
+
assert_equal Time.local(2012, 11, 3, 12), next_time.end
|
|
125
|
+
|
|
126
|
+
next_next_time = day_portion.next(:future)
|
|
127
|
+
|
|
128
|
+
assert_equal Time.local(2012, 11, 4, 6), next_next_time.begin
|
|
129
|
+
assert_equal Time.local(2012, 11, 4, 12), next_next_time.end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_afternoon_future
|
|
133
|
+
day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
|
|
134
|
+
day_portion.start = @now
|
|
135
|
+
|
|
136
|
+
next_time = day_portion.next(:future)
|
|
137
|
+
assert_equal Time.local(2006, 8, 17, 13), next_time.begin
|
|
138
|
+
assert_equal Time.local(2006, 8, 17, 17), next_time.end
|
|
139
|
+
|
|
140
|
+
next_next_time = day_portion.next(:future)
|
|
141
|
+
assert_equal Time.local(2006, 8, 18, 13), next_next_time.begin
|
|
142
|
+
assert_equal Time.local(2006, 8, 18, 17), next_next_time.end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_afternoon_past
|
|
146
|
+
day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
|
|
147
|
+
day_portion.start = @now
|
|
148
|
+
|
|
149
|
+
next_time = day_portion.next(:past)
|
|
150
|
+
assert_equal Time.local(2006, 8, 15, 13), next_time.begin
|
|
151
|
+
assert_equal Time.local(2006, 8, 15, 17), next_time.end
|
|
152
|
+
|
|
153
|
+
next_next_time = day_portion.next(:past)
|
|
154
|
+
assert_equal Time.local(2006, 8, 14, 13), next_next_time.begin
|
|
155
|
+
assert_equal Time.local(2006, 8, 14, 17), next_next_time.end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_afternoon_future_with_daylight_savings_time_boundary
|
|
159
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
160
|
+
day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
|
|
161
|
+
day_portion.start = @now
|
|
162
|
+
|
|
163
|
+
next_time = day_portion.next(:future)
|
|
164
|
+
assert_equal Time.local(2012, 11, 3, 13), next_time.begin
|
|
165
|
+
assert_equal Time.local(2012, 11, 3, 17), next_time.end
|
|
166
|
+
|
|
167
|
+
next_next_time = day_portion.next(:future)
|
|
168
|
+
|
|
169
|
+
assert_equal Time.local(2012, 11, 4, 13), next_next_time.begin
|
|
170
|
+
assert_equal Time.local(2012, 11, 4, 17), next_next_time.end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def test_evening_future
|
|
174
|
+
day_portion = Chronic::RepeaterDayPortion.new(:evening)
|
|
175
|
+
day_portion.start = @now
|
|
176
|
+
|
|
177
|
+
next_time = day_portion.next(:future)
|
|
178
|
+
assert_equal Time.local(2006, 8, 16, 17), next_time.begin
|
|
179
|
+
assert_equal Time.local(2006, 8, 16, 20), next_time.end
|
|
180
|
+
|
|
181
|
+
next_next_time = day_portion.next(:future)
|
|
182
|
+
assert_equal Time.local(2006, 8, 17, 17), next_next_time.begin
|
|
183
|
+
assert_equal Time.local(2006, 8, 17, 20), next_next_time.end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def test_evening_past
|
|
187
|
+
day_portion = Chronic::RepeaterDayPortion.new(:evening)
|
|
188
|
+
day_portion.start = @now
|
|
189
|
+
|
|
190
|
+
next_time = day_portion.next(:past)
|
|
191
|
+
assert_equal Time.local(2006, 8, 15, 17), next_time.begin
|
|
192
|
+
assert_equal Time.local(2006, 8, 15, 20), next_time.end
|
|
193
|
+
|
|
194
|
+
next_next_time = day_portion.next(:past)
|
|
195
|
+
assert_equal Time.local(2006, 8, 14, 17), next_next_time.begin
|
|
196
|
+
assert_equal Time.local(2006, 8, 14, 20), next_next_time.end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_evening_future_with_daylight_savings_time_boundary
|
|
200
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
201
|
+
day_portion = Chronic::RepeaterDayPortion.new(:evening)
|
|
202
|
+
day_portion.start = @now
|
|
203
|
+
|
|
204
|
+
next_time = day_portion.next(:future)
|
|
205
|
+
assert_equal Time.local(2012, 11, 3, 17), next_time.begin
|
|
206
|
+
assert_equal Time.local(2012, 11, 3, 20), next_time.end
|
|
207
|
+
|
|
208
|
+
next_next_time = day_portion.next(:future)
|
|
209
|
+
|
|
210
|
+
assert_equal Time.local(2012, 11, 4, 17), next_next_time.begin
|
|
211
|
+
assert_equal Time.local(2012, 11, 4, 20), next_next_time.end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def test_night_future
|
|
215
|
+
day_portion = Chronic::RepeaterDayPortion.new(:night)
|
|
216
|
+
day_portion.start = @now
|
|
217
|
+
|
|
218
|
+
next_time = day_portion.next(:future)
|
|
219
|
+
assert_equal Time.local(2006, 8, 16, 20), next_time.begin
|
|
220
|
+
assert_equal Time.local(2006, 8, 17, 0), next_time.end
|
|
221
|
+
|
|
222
|
+
next_next_time = day_portion.next(:future)
|
|
223
|
+
assert_equal Time.local(2006, 8, 17, 20), next_next_time.begin
|
|
224
|
+
assert_equal Time.local(2006, 8, 18, 0), next_next_time.end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def test_night_past
|
|
228
|
+
day_portion = Chronic::RepeaterDayPortion.new(:night)
|
|
229
|
+
day_portion.start = @now
|
|
230
|
+
|
|
231
|
+
next_time = day_portion.next(:past)
|
|
232
|
+
assert_equal Time.local(2006, 8, 15, 20), next_time.begin
|
|
233
|
+
assert_equal Time.local(2006, 8, 16, 0), next_time.end
|
|
234
|
+
|
|
235
|
+
next_next_time = day_portion.next(:past)
|
|
236
|
+
assert_equal Time.local(2006, 8, 14, 20), next_next_time.begin
|
|
237
|
+
assert_equal Time.local(2006, 8, 15, 0), next_next_time.end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def test_night_future_with_daylight_savings_time_boundary
|
|
241
|
+
@now = Time.local(2012,11,3,0,0,0)
|
|
242
|
+
day_portion = Chronic::RepeaterDayPortion.new(:night)
|
|
243
|
+
day_portion.start = @now
|
|
244
|
+
|
|
245
|
+
next_time = day_portion.next(:future)
|
|
246
|
+
assert_equal Time.local(2012, 11, 3, 20), next_time.begin
|
|
247
|
+
assert_equal Time.local(2012, 11, 4, 0), next_time.end
|
|
248
|
+
|
|
249
|
+
next_next_time = day_portion.next(:future)
|
|
250
|
+
|
|
251
|
+
assert_equal Time.local(2012, 11, 4, 20), next_next_time.begin
|
|
252
|
+
assert_equal Time.local(2012, 11, 5, 0), next_next_time.end
|
|
253
|
+
end
|
|
254
|
+
end
|