ice_cube 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d075ab984a12f078d212922e5119adb3280095f9
4
- data.tar.gz: afed7767f9d95f17308f6dd3a40fcfc025c46d44
3
+ metadata.gz: 51dd94d70b0d51847c678abf736d395ddbee5e2e
4
+ data.tar.gz: 2b69372e7e4e67487347cab5a8a773da40a87e91
5
5
  SHA512:
6
- metadata.gz: 2a24dc8dc9b8a745a6753bc60d9551366af050e3ce7d80d32b4d7c6b97006c0a9c65338a75fb4b184141bb38467dbb0e73eca98e35f2407f29d79df5bd069a3a
7
- data.tar.gz: c309f41dd53711998b439544e5b9b386617d2a2b63b1792688cff76346b56765a11012b4d15e3cede673f8ed658a9997ac0e430c4af34bb7c8fa7aed35f3bc57
6
+ metadata.gz: d20e08c68105003f8a6c3f192c679d185c07e43681543844f890d00947d94d6c42d5e82a350e83cab506c74183bbd42eef2cb8d5deeab8f7979a819884221dff
7
+ data.tar.gz: f1ab8c1b534dd70e185da9b272a973202cb071f29bd90cb2a31fa7d83d1b3f0e61c321d3d402e79e0059cf698374a0465dc954218de77afe0ac459cc0f990f47
@@ -6,28 +6,6 @@ en:
6
6
  date:
7
7
  formats:
8
8
  default: '%B %-d, %Y'
9
- month_names:
10
- -
11
- - January
12
- - February
13
- - March
14
- - April
15
- - May
16
- - June
17
- - July
18
- - August
19
- - September
20
- - October
21
- - November
22
- - December
23
- day_names:
24
- - Sunday
25
- - Monday
26
- - Tuesday
27
- - Wednesday
28
- - Thursday
29
- - Friday
30
- - Saturday
31
9
  times:
32
10
  other: '%{count} times'
33
11
  one: '%{count} time'
@@ -91,13 +69,13 @@ en:
91
69
  on_weekends: on Weekends
92
70
  on_weekdays: on Weekdays
93
71
  days_on:
94
- - Sundays
95
- - Mondays
96
- - Tuesdays
97
- - Wednesdays
98
- - Thursdays
99
- - Fridays
100
- - Saturdays
72
+ - Sundays
73
+ - Mondays
74
+ - Tuesdays
75
+ - Wednesdays
76
+ - Thursdays
77
+ - Fridays
78
+ - Saturdays
101
79
  on_days: on %{days}
102
80
  array:
103
81
  last_word_connector: ', and '
@@ -114,7 +92,6 @@ en:
114
92
  until: '%{rest} %{current}'
115
93
  count: '%{rest} %{current}'
116
94
  default: '%{rest} %{current}'
117
-
118
95
  date:
119
96
  abbr_day_names:
120
97
  - Sun
@@ -146,10 +123,6 @@ en:
146
123
  - Thursday
147
124
  - Friday
148
125
  - Saturday
149
- formats:
150
- default: "%Y-%m-%d"
151
- long: "%B %d, %Y"
152
- short: "%b %d"
153
126
  month_names:
154
127
  -
155
128
  - January
@@ -164,15 +137,3 @@ en:
164
137
  - October
165
138
  - November
166
139
  - December
167
- order:
168
- - :year
169
- - :month
170
- - :day
171
-
172
- time:
173
- am: am
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
@@ -6,28 +6,6 @@ es:
6
6
  date:
7
7
  formats:
8
8
  default: '%-d de %B de %Y'
9
- month_names:
10
- -
11
- - Enero
12
- - Febrero
13
- - Marzo
14
- - Abril
15
- - Mayo
16
- - Junio
17
- - Julio
18
- - Agosto
19
- - Septiembre
20
- - Octubre
21
- - Noviembre
22
- - Diciembre
23
- day_names:
24
- - Domingo
25
- - Lunes
26
- - Martes
27
- - Miércoles
28
- - Jueves
29
- - Viernes
30
- - Sábado
31
9
  times:
32
10
  other: '%{count} veces'
33
11
  one: '%{count} vez'
@@ -92,13 +70,13 @@ es:
92
70
  on_weekends: en fin de semana
93
71
  on_weekdays: en días laborables
94
72
  days_on:
95
- - los domingos
96
- - los lunes
97
- - los martes
98
- - los miércoles
99
- - los jueves
100
- - los viernes
101
- - los sábados
73
+ - los domingos
74
+ - los lunes
75
+ - los martes
76
+ - los miércoles
77
+ - los jueves
78
+ - los viernes
79
+ - los sábados
102
80
  on_days: '%{days}'
103
81
  array:
104
82
  last_word_connector: ' y '
@@ -115,62 +93,48 @@ es:
115
93
  until: '%{rest} %{current}'
