opening_hours_converter 1.10.0 → 1.11.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
  SHA256:
3
- metadata.gz: 684e901a145245d2884ed3cb350d887385efc2b39cc8402e2251216f3a49ff9d
4
- data.tar.gz: a51144324b7af7a323b25a6634c8f8e5e3edcfcdbeb12ca1ad2b50ac3d830488
3
+ metadata.gz: 8d9c36ae7cf29f7c3cc90f3fa56a1b24f3294b9201356bb3c7cecf5319857343
4
+ data.tar.gz: 34079e2a3f1dbb735d5e07f9aab3a62d726cf0f7f88de29e86235a73462c5a4a
5
5
  SHA512:
6
- metadata.gz: ef452a46a37394b827a8e8c36e7ecfb1b2d40cc3d8da4461730a933c81aea679ed4ddc40d486563c7fa37834899d4d385786b9792ac850f3c14c369bbdcc5e68
7
- data.tar.gz: d3db0f40cee5804148039f76a662de2ff4696f7986365f9875007899a6f2ff733d845e1682f0c890c74cb0a9c6618e3776825036695cdcb32ea55d0862d2ed55
6
+ metadata.gz: 68a659bdff345013b1c2e00df196725024792536e87b92b586c46e286f2bb8baab856d2c91564feb22c6d0969f26a1a5f781adf42e7d8f78659e3b1ef008e6e0
7
+ data.tar.gz: 8f977df19ce9fe13547f5215320b1a699ee1bf40a6b2e804865b9b9aba15e8dbe74eb5ac3c0f608f76010b6768b381c0f09fa537247be8fd31c78a611eb9a10a
@@ -172,23 +172,30 @@ module OpeningHoursConverter
172
172
  else
173
173
  result.each do |selector, intervals|
174
174
  if selector == 'always'
175
- intervals.each do |interval|
175
+ if end_before_start?(intervals)
176
+ end_interval = intervals.select { |interval| interval[:start][:day] == 0 && interval[:start][:month] == 0 }.first
177
+ start_interval = intervals.select { |interval| interval[:end][:day] == 30 && interval[:end][:month] == 11 }.first
176
178
  str_result += ',' if !str_result.empty?
177
- if is_full_year?(interval)
178
- elsif starts_year?(interval) && ends_year?(interval)
179
- str_result += "#{interval[:start][:year]}-#{interval[:end][:year]}"
180
- elsif is_full_month?(interval)
181
- str_result += (OSM_MONTHS[interval[:start][:month]]).to_s
182
- elsif is_same_month?(interval)
183
- if is_same_day?(interval)
184
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}"
179
+ str_result += "#{OSM_MONTHS[start_interval[:start][:month]]} #{start_interval[:start][:day] + 1 < 10 ? "0#{start_interval[:start][:day] + 1}" : start_interval[:start][:day] + 1}-#{OSM_MONTHS[end_interval[:end][:month]]} #{end_interval[:end][:day] + 1 < 10 ? "0#{end_interval[:end][:day] + 1}" : end_interval[:end][:day] + 1}"
180
+ else
181
+ intervals.each do |interval|
182
+ str_result += ',' if !str_result.empty?
183
+ if is_full_year?(interval)
184
+ elsif starts_year?(interval) && ends_year?(interval)
185
+ str_result += "#{interval[:start][:year]}-#{interval[:end][:year]}"
186
+ elsif is_full_month?(interval)
187
+ str_result += (OSM_MONTHS[interval[:start][:month]]).to_s
188
+ elsif is_same_month?(interval)
189
+ if is_same_day?(interval)
190
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}"
191
+ else
192
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
193
+ end
194
+ elsif starts_month?(interval) && ends_month?(interval)
195
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]}-#{OSM_MONTHS[interval[:end][:month]]}"
185
196
  else
186
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
197
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{OSM_MONTHS[interval[:end][:month]]} #{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
187
198
  end
188
- elsif starts_month?(interval) && ends_month?(interval)
189
- str_result += "#{OSM_MONTHS[interval[:start][:month]]}-#{OSM_MONTHS[interval[:end][:month]]}"
190
- else
191
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{OSM_MONTHS[interval[:end][:month]]} #{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
192
199
  end
193
200
  end
194
201
  elsif selector == 'multi_year'
@@ -225,7 +232,15 @@ module OpeningHoursConverter
225
232
  str_result.strip
226
233
  end
227
234
 
235
+ def end_before_start?(intervals)
236
+ intervals.length == 2 &&
237
+ intervals.one? { |interval| interval[:start][:day] == 0 && interval[:start][:month] == 0 } &&
238
+ intervals.one? { |interval| interval[:end][:day] == 30 && interval[:end][:month] == 11 }
239
+ end
240
+
228
241
  def is_only_week_interval?(r)
242
+ return false if r == {}
243
+
229
244
  r.all? do |year, intervals|
230
245
  intervals.all? do |interval|
231
246
  is_week_interval?(interval)
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.10.0
4
+ version: 1.11.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: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2019-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json