ice_cube 0.7.11 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/ice_cube/rule.rb
CHANGED
data/lib/ice_cube/time_util.rb
CHANGED
@@ -64,6 +64,18 @@ module IceCube
|
|
64
64
|
day
|
65
65
|
end
|
66
66
|
|
67
|
+
# Convert a symbol to an ical day (SU, MO)
|
68
|
+
def self.week_start(sym)
|
69
|
+
raise "No such day: #{sym}" unless DAYS.keys.include?(sym)
|
70
|
+
day = sym.to_s.upcase[0..1]
|
71
|
+
day
|
72
|
+
end
|
73
|
+
|
74
|
+
# Convert weekday from base sunday to the schedule's week start.
|
75
|
+
def self.normalize_weekday(daynum, week_start)
|
76
|
+
(daynum - symbol_to_day(week_start)) % 7
|
77
|
+
end
|
78
|
+
|
67
79
|
# Return the count of the number of times wday appears in the month,
|
68
80
|
# and which of those time falls on
|
69
81
|
def self.which_occurrence_in_month(time, wday)
|
@@ -93,7 +105,7 @@ module IceCube
|
|
93
105
|
def self.days_in_month_year(month, year)
|
94
106
|
is_leap?(year) ? LEAP_YEAR_MONTH_DAYS[month - 1] : COMMON_YEAR_MONTH_DAYS[month - 1]
|
95
107
|
end
|
96
|
-
|
108
|
+
|
97
109
|
# Number of days in a year
|
98
110
|
def self.days_in_year(time)
|
99
111
|
is_leap?(time.year) ? 366 : 365
|
@@ -190,7 +202,7 @@ module IceCube
|
|
190
202
|
yield
|
191
203
|
end
|
192
204
|
end
|
193
|
-
|
205
|
+
|
194
206
|
def clear_sec
|
195
207
|
@time -= @time.sec
|
196
208
|
end
|
@@ -4,14 +4,15 @@ module IceCube
|
|
4
4
|
|
5
5
|
module Validations::WeeklyInterval
|
6
6
|
|
7
|
-
def interval(interval)
|
8
|
-
validations_for(:interval) << Validation.new(interval)
|
7
|
+
def interval(interval, week_start = :sunday)
|
8
|
+
validations_for(:interval) << Validation.new(interval, week_start)
|
9
9
|
clobber_base_validations(:day)
|
10
|
+
self
|
10
11
|
end
|
11
12
|
|
12
13
|
class Validation
|
13
14
|
|
14
|
-
attr_reader :interval
|
15
|
+
attr_reader :interval, :week_start
|
15
16
|
|
16
17
|
def type
|
17
18
|
:day
|
@@ -25,6 +26,7 @@ module IceCube
|
|
25
26
|
builder['FREQ'] << 'WEEKLY'
|
26
27
|
unless interval == 1
|
27
28
|
builder['INTERVAL'] << interval
|
29
|
+
builder['WKST'] << TimeUtil.week_start(week_start)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -32,15 +34,19 @@ module IceCube
|
|
32
34
|
builder[:interval] = interval
|
33
35
|
end
|
34
36
|
|
35
|
-
def initialize(interval)
|
37
|
+
def initialize(interval, week_start)
|
36
38
|
@interval = interval
|
39
|
+
@week_start = week_start
|
37
40
|
end
|
38
41
|
|
39
42
|
def validate(time, schedule)
|
40
43
|
date = Date.new(time.year, time.month, time.day)
|
41
44
|
st = schedule.start_time
|
42
45
|
start_date = Date.new(st.year, st.month, st.day)
|
43
|
-
weeks = (
|
46
|
+
weeks = (
|
47
|
+
(date - TimeUtil.normalize_weekday(date.wday, week_start)) -
|
48
|
+
(start_date - TimeUtil.normalize_weekday(start_date.wday, week_start))
|
49
|
+
) / 7
|
44
50
|
unless weeks % interval == 0
|
45
51
|
(interval - (weeks % interval)) * 7
|
46
52
|
end
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70300114106600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70300114106600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: active_support
|
27
|
-
requirement: &
|
27
|
+
requirement: &70300114105840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70300114105840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tzinfo
|
38
|
-
requirement: &
|
38
|
+
requirement: &70300114105260 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70300114105260
|
47
47
|
description: ice_cube is a recurring date library for Ruby. It allows for quick,
|
48
48
|
programatic expansion of recurring date rules.
|
49
49
|
email: john@crepezzi.com
|