116
94
  count: '%{rest} %{current}'
117
95
  default: '%{rest} %{current}'
118
-
119
96
  date:
120
97
  day_names:
121
- - Domingo
122
- - Lunes
123
- - Martes
124
- - Miércoles
125
- - Jueves
126
- - Viernes
127
- - Sábado
98
+ - Domingo
99
+ - Lunes
100
+ - Martes
101
+ - Miércoles
102
+ - Jueves
103
+ - Viernes
104
+ - Sábado
128
105
  abbr_day_names:
129
- - Dom
130
- - Lun
131
- - Mar
132
- - Mie
133
- - Jue
134
- - Vie
135
- - Sab
136
- # Don't forget the nil at the beginning; there's no such thing as a 0th month
106
+ - Dom
107
+ - Lun
108
+ - Mar
109
+ - Mie
110
+ - Jue
111
+ - Vie
112
+ - Sab
137
113
  month_names:
138
- -
139
- - Enero
140
- - Febrero
141
- - Marzo
142
- - Abril
143
- - Mayo
144
- - Junio
145
- - Julio
146
- - Agosto
147
- - Septiembre
148
- - Octubre
149
- - Noviembre
150
- - Diciembre
114
+ -
115
+ - Enero
116
+ - Febrero
117
+ - Marzo
118
+ - Abril
119
+ - Mayo
120
+ - Junio
121
+ - Julio
122
+ - Agosto
123
+ - Septiembre
124
+ - Octubre
125
+ - Noviembre
126
+ - Diciembre
151
127
  abbr_month_names:
152
- -
153
- - Ene
154
- - Feb
155
- - Mar
156
- - Abr
157
- - May
158
- - Jun
159
- - Jul
160
- - Ago
161
- - Sep
162
- - Oct
163
- - Nov
164
- - Dic
165
- formats:
166
- default: '%d/%m/%Y'
167
- long: '%d de %B de %Y'
168
- short: '%d de %B'
169
-
170
- time:
171
- formats:
172
- default: "%A, %d de %B de %Y %H:%M:%S %z"
173
- short: "%d de %b %H:%M"
174
- long: "%d de %B de %Y a las %H:%M"
175
- am: "am"
176
- pm: "pm"
128
+ -
129
+ - Ene
130
+ - Feb
131
+ - Mar
132
+ - Abr
133
+ - May
134
+ - Jun
135
+ - Jul
136
+ - Ago
137
+ - Sep
138
+ - Oct
139
+ - Nov
140
+ - Dic
@@ -6,28 +6,6 @@ ja:
6
6
  date:
7
7
  formats:
8
8
  default: '%Y年%m月%d日'
9
- month_names:
10
- -
11
- - 1月
12
- - 2月
13
- - 3月
14
- - 4月
15
- - 5月
16
- - 6月
17
- - 7月
18
- - 8月
19
- - 9月
20
- - 10月
21
- - 11月
22
- - 12月
23
- day_names:
24
- - 日曜
25
- - 月曜
26
- - 火曜
27
- - 水曜
28
- - 木曜
29
- - 金曜
30
- - 土曜
31
9
  times:
32
10
  other: '%{count}回'
33
11
  one: '%{count}回'
@@ -82,13 +60,13 @@ ja:
82
60
  on_weekends: 週末
83
61
  on_weekdays: 平日
84
62
  days_on:
85
- - 日曜
86
- - 月曜
87
- - 火曜
88
- - 水曜
89
- - 木曜
90
- - 金曜
91
- - 土曜
63
+ - 日曜
64
+ - 月曜
65
+ - 火曜
66
+ - 水曜
67
+ - 木曜
68
+ - 金曜
69
+ - 土曜
92
70
  on_days: '%{days}'
93
71
  array:
94
72
  last_word_connector: '、'
@@ -105,3 +83,48 @@ ja:
105
83
  until: '%{current}%{rest}'
106
84
  count: '%{rest}%{current}'
107
85
  default: '%{rest}%{current}'
86
+ date:
87
+ abbr_day_names:
88
+ - 日
89
+ - 月
90
+ - 火
91
+ - 水
92
+ - 木
93
+ - 金
94
+ - 土
95
+ abbr_month_names:
96
+ -
97
+ - 1月
98
+ - 2月
99
+ - 3月
100
+ - 4月
101
+ - 5月
102
+ - 6月
103
+ - 7月
104
+ - 8月
105
+ - 9月
106
+ - 10月
107
+ - 11月
108
+ - 12月
109
+ day_names:
110
+ - 日曜
111
+ - 月曜
112
+ - 火曜
113
+ - 水曜
114
+ - 木曜
115
+ - 金曜
116
+ - 土曜
117
+ month_names:
118
+ -
119
+ - 1月
120
+ - 2月
121
+ - 3月
122
+ - 4月
123
+ - 5月
124
+ - 6月
125
+ - 7月
126
+ - 8月
127
+ - 9月
128
+ - 10月
129
+ - 11月
130
+ - 12月
@@ -41,9 +41,9 @@ module IceCube
41
41
  wday_validations = other_interval_validations.select { |v| v.type == :wday }
