opening_hours_converter 1.4.17 → 1.5.0

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: 669c41a41232c2ec313fc364e29d48fa5eb12dc7
4
- data.tar.gz: 1152ac197152568691c9d49cc1090e19d71b0537
3
+ metadata.gz: ac95f6b36e6b0c6062f5ef420f45dd8ad6ff34de
4
+ data.tar.gz: b059dce0398318ca355cdc9a183f10cc65255ed7
5
5
  SHA512:
6
- metadata.gz: 296912ab3c446e5203b8dd6c3698e654dbc310dc4046c81607e99b4fe84dc2e6316f445a1e8f35ad2eed5569fa989fd8eb40ee191e6a0aa2ede2bbe6ea7e12b5
7
- data.tar.gz: 0b23783a4444834f48d4ddc0292def520ba2f9254186a6bda0def62b91c330cd2b964bc4f974c3fbbfc149e40bb68dc85fef927ea51762893c645122eb1d98f5
6
+ metadata.gz: c10976b2002f9a3fe7a20db89bec0c4cb992538dede16feb2cbd56f43634a1339d8fc116cb859dca0e8a615d084fd211c5f6c773b4cc6fa6605edb34e0dbaf6e
7
+ data.tar.gz: fdacc54c5108c114a086b4c0f69887920ddbcd745d1b8f3c3431953556bc41cf91a53c93bcc7a5b760e3e4cd10af0e9e4d76e8a2371e1562710713fa4b59f279
@@ -108,13 +108,9 @@ module OpeningHoursConverter
108
108
  result = ""
109
109
 
110
110
  if rules.length == 0
111
-
112
111
  date_ranges.each do |dr|
113
- if dr.wide_interval.type != "always"
114
- result += "#{dr.wide_interval.get_time_selector} off"
115
- end
112
+ result += "#{dr.wide_interval.get_time_selector} off"
116
113
  end
117
-
118
114
  else
119
115
  rules.each_with_index do |rule, rule_index|
120
116
  if rule_index > 0
@@ -124,7 +120,7 @@ module OpeningHoursConverter
124
120
  end
125
121
  end
126
122
 
127
- return result
123
+ return result.strip
128
124
  end
129
125
 
130
126
  def build_holiday(date_range)
@@ -161,16 +157,10 @@ module OpeningHoursConverter
161
157
 
162
158
  def build_week(date_range)
163
159
  result = []
164
- intervals = date_range.typical.get_intervals(true)
165
160
 
166
- time_intervals = create_time_intervals(date_range.wide_interval, date_range.wide_interval.type, intervals)
167
-
168
- monday0 = time_intervals[0]
169
- sunday24 = time_intervals[1]
170
- days = time_intervals[2]
171
-
172
- days = night_monday_sunday(days, monday0, sunday24)
161
+ intervals = date_range.typical.get_intervals(true)
173
162
 
163
+ days = create_time_intervals(date_range.wide_interval, date_range.wide_interval.type, intervals)
174
164
 
175
165
  days_status = Array.new(OSM_DAYS.length, 0)
176
166
 
@@ -224,21 +214,18 @@ module OpeningHoursConverter
224
214
  def build_week_diff(date_range, general_date_range)
225
215
  intervals = date_range.typical.get_intervals_diff(general_date_range.typical)
226
216
 
227
- time_intervals = create_time_intervals(
217
+ time_intervals =
218
+ days = create_time_intervals(
228
219
  date_range.wide_interval,
229
220
  date_range.wide_interval.type,
230
221
  intervals[:open])
231
- monday0 = time_intervals[0]
232
- sunday24 = time_intervals[1]
233
- days = time_intervals[2]
222
+
234
223
  intervals[:closed].each do |interval|
235
224
  for i in interval.day_start..interval.day_end do
236
225
  days[i].add_time(OpeningHoursConverter::OpeningHoursTime.new)
237
226
  end
238
227
  end
239
228
 
240
- days = night_monday_sunday(days, monday0, sunday24)
241
-
242
229
  days_status = Array.new(OSM_DAYS.length, 0)
243
230
  result = []
244
231
 
@@ -329,9 +316,6 @@ module OpeningHoursConverter
329
316
  end
330
317
 
331
318
  def create_time_intervals(wide_interval, type, intervals)
332
- monday0 = -1
333
- sunday24 = -1
334
-
335
319
  days = []
336
320
  for i in 0...7
337
321
  days << OpeningHoursConverter::OpeningHoursRule.new
@@ -340,22 +324,12 @@ module OpeningHoursConverter
340
324
 
341
325
  intervals.each do |interval|
342
326
  if !interval.nil?
343
- if interval.day_start == DAYS_MAX && interval.day_end == DAYS_MAX && interval.end == MINUTES_MAX
344
- sunday24 = interval.start
345
- end
346
- if interval.day_start == 0 && interval.day_end == 0 && interval.start == 0
347
- monday0 = interval.end
348
- end
349
327
  begin
350
328
  if interval.day_start == interval.day_end
351
329
  days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, interval.end))
