chronic 0.6.5 → 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.
Files changed (44) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.md +25 -0
  3. data/README.md +5 -0
  4. data/chronic.gemspec +3 -0
  5. data/lib/chronic/chronic.rb +82 -67
  6. data/lib/chronic/grabber.rb +9 -7
  7. data/lib/chronic/handler.rb +10 -12
  8. data/lib/chronic/handlers.rb +84 -11
  9. data/lib/chronic/ordinal.rb +12 -9
  10. data/lib/chronic/pointer.rb +9 -7
  11. data/lib/chronic/repeater.rb +30 -20
  12. data/lib/chronic/repeaters/repeater_day_portion.rb +25 -11
  13. data/lib/chronic/scalar.rb +30 -23
  14. data/lib/chronic/season.rb +1 -12
  15. data/lib/chronic/separator.rb +21 -15
  16. data/lib/chronic/tag.rb +5 -11
  17. data/lib/chronic/time_zone.rb +9 -7
  18. data/lib/chronic/token.rb +12 -10
  19. data/lib/chronic.rb +50 -44
  20. data/test/helper.rb +7 -1
  21. data/test/{test_Chronic.rb → test_chronic.rb} +8 -6
  22. data/test/{test_DaylightSavings.rb → test_daylight_savings.rb} +1 -1
  23. data/test/{test_Handler.rb → test_handler.rb} +1 -1
  24. data/test/{test_MiniDate.rb → test_mini_date.rb} +9 -9
  25. data/test/{test_Numerizer.rb → test_numerizer.rb} +1 -1
  26. data/test/test_parsing.rb +149 -10
  27. data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +1 -1
  28. data/test/test_repeater_day_portion.rb +254 -0
  29. data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +1 -1
  30. data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +1 -1
  31. data/test/{test_RepeaterMinute.rb → test_repeater_minute.rb} +1 -1
  32. data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +1 -1
  33. data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +1 -1
  34. data/test/{test_RepeaterSeason.rb → test_repeater_season.rb} +1 -1
  35. data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +1 -1
  36. data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +1 -1
  37. data/test/{test_RepeaterWeekday.rb → test_repeater_weekday.rb} +1 -1
  38. data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +1 -1
  39. data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +1 -1
  40. data/test/{test_Span.rb → test_span.rb} +1 -1
  41. data/test/{test_Token.rb → test_token.rb} +1 -1
  42. metadata +76 -44
  43. data/.gemtest +0 -0
  44. data/.yardopts +0 -3
@@ -1,12 +1,16 @@
1
1
  require 'helper'
2
2
 
3
- class TestChronic < Test::Unit::TestCase
3
+ class TestChronic < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 UTC 2006
7
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
8
  end
9
9
 
10
+ def test_pre_normalize
11
+ assert_equal Chronic.pre_normalize('12:55 pm'), Chronic.pre_normalize('12.55 pm')
12
+ end
13
+
10
14
  def test_pre_normalize_numerized_string
11
15
  string = 'two and a half years'
12
16
  assert_equal Chronic::Numerizer.numerize(string), Chronic.pre_normalize(string)
@@ -63,6 +67,8 @@ class TestChronic < Test::Unit::TestCase
63
67
  # middle, little
64
68
  endians = [
65
69
  Chronic::Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sm_sd_sy),
70
+ Chronic::Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sm_sd),
71
+ Chronic::Handler.new([:scalar_day, :separator_slash_or_dash, :scalar_month, :separator_at?, 'time?'], :handle_sd_sm),
66
72
  Chronic::Handler.new([:scalar_day, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sd_sm_sy)
67
73
  ]
68
74
 
@@ -131,11 +137,7 @@ class TestChronic < Test::Unit::TestCase
131
137
  assert_equal Time.local(2004, 3, 4), Chronic.construct(2004, 2, 33)
132
138
  assert_equal Time.local(2000, 3, 4), Chronic.construct(2000, 2, 33)
133
139
 
134
- assert_nothing_raised do
135
- Chronic.construct(2006, 1, 56)
136
- end
137
-
138
- assert_raise(RuntimeError) do
140
+ assert_raises(RuntimeError) do
139
141
  Chronic.construct(2006, 1, 57)
140
142
  end
141
143
  end
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestDaylightSavings < Test::Unit::TestCase
3
+ class TestDaylightSavings < TestCase
4
4
 
5
5
  def setup