42
42
  return 0 if wday_validations.none?
43
43
 
44
- days = (step_time - start_time).to_i / ONE_DAY
44
+ days = step_time.to_date - start_time.to_date
45
45
  interval = base_interval_validation.validate(step_time, start_time).to_i
46
- min_wday = TimeUtil.normalize_wday(wday_validations.min_by(&:day).day, week_start)
46
+ min_wday = wday_validations.map { |v| TimeUtil.normalize_wday(v.day, week_start) }.min
47
47
  step_wday = TimeUtil.normalize_wday(step_time.wday, week_start)
48
48
 
49
49
  days + interval - step_wday + min_wday
@@ -420,7 +420,7 @@ module IceCube
420
420
  # Find all of the occurrences for the schedule between opening_time
421
421
  # and closing_time
422
422
  # Iteration is unrolled in pairs to skip duplicate times in end of DST
423
- def enumerate_occurrences(opening_time, closing_time = nil, options = {}, &block)
423
+ def enumerate_occurrences(opening_time, closing_time = nil, options = {})
424
424
  opening_time = TimeUtil.match_zone(opening_time, start_time)
425
425
  closing_time = TimeUtil.match_zone(closing_time, start_time)
426
426
  opening_time += start_time.subsec - opening_time.subsec rescue 0
@@ -428,23 +428,16 @@ module IceCube
428
428
  spans = options[:spans] == true && duration != 0
429
429
  Enumerator.new do |yielder|
430
430
  reset
431
- t1 = full_required? ? start_time : opening_time - (spans ? duration : 0)
431
+ t1 = full_required? ? start_time : opening_time
432
+ t1 -= duration if spans
433
+ t1 = start_time if t1 < start_time
432
434
  loop do
433
435
  break unless (t0 = next_time(t1, closing_time))
434
436
  break if closing_time && t0 > closing_time
435
437
  if (spans ? (t0.end_time > opening_time) : (t0 >= opening_time))
436
- yielder << (block_given? ? block.call(t0) : t0)
438
+ yielder << (block_given? ? yield(t0) : t0)
437
439
  end
438
- break unless (t1 = next_time(t0 + 1, closing_time))
439
- break if closing_time && t1 > closing_time
440
- if TimeUtil.same_clock?(t0, t1) && recurrence_rules.any?(&:dst_adjust?)
441
- wind_back_dst
442
- next (t1 += 1)
443
- end
444
- if (spans ? (t1.end_time > opening_time) : (t1 >= opening_time))
445
- yielder << (block_given? ? block.call(t1) : t1)
446
- end
447
- next (t1 += 1)
440
+ t1 = t0 + 1
448
441
  end
449
442
  end
450
443
  end
@@ -460,7 +453,7 @@ module IceCube
460
453
  min_time
461
454
  end
462
455
  end
463
- break nil unless min_time
456
+ break unless min_time
464
457
  next (time = min_time + 1) if exception_time?(min_time)
465
458
  break Occurrence.new(min_time, min_time + duration)
466
459
  end
@@ -511,12 +504,6 @@ module IceCube
511
504
  end
512
505
  end
513
506
 
514
- def wind_back_dst
515
- recurrence_rules.each do |rule|
516
- rule.skipped_for_dst
517
- end
518
- end
519
-
520
507
  end
521
508
 
522
509
  end
@@ -47,7 +47,7 @@ module IceCube
47
47
  time.in_time_zone(reference.time_zone)
48
48
  else
49
49
  if reference.utc?
50
- time.utc
50
+ time.getgm
51
51
  elsif reference.zone
52
52
  time.getlocal
53
53
  else
@@ -89,18 +89,27 @@ module IceCube
89
89
 
90
90
  # Serialize a time appropriate for storing
91
91
  def self.serialize_time(time)
92
- if time.respond_to?(:time_zone)
93
- {:time => time.utc, :zone => time.time_zone.name}
94
- elsif time.is_a?(Time)
95
- time
92
+ case time
93
+ when Time, Date
94
+ if time.respond_to?(:time_zone)
95
+ {:time => time.utc, :zone => time.time_zone.name}
96
+ else
97
+ time
98
+ end
99
+ when DateTime
100
+ Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
101
+ else
102
+ raise ArgumentError, "cannot serialize #{time.inspect}, expected a Time"
96
103
  end
97
104
  end
98
105
 
99
106
  # Deserialize a time serialized with serialize_time or in ISO8601 string format
100
107
  def self.deserialize_time(time_or_hash)