352
330
  elsif interval.day_end - interval.day_start == 1
353
- if interval.start > interval.end
354
- days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, interval.end))
355
- else
356
- days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
357
- days[interval.day_end].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
358
- end
331
+ days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
332
+ days[interval.day_end].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
359
333
  else
360
334
  for j in interval.day_start..interval.day_end
361
335
  if j == interval.day_start
@@ -373,17 +347,6 @@ module OpeningHoursConverter
373
347
  end
374
348
  end
375
349
 
376
- return [ monday0, sunday24, days ]
377
- end
378
-
379
- def night_monday_sunday(days, monday0, sunday24)
380
- if monday0 >= 0 && sunday24 >= 0 && monday0 < sunday24
381
- days[0].time.sort! { |a, b| a.start <=> b.start }
382
- days[6].time.sort! { |a, b| a.start <=> b.start }
383
-
384
- days[6].time[days[6].time.length - 1] = OpeningHoursConverter::OpeningHoursTime.new(sunday24, monday0)
385
- days[0].time.shift
386
- end
387
350
  return days
388
351
  end
389
352
  end
@@ -178,6 +178,7 @@ module OpeningHoursConverter
178
178
  date_ranges << OpeningHoursConverter::WideInterval.new.always
179
179
  end
180
180
 
181
+
181
182
  if weekdays.length > 0 && holidays.length > 0
182
183
  weekdays << {from: -2, to: -2}
183
184
  holidays = []
@@ -536,7 +537,7 @@ module OpeningHoursConverter
536
537
  if wd < 6
537
538
  typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, times[:to]))
538
539
  else
539
- typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, 24*60))
540
+ typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd, 24*60))
540
541
  typical.add_interval(OpeningHoursConverter::Interval.new(0, 0, 0, times[:to]))
541
542
  end
542
543
  end
@@ -53,21 +53,52 @@ module OpeningHoursConverter
53
53
  case @type
54
54
  when "day"
55
55
  if !@end.nil?
56
- result = "toutes les semaines du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]}"
57
- if @start[:month] != @end[:month]
58
- result += " au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]}"
56
+ if @start[:year] && !@end[:year] || @start[:year] && @start[:year] == @end[:year]
57
+ result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]} #{@start[:year]}"
58
+ elsif @start[:year] && @end[:year] && @start[:year] != @end[:year]
59
+ result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]} #{@end[:year]}"
60
+ elsif @start[:month] != @end[:month]
61
+ result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]}"
62
+ else
63
+ result = "le #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]}"
59
64
  end
60
65
  else
61
- result = "le #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]}"
66
+ result = "le #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year] ? @start[:year] : ""}"
62
67
  end
63
68
  when "month"
64
69
  if !@end.nil?
65
- result = "toutes les semaines de #{IRL_MONTHS[@start[:month] - 1]} à #{IRL_MONTHS[@endd[:month] - 1]}"
70
+ if @start[:year] && !@end[:year] || @start[:year] && @start[:year] == @end[:year]
71
+ result = "de #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} à #{IRL_MONTHS[@end[:month] - 1]} #{@start[:year]}"
72
+ elsif @start[:year] && @end[:year] && @start[:year] != @end[:year]
73
+ result = "de #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} à #{IRL_MONTHS[@end[:month] - 1]} #{@end[:year]}"
74
+ else
75
+ result = "de #{IRL_MONTHS[@start[:month] - 1]} à #{IRL_MONTHS[@end[:month] - 1]}"
76
+ end
77
+ else
78
+ result = "#{IRL_MONTHS[@start[:month] - 1]}#{@start[:year] ? " #{@start[:year]}" : ""}"
79
+ end
80
+ when "year"
81
+ if !@end.nil?
82
+ result = "de #{@start[:year]} à #{@end[:year]}"
66
83
  else
67
- result = "toutes les semaines de #{IRL_MONTHS[@start[:month] - 1]}"
84
+ result = "#{@start[:year]}"
85
+ end
86
+ when "holiday"
87
+ if !@end.nil?
88
+ if !@start[:year]
89
+ result = "jours fériés"
90
+ else
91
+ result = "les jours fériés de #{@start[:year]} à #{@end[:year]}"
92
+ end
93
+ else
94
+ if !@start[:year]
95
+ result = "jours fériés"
96
+ else
97
+ result = "les jours fériés de #{@start[:year]}"
98
+ end
68
99
  end
69
100
  when "always"
70
- result = "toutes les semaines"
101
+ result = "tout le temps"
71
102
  end
72
103
  return result
73
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opening_hours_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.17
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziserman Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json