ice_cube 0.16.2 → 0.16.4
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.
- checksums.yaml +5 -5
- data/config/locales/de.yml +1 -1
- data/config/locales/fr.yml +2 -2
- data/config/locales/it.yml +179 -0
- data/config/locales/nl.yml +133 -0
- data/config/locales/sv.yml +1 -1
- data/lib/ice_cube/i18n.rb +11 -12
- data/lib/ice_cube/input_alignment.rb +89 -0
- data/lib/ice_cube/null_i18n.rb +12 -6
- data/lib/ice_cube/occurrence.rb +25 -23
- data/lib/ice_cube/parsers/ical_parser.rb +8 -5
- data/lib/ice_cube/rule.rb +4 -11
- data/lib/ice_cube/rules/daily_rule.rb +9 -0
- data/lib/ice_cube/rules/hourly_rule.rb +9 -0
- data/lib/ice_cube/rules/minutely_rule.rb +9 -0
- data/lib/ice_cube/rules/monthly_rule.rb +9 -0
- data/lib/ice_cube/rules/secondly_rule.rb +9 -0
- data/lib/ice_cube/rules/weekly_rule.rb +10 -1
- data/lib/ice_cube/rules/yearly_rule.rb +9 -0
- data/lib/ice_cube/schedule.rb +10 -9
- data/lib/ice_cube/single_occurrence_rule.rb +4 -0
- data/lib/ice_cube/time_util.rb +26 -16
- data/lib/ice_cube/validated_rule.rb +10 -19
- data/lib/ice_cube/validations/count.rb +1 -2
- data/lib/ice_cube/validations/daily_interval.rb +5 -1
- data/lib/ice_cube/validations/day.rb +6 -2
- data/lib/ice_cube/validations/day_of_month.rb +5 -0
- data/lib/ice_cube/validations/hour_of_day.rb +23 -0
- data/lib/ice_cube/validations/hourly_interval.rb +2 -0
- data/lib/ice_cube/validations/minute_of_hour.rb +16 -0
- data/lib/ice_cube/validations/minutely_interval.rb +2 -0
- data/lib/ice_cube/validations/month_of_year.rb +5 -0
- data/lib/ice_cube/validations/monthly_interval.rb +4 -1
- data/lib/ice_cube/validations/schedule_lock.rb +4 -0
- data/lib/ice_cube/validations/second_of_minute.rb +19 -3
- data/lib/ice_cube/validations/secondly_interval.rb +2 -0
- data/lib/ice_cube/validations/until.rb +1 -2
- data/lib/ice_cube/validations/weekly_interval.rb +0 -2
- data/lib/ice_cube/version.rb +1 -1
- data/lib/ice_cube.rb +1 -3
- data/spec/spec_helper.rb +32 -9
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f736ccbe2ce60c734d37420278729ecf69b8fb9a31716aff0c2ca22df02020e
|
4
|
+
data.tar.gz: abda4a9eaad18bf0ff1f7a57056542dcffdc210fab6ba7634d0977893bb6decd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 474281dcabc90c8a25b5789b5a49dac347afbc89b7d1b31accb5d07fa4f8c1a5a8c440669b61733f49a24d5b7dae4ff5add7cf2e39831ca198dbbc3b524c9749
|
7
|
+
data.tar.gz: 00d8c976dc6b6513f3a6e3170ed0f7022fc7ea04bdb2d592dfb7ac7d29b2744d07bd4c21006f822f58ba05e4dfeb312c9dc97d35f521f69fefef485b9b06c8bb
|
data/config/locales/de.yml
CHANGED
data/config/locales/fr.yml
CHANGED
@@ -137,7 +137,7 @@ fr:
|
|
137
137
|
- dimanche
|
138
138
|
- lundi
|
139
139
|
- mardi
|
140
|
-
-
|
140
|
+
- mercredi
|
141
141
|
- jeudi
|
142
142
|
- vendredi
|
143
143
|
- samedi
|
@@ -170,4 +170,4 @@ fr:
|
|
170
170
|
default: "%a, %d %b %Y %H:%M:%S %z"
|
171
171
|
long: "%d %B %Y %H:%M"
|
172
172
|
short: "%d %b %H:%M"
|
173
|
-
pm: pm
|
173
|
+
pm: pm
|
@@ -0,0 +1,179 @@
|
|
1
|
+
it:
|
2
|
+
ice_cube:
|
3
|
+
pieces_connector: ' / '
|
4
|
+
not: 'tranne %{target}'
|
5
|
+
not_on: 'tranne %{target}'
|
6
|
+
date:
|
7
|
+
formats:
|
8
|
+
default: '%-d. %B %Y'
|
9
|
+
month_names:
|
10
|
+
-
|
11
|
+
- gennaio
|
12
|
+
- febbraio
|
13
|
+
- marzo
|
14
|
+
- aprile
|
15
|
+
- maggio
|
16
|
+
- giugno
|
17
|
+
- luglio
|
18
|
+
- agosto
|
19
|
+
- settembre
|
20
|
+
- ottobre
|
21
|
+
- novembre
|
22
|
+
- dicembre
|
23
|
+
day_names:
|
24
|
+
- domenica
|
25
|
+
- lunedì
|
26
|
+
- martedì
|
27
|
+
- mercoledì
|
28
|
+
- giovedì
|
29
|
+
- venerdì
|
30
|
+
- sabato
|
31
|
+
times:
|
32
|
+
other: '%{count} volte'
|
33
|
+
one: '%{count} volta'
|
34
|
+
until: 'fino al %{date}'
|
35
|
+
days_of_week: '%{segments} %{day}'
|
36
|
+
days_of_month:
|
37
|
+
one: '%{segments} giorno del mese'
|
38
|
+
other: '%{segments} giorni del mese'
|
39
|
+
days_of_year:
|
40
|
+
one: "%{segments} giorno dell'anno"
|
41
|
+
other: "%{segments} giorni dell'anno"
|
42
|
+
at_hours_of_the_day:
|
43
|
+
one: alla %{segments} ora del giorno
|
44
|
+
other: alla %{segments} ora del giorno
|
45
|
+
on_minutes_of_hour:
|
46
|
+
one: al %{segments} minuto dell'ora
|
47
|
+
other: al %{segments} minuto dell'ora
|
48
|
+
at_seconds_of_minute:
|
49
|
+
one: al %{segments} secondo
|
50
|
+
other: al %{segments} secondo
|
51
|
+
on_seconds_of_minute:
|
52
|
+
one: al %{segments} secondo del minuto
|
53
|
+
other: al %{segments} secondo del minuto
|
54
|
+
each_second:
|
55
|
+
one: ogni secondo
|
56
|
+
other: Ogni %{count} secondi
|
57
|
+
each_minute:
|
58
|
+
one: Ogni minuto
|
59
|
+
other: Ogni %{count} minuti
|
60
|
+
each_hour:
|
61
|
+
one: Ogni ora
|
62
|
+
other: Ogni %{count} ore
|
63
|
+
each_day:
|
64
|
+
one: Ogni giorno
|
65
|
+
other: Ogni %{count} giorni
|
66
|
+
each_week:
|
67
|
+
one: Ogni settimana
|
68
|
+
other: Ogni %{count} settimane
|
69
|
+
each_month:
|
70
|
+
one: Ogni mese
|
71
|
+
other: Ogni %{count} mesi
|
72
|
+
each_year:
|
73
|
+
one: Ogni anno
|
74
|
+
other: Ogni %{count} anni
|
75
|
+
'on': il %{sentence}
|
76
|
+
in: 'a %{target}'
|
77
|
+
integer:
|
78
|
+
negative: '%{ordinal}. e ultimo'
|
79
|
+
literal_ordinals:
|
80
|
+
-1: ultimo
|
81
|
+
-2: penultimo
|
82
|
+
ordinal: '%{number}%{ordinal}'
|
83
|
+
ordinals:
|
84
|
+
default: '.'
|
85
|
+
# 1: st
|
86
|
+
# 2: nd
|
87
|
+
# 3: rd
|
88
|
+
# 11: th
|
89
|
+
# 12: th
|
90
|
+
# 13: th
|
91
|
+
on_weekends: nel fine settimana
|
92
|
+
on_weekdays: nei giorni feriali
|
93
|
+
days_on:
|
94
|
+
- di domenica
|
95
|
+
- di lunedì
|
96
|
+
- di martedì
|
97
|
+
- di mercoledì
|
98
|
+
- di giovedì
|
99
|
+
- di venerdì
|
100
|
+
- di sabato
|
101
|
+
on_days: '%{days}'
|
102
|
+
array:
|
103
|
+
last_word_connector: ' e '
|
104
|
+
two_words_connector: ' e '
|
105
|
+
words_connector: ', '
|
106
|
+
string:
|
107
|
+
format:
|
108
|
+
day: '%{rest} %{current}'
|
109
|
+
day_of_week: '%{rest} %{current}'
|
110
|
+
day_of_month: '%{rest} %{current}'
|
111
|
+
day_of_year: '%{rest} %{current}'
|
112
|
+
hour_of_day: '%{rest} %{current}'
|
113
|
+
minute_of_hour: '%{rest} %{current}'
|
114
|
+
until: '%{rest} %{current}'
|
115
|
+
count: '%{rest} %{current}'
|
116
|
+
default: '%{rest} %{current}'
|
117
|
+
|
118
|
+
date:
|
119
|
+
abbr_day_names:
|
120
|
+
- dom
|
121
|
+
- lun
|
122
|
+
- mar
|
123
|
+
- mer
|
124
|
+
- gio
|
125
|
+
- ven
|
126
|
+
- sab
|
127
|
+
abbr_month_names:
|
128
|
+
-
|
129
|
+
- gen
|
130
|
+
- feb
|
131
|
+
- mar
|
132
|
+
- apr
|
133
|
+
- mag
|
134
|
+
- giu
|
135
|
+
- lug
|
136
|
+
- ago
|
137
|
+
- set
|
138
|
+
- ott
|
139
|
+
- nov
|
140
|
+
- dic
|
141
|
+
day_names:
|
142
|
+
- domenica
|
143
|
+
- lunedì
|
144
|
+
- martedì
|
145
|
+
- mercoledì
|
146
|
+
- giovedì
|
147
|
+
- venerdì
|
148
|
+
- sabato
|
149
|
+
formats:
|
150
|
+
default: "%d/%m/%Y"
|
151
|
+
long: "%d %B %Y"
|
152
|
+
short: "%d %b"
|
153
|
+
month_names:
|
154
|
+
-
|
155
|
+
- gennaio
|
156
|
+
- febbraio
|
157
|
+
- marzo
|
158
|
+
- aprile
|
159
|
+
- maggio
|
160
|
+
- giugno
|
161
|
+
- luglio
|
162
|
+
- agosto
|
163
|
+
- settembre
|
164
|
+
- ottobre
|
165
|
+
- novembre
|
166
|
+
- dicembre
|
167
|
+
order:
|
168
|
+
- :day
|
169
|
+
- :month
|
170
|
+
- :year
|
171
|
+
|
172
|
+
time:
|
173
|
+
am: alle
|
174
|
+
formats:
|
175
|
+
default: "%a, %d %b %Y %H:%M:%S %z"
|
176
|
+
long: "%B %d, %Y %H:%M"
|
177
|
+
short: "%d %b %H:%M"
|
178
|
+
pm: pm
|
179
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
nl:
|
2
|
+
ice_cube:
|
3
|
+
pieces_connector: ' / '
|
4
|
+
not: 'niet %{target}'
|
5
|
+
not_on: 'niet op %{target}'
|
6
|
+
date:
|
7
|
+
formats:
|
8
|
+
default: '%-d %B %Y'
|
9
|
+
times:
|
10
|
+
other: '%{count} keer'
|
11
|
+
one: '%{count} keer'
|
12
|
+
until: 'tot %{date}'
|
13
|
+
days_of_week: '%{segments} %{day}'
|
14
|
+
days_of_month:
|
15
|
+
other: '%{segments} dagen van de maand'
|
16
|
+
one: '%{segments} dag van de maand'
|
17
|
+
days_of_year:
|
18
|
+
other: '%{segments} dagen van het jaar'
|
19
|
+
one: '%{segments} dag van het jaar'
|
20
|
+
at_hours_of_the_day:
|
21
|
+
other: op de %{segments} uren van de dag
|
22
|
+
one: op het %{segments} uur
|
23
|
+
on_minutes_of_hour:
|
24
|
+
other: op de %{segments} minuten van het uur
|
25
|
+
one: om de %{segments} minuut van het uur
|
26
|
+
at_seconds_of_minute:
|
27
|
+
other: op de %{segments} seconden
|
28
|
+
one: op de %{segments} seconde
|
29
|
+
on_seconds_of_minute:
|
30
|
+
other: op de %{segments} seconden van de minuut
|
31
|
+
one: op de %{segments} seconde van de minuut
|
32
|
+
each_second:
|
33
|
+
one: Elke seconde
|
34
|
+
other: Elke %{count} seconden
|
35
|
+
each_minute:
|
36
|
+
one: Elke minuut
|
37
|
+
other: Elke %{count} minuten
|
38
|
+
each_hour:
|
39
|
+
one: Elk uur
|
40
|
+
other: Elke %{count} uren
|
41
|
+
each_day:
|
42
|
+
one: Dagelijks
|
43
|
+
other: Elke %{count} dagen
|
44
|
+
each_week:
|
45
|
+
one: Wekelijks
|
46
|
+
other: Elke %{count} weken
|
47
|
+
each_month:
|
48
|
+
one: Maandelijks
|
49
|
+
other: Elke %{count} maanden
|
50
|
+
each_year:
|
51
|
+
one: Jaarlijks
|
52
|
+
other: Elke %{count} jaren
|
53
|
+
'on': op de %{sentence}
|
54
|
+
in: 'in %{target}'
|
55
|
+
integer:
|
56
|
+
negative: '%{ordinal} laatste'
|
57
|
+
literal_ordinals:
|
58
|
+
-1: laatste
|
59
|
+
-2: voorlaatste
|
60
|
+
ordinal: '%{number}%{ordinal}'
|
61
|
+
ordinals:
|
62
|
+
default: e
|
63
|
+
on_weekends: in het weekend
|
64
|
+
on_weekdays: op weekdagen
|
65
|
+
days_on:
|
66
|
+
- zondagen
|
67
|
+
- maandagen
|
68
|
+
- dinsdagen
|
69
|
+
- woensdagen
|
70
|
+
- donderdagen
|
71
|
+
- vrijdagen
|
72
|
+
- zaterdagen
|
73
|
+
on_days: op %{days}
|
74
|
+
array:
|
75
|
+
last_word_connector: ' en '
|
76
|
+
two_words_connector: ' en '
|
77
|
+
words_connector: ', '
|
78
|
+
string:
|
79
|
+
format:
|
80
|
+
day: '%{rest} %{current}'
|
81
|
+
day_of_week: '%{rest} %{current}'
|
82
|
+
day_of_month: '%{rest} %{current}'
|
83
|
+
day_of_year: '%{rest} %{current}'
|
84
|
+
hour_of_day: '%{rest} %{current}'
|
85
|
+
minute_of_hour: '%{rest} %{current}'
|
86
|
+
until: '%{rest} %{current}'
|
87
|
+
count: '%{rest} %{current}'
|
88
|
+
default: '%{rest} %{current}'
|
89
|
+
date:
|
90
|
+
abbr_day_names:
|
91
|
+
- zo
|
92
|
+
- ma
|
93
|
+
- di
|
94
|
+
- wo
|
95
|
+
- do
|
96
|
+
- vr
|
97
|
+
- za
|
98
|
+
abbr_month_names:
|
99
|
+
-
|
100
|
+
- jan
|
101
|
+
- feb
|
102
|
+
- mrt
|
103
|
+
- apr
|
104
|
+
- mei
|
105
|
+
- jun
|
106
|
+
- jul
|
107
|
+
- aug
|
108
|
+
- sep
|
109
|
+
- okt
|
110
|
+
- nov
|
111
|
+
- dec
|
112
|
+
day_names:
|
113
|
+
- zondag
|
114
|
+
- maandag
|
115
|
+
- dinsdag
|
116
|
+
- woensdag
|
117
|
+
- donderdag
|
118
|
+
- vrijdag
|
119
|
+
- zaterdag
|
120
|
+
month_names:
|
121
|
+
-
|
122
|
+
- januari
|
123
|
+
- februari
|
124
|
+
- maart
|
125
|
+
- april
|
126
|
+
- mei
|
127
|
+
- juni
|
128
|
+
- juli
|
129
|
+
- augustus
|
130
|
+
- september
|
131
|
+
- oktober
|
132
|
+
- november
|
133
|
+
- december
|
data/config/locales/sv.yml
CHANGED
data/lib/ice_cube/i18n.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
+
require 'ice_cube/null_i18n'
|
2
|
+
|
1
3
|
module IceCube
|
2
4
|
module I18n
|
3
|
-
def self.t(*args)
|
4
|
-
backend.t(*args)
|
5
|
-
end
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
LOCALES_PATH = File.expand_path(File.join('..', '..', '..', 'config', 'locales'), __FILE__)
|
7
|
+
|
8
|
+
class << self
|
9
|
+
delegate :t, :l, to: :backend
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.backend
|
12
|
-
@backend
|
13
|
+
@backend ||= detect_backend!
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.detect_backend!
|
16
|
-
|
17
|
-
::I18n
|
18
|
-
|
19
|
-
|
20
|
-
require 'ice_cube/null_i18n'
|
21
|
-
@backend = NullI18n
|
17
|
+
::I18n.load_path += Dir[File.join(LOCALES_PATH, '*.yml')]
|
18
|
+
::I18n
|
19
|
+
rescue NameError
|
20
|
+
NullI18n
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module IceCube
|
2
|
+
class InputAlignment
|
3
|
+
|
4
|
+
def initialize(rule, value, rule_part)
|
5
|
+
@rule = rule
|
6
|
+
@value = value
|
7
|
+
@rule_part = rule_part
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :rule, :value, :rule_part
|
11
|
+
|
12
|
+
def verify(freq, options={}, &block)
|
13
|
+
@rule.validations[:interval] or return
|
14
|
+
|
15
|
+
case @rule
|
16
|
+
when DailyRule
|
17
|
+
verify_wday_alignment(freq, &block)
|
18
|
+
when MonthlyRule
|
19
|
+
verify_month_alignment(freq, &block)
|
20
|
+
else
|
21
|
+
verify_freq_alignment(freq, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def interval_validation
|
28
|
+
@interval_validation ||= @rule.validations[:interval].first
|
29
|
+
end
|
30
|
+
|
31
|
+
def interval_value
|
32
|
+
@interval_value ||= (rule_part == :interval) ? value : interval_validation.interval
|
33
|
+
end
|
34
|
+
|
35
|
+
def fixed_validations
|
36
|
+
@fixed_validations ||= @rule.validations.values.flatten.select { |v|
|
37
|
+
interval_type = (v.type == :wday ? :day : v.type)
|
38
|
+
v.class < Validations::FixedValue &&
|
39
|
+
interval_type == rule.base_interval_validation.type
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def verify_freq_alignment(freq)
|
44
|
+
interval_validation.type == freq or return
|
45
|
+
(last_validation = fixed_validations.min_by(&:value)) or return
|
46
|
+
|
47
|
+
alignment = (value - last_validation.value) % interval_validation.interval
|
48
|
+
return if alignment.zero?
|
49
|
+
|
50
|
+
validation_values = fixed_validations.map(&:value).join(', ')
|
51
|
+
if rule_part == :interval
|
52
|
+
message = "interval(#{value}) " \
|
53
|
+
"must be a multiple of " \
|
54
|
+
"intervals in #{last_validation.key}(#{validation_values})"
|
55
|
+
else
|
56
|
+
message = "intervals in #{last_validation.key}(#{validation_values}, #{value}) " \
|
57
|
+
"must be multiples of " \
|
58
|
+
"interval(#{interval_validation.interval})"
|
59
|
+
end
|
60
|
+
|
61
|
+
yield ArgumentError.new(message)
|
62
|
+
end
|
63
|
+
|
64
|
+
def verify_month_alignment(_freq)
|
65
|
+
return if interval_value == 1 || (interval_value % 12).zero?
|
66
|
+
return if fixed_validations.empty?
|
67
|
+
|
68
|
+
message = "month_of_year can only be used with interval(1) or multiples of interval(12)"
|
69
|
+
|
70
|
+
yield ArgumentError.new(message)
|
71
|
+
end
|
72
|
+
|
73
|
+
def verify_wday_alignment(freq)
|
74
|
+
return if interval_value == 1
|
75
|
+
|
76
|
+
if freq == :wday
|
77
|
+
return if (interval_value % 7).zero?
|
78
|
+
return if Array(@rule.validations[:day]).empty?
|
79
|
+
message = "day can only be used with multiples of interval(7)"
|
80
|
+
else
|
81
|
+
(fixed_validation = fixed_validations.first) or return
|
82
|
+
message = "#{fixed_validation.key} can only be used with interval(1)"
|
83
|
+
end
|
84
|
+
|
85
|
+
yield ArgumentError.new(message)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
data/lib/ice_cube/null_i18n.rb
CHANGED
@@ -7,13 +7,19 @@ module IceCube
|
|
7
7
|
|
8
8
|
base = base[options[:count] == 1 ? "one" : "other"] if options[:count]
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
case base
|
11
|
+
when Hash
|
12
|
+
base.each_with_object({}) do |(k, v), hash|
|
13
|
+
hash[k.is_a?(String) ? k.to_sym : k] = v
|
13
14
|
end
|
15
|
+
when Array
|
16
|
+
base.each_with_index.each_with_object({}) do |(v, k), hash|
|
17
|
+
hash[k] = v
|
18
|
+
end
|
19
|
+
else
|
20
|
+
return base unless base.include?('%{')
|
21
|
+
base % options
|
14
22
|
end
|
15
|
-
|
16
|
-
options.reduce(base) { |result, (find, replace)| result.gsub("%{#{find}}", "#{replace}") }
|
17
23
|
end
|
18
24
|
|
19
25
|
def self.l(date_or_time, options = {})
|
@@ -22,7 +28,7 @@ module IceCube
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def self.config
|
25
|
-
@config ||= YAML.
|
31
|
+
@config ||= YAML.load_file(File.join(IceCube::I18n::LOCALES_PATH, 'en.yml'))['en']
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/ice_cube/occurrence.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'forwardable'
|
2
1
|
require 'delegate'
|
3
2
|
|
4
3
|
module IceCube
|
@@ -20,18 +19,16 @@ module IceCube
|
|
20
19
|
# Time.now - Occurrence.new(start_time) # => 3600
|
21
20
|
#
|
22
21
|
class Occurrence < SimpleDelegator
|
22
|
+
include Comparable
|
23
23
|
|
24
24
|
# Report class name as 'Time' to thwart type checking.
|
25
25
|
def self.name
|
26
26
|
'Time'
|
27
27
|
end
|
28
28
|
|
29
|
-
# Optimize for common methods to avoid method_missing
|
30
|
-
extend Forwardable
|
31
|
-
def_delegators :start_time, :to_i, :<=>, :==
|
32
|
-
def_delegators :to_range, :cover?, :include?, :each, :first, :last
|
33
|
-
|
34
29
|
attr_reader :start_time, :end_time
|
30
|
+
alias first start_time
|
31
|
+
alias last end_time
|
35
32
|
|
36
33
|
def initialize(start_time, end_time=nil)
|
37
34
|
@start_time = start_time
|
@@ -39,29 +36,34 @@ module IceCube
|
|
39
36
|
__setobj__ @start_time
|
40
37
|
end
|
41
38
|
|
39
|
+
def to_i
|
40
|
+
@start_time.to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
def <=>(other)
|
44
|
+
@start_time <=> other
|
45
|
+
end
|
46
|
+
|
42
47
|
def is_a?(klass)
|
43
48
|
klass == ::Time || super
|
44
49
|
end
|
45
50
|
alias_method :kind_of?, :is_a?
|
46
51
|
|
47
|
-
def intersects?
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
else
|
62
|
-
cover? other
|
63
|
-
end
|
52
|
+
def intersects?(other)
|
53
|
+
return cover?(other) unless other.is_a?(Occurrence) || other.is_a?(Range)
|
54
|
+
|
55
|
+
this_start = first + 1
|
56
|
+
this_end = last # exclude end boundary
|
57
|
+
other_start = other.first + 1
|
58
|
+
other_end = other.last + 1
|
59
|
+
|
60
|
+
!(this_end < other_start || this_start > other_end)
|
61
|
+
end
|
62
|
+
|
63
|
+
def cover?(other)
|
64
|
+
to_range.cover?(other)
|
64
65
|
end
|
66
|
+
alias_method :include?, :cover?
|
65
67
|
|
66
68
|
def comparable_time
|
67
69
|
start_time
|
@@ -4,15 +4,18 @@ module IceCube
|
|
4
4
|
data = {}
|
5
5
|
ical_string.each_line do |line|
|
6
6
|
(property, value) = line.split(':')
|
7
|
-
(property,
|
7
|
+
(property, _tzid) = property.split(';')
|
8
8
|
case property
|
9
9
|
when 'DTSTART'
|
10
|
-
data[:start_time] =
|
10
|
+
data[:start_time] = TimeUtil.deserialize_time(value)
|
11
11
|
when 'DTEND'
|
12
|
-
data[:end_time] =
|
12
|
+
data[:end_time] = TimeUtil.deserialize_time(value)
|
13
|
+
when 'RDATE'
|
14
|
+
data[:rtimes] ||= []
|
15
|
+
data[:rtimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) }
|
13
16
|
when 'EXDATE'
|
14
17
|
data[:extimes] ||= []
|
15
|
-
data[:extimes] += value.split(',').map{|v|
|
18
|
+
data[:extimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) }
|
16
19
|
when 'DURATION'
|
17
20
|
data[:duration] # FIXME
|
18
21
|
when 'RRULE'
|
@@ -41,7 +44,7 @@ module IceCube
|
|
41
44
|
when 'COUNT'
|
42
45
|
params[:count] = value.to_i
|
43
46
|
when 'UNTIL'
|
44
|
-
params[:until] =
|
47
|
+
params[:until] = TimeUtil.deserialize_time(value).utc
|
45
48
|
when 'WKST'
|
46
49
|
params[:week_start] = TimeUtil.ical_day_to_symbol(value)
|
47
50
|
when 'BYSECOND'
|
data/lib/ice_cube/rule.rb
CHANGED
@@ -19,11 +19,9 @@ module IceCube
|
|
19
19
|
until_time || occurrence_count
|
20
20
|
end
|
21
21
|
|
22
|
-
def ==(
|
23
|
-
|
24
|
-
|
25
|
-
hash && hash == rule.to_hash
|
26
|
-
end
|
22
|
+
def ==(other)
|
23
|
+
return false unless other.is_a? Rule
|
24
|
+
hash == other.hash
|
27
25
|
end
|
28
26
|
|
29
27
|
def hash
|
@@ -31,7 +29,7 @@ module IceCube
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def to_ical
|
34
|
-
raise MethodNotImplemented, "Expected to be
|
32
|
+
raise MethodNotImplemented, "Expected to be overridden by subclasses"
|
35
33
|
end
|
36
34
|
|
37
35
|
# Convert from ical string and create a rule
|
@@ -60,11 +58,6 @@ module IceCube
|
|
60
58
|
next_time(time, schedule, time).to_i == time.to_i
|
61
59
|
end
|
62
60
|
|
63
|
-
# Whether this rule requires a full run
|
64
|
-
def full_required?
|
65
|
-
!@count.nil?
|
66
|
-
end
|
67
|
-
|
68
61
|
class << self
|
69
62
|
|
70
63
|
# Convert from a hash and create a rule
|
@@ -2,6 +2,15 @@ module IceCube
|
|
2
2
|
|
3
3
|
class DailyRule < ValidatedRule
|
4
4
|
|
5
|
+
include Validations::HourOfDay
|
6
|
+
include Validations::MinuteOfHour
|
7
|
+
include Validations::SecondOfMinute
|
8
|
+
include Validations::DayOfMonth
|
9
|
+
include Validations::DayOfWeek
|
10
|
+
include Validations::Day
|
11
|
+
include Validations::MonthOfYear
|
12
|
+
# include Validations::DayOfYear # n/a
|
13
|
+
|
5
14
|
include Validations::DailyInterval
|
6
15
|
|
7
16
|
def initialize(interval = 1)
|
@@ -2,6 +2,15 @@ module IceCube
|
|
2
2
|
|
3
3
|
class HourlyRule < ValidatedRule
|
4
4
|
|
5
|
+
include Validations::HourOfDay
|
6
|
+
include Validations::MinuteOfHour
|
7
|
+
include Validations::SecondOfMinute
|
8
|
+
include Validations::DayOfMonth
|
9
|
+
include Validations::DayOfWeek
|
10
|
+
include Validations::Day
|
11
|
+
include Validations::MonthOfYear
|
12
|
+
include Validations::DayOfYear
|
13
|
+
|
5
14
|
include Validations::HourlyInterval
|
6
15
|
|
7
16
|
def initialize(interval = 1)
|