101
108
  case time_or_hash
102
- when Time
109
+ when Time, Date
103
110
  time_or_hash
111
+ when DateTime
112
+ Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
104
113
  when Hash
105
114
  hash = FlexibleHash.new(time_or_hash)
106
115
  hash[:time].in_time_zone(hash[:zone])
@@ -260,27 +269,32 @@ module IceCube
260
269
 
261
270
  def initialize(time, dst_adjust = true)
262
271
  @dst_adjust = dst_adjust
263
- @time = time
272
+ @base = time
273
+ if dst_adjust
274
+ @time = Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec + time.subsec)
275
+ else
276
+ @time = time
277
+ end
264
278
  end
265
279
 
266
- # Get the wrapper time back
280
+ # Get the wrapped time back in its original zone & format
267
281
  def to_time
268
- @time
282
+ return @time unless @dst_adjust
283
+ parts = @time.year, @time.month, @time.day, @time.hour, @time.min, @time.sec + @time.subsec
284
+ TimeUtil.build_in_zone(parts, @base)
269
285
  end
270
286
 
271
287
  # DST-safely add an interval of time to the wrapped time
272
288
  def add(type, val)
273
289
  type = :day if type == :wday
274
- adjust do
275
- @time += case type
276
- when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
277
- when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
278
- when :day then val * ONE_DAY
279
- when :hour then val * ONE_HOUR
280
- when :min then val * ONE_MINUTE
281
- when :sec then val
282
- end
283
- end
290
+ @time += case type
291
+ when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
292
+ when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
293
+ when :day then val * ONE_DAY
294
+ when :hour then val * ONE_HOUR
295
+ when :min then val * ONE_MINUTE
296
+ when :sec then val
297
+ end
284
298
  end
285
299
 
286
300
  # Clear everything below a certain type
@@ -289,25 +303,12 @@ module IceCube
289
303
  type = :day if type == :wday
290
304
  CLEAR_ORDER.each do |ptype|
291
305
  break if ptype == type
292
- adjust do
293
- send(:"clear_#{ptype}")
294
- end
306
+ send :"clear_#{ptype}"
295
307
  end
296
308
  end
297
309
 
298
310
  private
299
311
 
300
- def adjust(&block)
301
- if @dst_adjust
302
- off = @time.utc_offset
303
- yield
304
- diff = off - @time.utc_offset
305
- @time += diff if diff != 0
306
- else
307
- yield
308
- end
309
- end
310
-
311
312
  def clear_sec
312
313
  @time.sec > 0 ? @time -= @time.sec : @time
313
314
  end
@@ -79,12 +79,12 @@ module IceCube
79
79
  end
80
80
 
81
81
  def dst_adjust?
82
- @validations[:interval].any? &:dst_adjust?
82
+ @validations[:interval].any?(&:dst_adjust?)
83
83
  end
84
84
 
85
85
  def to_s
86
86
  builder = StringBuilder.new
87
- @validations.each do |name, validations|
87
+ @validations.each_value do |validations|
88
88
  validations.each do |validation|
89
89
  validation.build_s(builder)
90
90
  end
@@ -94,7 +94,7 @@ module IceCube
94
94
 
95
95
  def to_hash
96
96
  builder = HashBuilder.new(self)
97
- @validations.each do |name, validations|
97
+ @validations.each_value do |validations|
98
98
  validations.each do |validation|
99
99
  validation.build_hash(builder)
100
100
  end
@@ -104,7 +104,7 @@ module IceCube
104
104
 
105
105
  def to_ical
106
106
  builder = IcalBuilder.new
107
- @validations.each do |name, validations|
107
+ @validations.each_value do |validations|
108
108
  validations.each do |validation|
109
109
  validation.build_ical(builder)
110
110
  end
@@ -48,7 +48,7 @@ module IceCube
48
48
  builder.piece(:day_of_week) << IceCube::I18n.t(
49
49
  'ice_cube.days_of_week',
50
50
  segments: StringBuilder.nice_number(occ),
51
- day: IceCube::I18n.t('ice_cube.date.day_names')[day]
51
+ day: IceCube::I18n.t('date.day_names')[day]
52
52
  )
53
53
  end
54
54
 
@@ -32,7 +32,7 @@ module IceCube
32
32
  end
33
33
 
34
34
  def build_s(builder)
35
- builder.piece(:month_of_year) << IceCube::I18n.t("ice_cube.date.month_names")[month]
35
+ builder.piece(:month_of_year) << IceCube::I18n.t("date.month_names")[month]
36
36
  end
37
37
 
38
38
  def build_hash(builder)
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.16.1'
3
+ VERSION = '0.16.2'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Crepezzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project: ice-cube
124
- rubygems_version: 2.5.2
124
+ rubygems_version: 2.6.11
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Ruby Date Recurrence Library