6
6
  @begin_daylight_savings = Time.local(2008, 3, 9, 5, 0, 0, 0)
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestHandler < Test::Unit::TestCase
3
+ class TestHandler < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 UTC 2006
@@ -1,32 +1,32 @@
1
1
  require 'helper'
2
2
 
3
- class TestMiniDate < Test::Unit::TestCase
3
+ class TestMiniDate < TestCase
4
4
  def test_valid_month
5
- assert_raise(ArgumentError){ Chronic::MiniDate.new(0,12) }
6
- assert_raise(ArgumentError){ Chronic::MiniDate.new(13,1) }
5
+ assert_raises(ArgumentError){ Chronic::MiniDate.new(0,12) }
6
+ assert_raises(ArgumentError){ Chronic::MiniDate.new(13,1) }
7
7
  end
8
-
8
+
9
9
  def test_is_between
10
10
  m=Chronic::MiniDate.new(3,2)
11
11
  assert m.is_between?(Chronic::MiniDate.new(2,4), Chronic::MiniDate.new(4,7))
12
- assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
13
-
12
+ assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
13
+
14
14
  #There was a hang if date tested is in december and outside the testing range
15
15
  m=Chronic::MiniDate.new(12,24)
16
16
  assert !m.is_between?(Chronic::MiniDate.new(10,1), Chronic::MiniDate.new(12,21))
17
17
  end
18
-
18
+
19
19
  def test_is_between_short_range
20
20
  m=Chronic::MiniDate.new(5,10)
21
21
  assert m.is_between?(Chronic::MiniDate.new(5,3), Chronic::MiniDate.new(5,12))
22
22
  assert !m.is_between?(Chronic::MiniDate.new(5,11), Chronic::MiniDate.new(5,15))
23
23
  end
24
-
24
+
25
25
  def test_is_between_wrapping_range
26
26
  m=Chronic::MiniDate.new(1,1)
27
27
  assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(2,2))
28
28
  m=Chronic::MiniDate.new(12,12)
29
29
  assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(1,5))
30
30
  end
31
-
31
+
32
32
  end
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class ParseNumbersTest < Test::Unit::TestCase
3
+ class ParseNumbersTest < TestCase
4
4
 
5
5
  def test_straight_parsing
