-
Notifications
You must be signed in to change notification settings - Fork 454
/
test_repeater_weekday.rb
55 lines (41 loc) · 1.79 KB
/
test_repeater_weekday.rb
1
2
3
4
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
require 'helper'
class TestRepeaterWeekday < TestCase
def setup
@now = Time.local(2007, 6, 11, 14, 0, 0, 0) # Mon
end
def test_next_future
weekdays = Chronic::RepeaterWeekday.new(:weekday)
weekdays.start = @now
next1_weekday = weekdays.next(:future) # Tues
assert_equal Time.local(2007, 6, 12), next1_weekday.begin
assert_equal Time.local(2007, 6, 13), next1_weekday.end
next2_weekday = weekdays.next(:future) # Wed
assert_equal Time.local(2007, 6, 13), next2_weekday.begin
assert_equal Time.local(2007, 6, 14), next2_weekday.end
next3_weekday = weekdays.next(:future) # Thurs
assert_equal Time.local(2007, 6, 14), next3_weekday.begin
assert_equal Time.local(2007, 6, 15), next3_weekday.end
next4_weekday = weekdays.next(:future) # Fri
assert_equal Time.local(2007, 6, 15), next4_weekday.begin
assert_equal Time.local(2007, 6, 16), next4_weekday.end
next5_weekday = weekdays.next(:future) # Mon
assert_equal Time.local(2007, 6, 18), next5_weekday.begin
assert_equal Time.local(2007, 6, 19), next5_weekday.end
end
def test_next_past
weekdays = Chronic::RepeaterWeekday.new(:weekday)
weekdays.start = @now
last1_weekday = weekdays.next(:past) # Fri
assert_equal Time.local(2007, 6, 8), last1_weekday.begin
assert_equal Time.local(2007, 6, 9), last1_weekday.end
last2_weekday = weekdays.next(:past) # Thurs
assert_equal Time.local(2007, 6, 7), last2_weekday.begin
assert_equal Time.local(2007, 6, 8), last2_weekday.end
end
def test_offset
span = Chronic::Span.new(@now, @now + 1)
offset_span = Chronic::RepeaterWeekday.new(:weekday).offset(span, 5, :future)
assert_equal Time.local(2007, 6, 18, 14), offset_span.begin
assert_equal Time.local(2007, 6, 18, 14, 0, 1), offset_span.end
end
end