6
6
  strings = {
data/test/test_parsing.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestParsing < Test::Unit::TestCase
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 test_handle_sm_sy
303
+ def test_handle_sm_sd
284
304
  time = parse_now("05/06")
285
- assert_equal Time.local(2006, 5, 16, 12), time
305
+ assert_equal Time.local(2006, 5, 6, 12), time
286
306
 
287
- time = parse_now("12/06")
288
- assert_equal Time.local(2006, 12, 16, 12), time
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("13/06")
291
- assert_equal nil, time
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
@@ -539,6 +589,34 @@ class TestParsing < Test::Unit::TestCase
539
589
  time = parse_now("last wed")
540
590
  assert_equal Time.local(2006, 8, 9, 12), time
541
591
 
592
+ monday = Time.local(2006, 8, 21, 12)
593
+ assert_equal monday, parse_now("mon")
594
+ assert_equal monday, parse_now("mun")
595
+
596
+ tuesday = Time.local(2006, 8, 22, 12)
597
+ assert_equal tuesday, parse_now("tue")
598
+ assert_equal tuesday, parse_now("tus")
599
+
600
+ wednesday = Time.local(2006, 8, 23, 12)
601
+ assert_equal wednesday, parse_now("wed")
602
+ assert_equal wednesday, parse_now("wenns")
603
+
604
+ thursday = Time.local(2006, 8, 17, 12)
605
+ assert_equal thursday, parse_now("thu")
606
+ assert_equal thursday, parse_now("thur")
607
+
608
+ friday = Time.local(2006, 8, 18, 12)
609
+ assert_equal friday, parse_now("fri")
610
+ assert_equal friday, parse_now("fry")
611
+
612
+ saturday = Time.local(2006, 8, 19, 12)
613
+ assert_equal saturday, parse_now("sat")
614
+ assert_equal saturday, parse_now("satterday")
615
+
616
+ sunday = Time.local(2006, 8, 20, 12)
617
+ assert_equal sunday, parse_now("sun")
618
+ assert_equal sunday, parse_now("sum")
619
+
542
620
  # day portion
543
621
 
544
622
  time = parse_now("this morning")
@@ -547,13 +625,33 @@ class TestParsing < Test::Unit::TestCase
547
625
  time = parse_now("tonight")
548
626
  assert_equal Time.local(2006, 8, 16, 22), time
549
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
+
550
636
  # minute
551
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
+
552
644
  time = parse_now("next minute")
553
645
  assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
554
646
 
555
647
  # second
556
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
+
557
655
  time = parse_now("this second")
558
656
  assert_equal Time.local(2006, 8, 16, 14), time
559
657
 
@@ -646,6 +744,20 @@ class TestParsing < Test::Unit::TestCase
646
744
  assert_equal Time.local(2006, 8, 8, 12), time
647
745
  end
648
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
+
649
761
  def test_parse_guess_s_r_p
650
762
  # past
651
763
 
@@ -808,6 +920,7 @@ class TestParsing < Test::Unit::TestCase
808
920
  assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
809
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")
810
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")
811
924
  end
812
925
 
813
926
  def test_parse_only_complete_pointers
@@ -827,11 +940,11 @@ class TestParsing < Test::Unit::TestCase
827
940
  end
828
941
 
829
942
  def test_argument_validation
830
- assert_raise(ArgumentError) do
943
+ assert_raises(ArgumentError) do
831
944
  time = Chronic.parse("may 27", :foo => :bar)
832
945
  end
833
946
 
834
- assert_raise(ArgumentError) do
947
+ assert_raises(ArgumentError) do
835
948
  time = Chronic.parse("may 27", :context => :bar)
836
949
  end
837
950
  end
@@ -887,7 +1000,7 @@ class TestParsing < Test::Unit::TestCase
887
1000
  t1 = Chronic.parse("now")
888
1001
  sleep 0.1
889
1002
  t2 = Chronic.parse("now")
890
- assert_not_equal t1, t2
1003
+ refute_equal t1, t2
891
1004
  end
892
1005
 
893
1006
  def test_noon
@@ -898,11 +1011,37 @@ class TestParsing < Test::Unit::TestCase
898
1011
  def test_handle_rdn_rmn_sd
899
1012
  time = parse_now("Thu Aug 10")
900
1013
  assert_equal Time.local(2006, 8, 10, 12), time
1014
+
1015
+ time = parse_now("Thursday July 31")
1016
+ assert_equal Time.local(2006, 7, 31, 12), time
1017
+
1018
+ time = parse_now("Thursday December 31")
1019
+ assert_equal Time.local(2006, 12, 31, 12), time
1020
+ end
1021
+
1022
+ def test_handle_rdn_rmn_sd_sy
1023
+ time = parse_now("Thu Aug 10 2006")
1024
+ assert_equal Time.local(2006, 8, 10, 12), time
1025
+
1026
+ time = parse_now("Thursday July 31 2006")
1027
+ assert_equal Time.local(2006, 7, 31, 12), time
1028
+
1029
+ time = parse_now("Thursday December 31 2006")
1030
+ assert_equal Time.local(2006, 12, 31, 12), time
1031
+
1032
+ time = parse_now("Thursday December 30 2006")
1033
+ assert_equal Time.local(2006, 12, 30, 12), time
901
1034
  end
902
1035
 
903
1036
  def test_handle_rdn_rmn_od
904
1037
  time = parse_now("Thu Aug 10th")
905
1038
  assert_equal Time.local(2006, 8, 10, 12), time
1039
+
1040
+ time = parse_now("Thursday July 31st")
1041
+ assert_equal Time.local(2006, 7, 31, 12), time
1042
+
1043
+ time = parse_now("Thursday December 31st")
1044
+ assert_equal Time.local(2006, 12, 31, 12), time
906
1045
  end
907
1046
 
908
1047
  private
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterDayName < Test::Unit::TestCase
3
+ class TestRepeaterDayName < TestCase
4
4
 
5
5
  def setup
6
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
@@ -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
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterFortnight < Test::Unit::TestCase
3
+ class TestRepeaterFortnight < TestCase
4
4
 
5
5
  def setup
6
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterHour < Test::Unit::TestCase
3
+ class TestRepeaterHour < TestCase
4
4
 
5
5
  def setup
6
6
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterMinute < Test::Unit::TestCase
3
+ class TestRepeaterMinute < TestCase
4
4
 
5
5
  def setup
6
6
  @now = Time.local(2008, 6, 25, 7, 15, 30, 0)
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterMonth < Test::Unit::TestCase
3
+ class TestRepeaterMonth < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 2006
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestRepeaterMonthName < Test::Unit::TestCase
3
+ class TestRepeaterMonthName < TestCase
4
4
 
5
5
  def setup
6
6
  # Wed Aug 16 14:00:00 2006