opening_hours_converter 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opening_hours_converter/constants.rb +7 -7
- data/lib/opening_hours_converter/interval.rb +1 -1
- data/lib/opening_hours_converter/iterator.rb +36 -46
- data/lib/opening_hours_converter/opening_hours_builder.rb +128 -161
- data/lib/opening_hours_converter/opening_hours_date.rb +52 -57
- data/lib/opening_hours_converter/opening_hours_parser.rb +114 -137
- data/lib/opening_hours_converter/opening_hours_rule.rb +69 -85
- data/lib/opening_hours_converter/opening_hours_time.rb +7 -9
- data/lib/opening_hours_converter/public_holiday.rb +19 -19
- data/lib/opening_hours_converter/week.rb +36 -44
- data/lib/opening_hours_converter/wide_interval.rb +145 -160
- metadata +2 -2
@@ -17,23 +17,22 @@ module OpeningHoursConverter
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_weekdays
|
20
|
-
result =
|
21
|
-
|
20
|
+
result = ''
|
21
|
+
weekdays = @weekdays.concat(@weekdays_over).sort.uniq
|
22
22
|
|
23
|
-
if
|
24
|
-
result =
|
25
|
-
|
23
|
+
if !weekdays.empty? && weekdays[0] == -2
|
24
|
+
result = 'PH'
|
25
|
+
weekdays.shift
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
i = wd.length - 2
|
28
|
+
if !weekdays.empty? && weekdays.include?(6) && weekdays.include?(0) && (weekdays.include?(5) || weekdays.include?(1))
|
29
|
+
start_week_end = 6
|
30
|
+
i = weekdays.length - 2
|
32
31
|
stop_looking = false
|
33
32
|
|
34
33
|
while !stop_looking && i >= 0
|
35
|
-
if
|
36
|
-
|
34
|
+
if weekdays[i] == weekdays[i + 1] - 1
|
35
|
+
start_week_end = weekdays[i]
|
37
36
|
i -= 1
|
38
37
|
else
|
39
38
|
stop_looking = true
|
@@ -42,71 +41,67 @@ module OpeningHoursConverter
|
|
42
41
|
|
43
42
|
i = 1
|
44
43
|
stop_looking = false
|
45
|
-
|
44
|
+
end_week_end = 0
|
46
45
|
|
47
|
-
while !stop_looking && i <
|
48
|
-
if
|
49
|
-
|
46
|
+
while !stop_looking && i < weekdays.length
|
47
|
+
if weekdays[i - 1] == weekdays[i] - 1
|
48
|
+
end_week_end = weekdays[i]
|
50
49
|
i += 1
|
51
50
|
else
|
52
51
|
stop_looking = true
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
length = 7 -
|
55
|
+
length = 7 - start_week_end + end_week_end + 1
|
57
56
|
|
58
|
-
if length >= 3 &&
|
59
|
-
if result.
|
60
|
-
|
61
|
-
end
|
62
|
-
result += "#{OSM_DAYS[start_we]}-#{OSM_DAYS[end_we]}"
|
57
|
+
if length >= 3 && start_week_end > end_week_end
|
58
|
+
result += ',' if !result.empty?
|
59
|
+
result += "#{OSM_DAYS[start_week_end]}-#{OSM_DAYS[end_week_end]}"
|
63
60
|
|
64
|
-
j=0
|
65
|
-
while j <
|
66
|
-
if
|
67
|
-
|
61
|
+
j = 0
|
62
|
+
while j < weekdays.length
|
63
|
+
if weekdays[j] <= end_week_end || weekdays[j] >= start_week_end
|
64
|
+
weekdays.slice!(j, 1)
|
68
65
|
else
|
69
|
-
j+=1
|
66
|
+
j += 1
|
70
67
|
end
|
71
68
|
end
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
75
|
-
if
|
76
|
-
result += result.
|
77
|
-
first_in_row =
|
78
|
-
for i in 1...
|
79
|
-
if
|
80
|
-
if first_in_row !=
|
81
|
-
if
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
result += ",#{OSM_DAYS[wd[i]]}"
|
88
|
-
first_in_row = wd[i]
|
89
|
-
elsif i == wd.length - 1
|
90
|
-
if wd[i] - first_in_row == 1
|
91
|
-
result += ",#{OSM_DAYS[wd[i]]}"
|
92
|
-
else
|
93
|
-
result += "-#{OSM_DAYS[wd[i]]}"
|
72
|
+
if weekdays.length > 1 || (weekdays.length == 1 && weekdays[0] != -1)
|
73
|
+
result += !result.empty? ? ",#{OSM_DAYS[weekdays[0]]}" : OSM_DAYS[weekdays[0]]
|
74
|
+
first_in_row = weekdays[0]
|
75
|
+
for i in 1...weekdays.length
|
76
|
+
if weekdays[i - 1] != weekdays[i] - 1
|
77
|
+
if first_in_row != weekdays[i - 1]
|
78
|
+
result += if weekdays[i - 1] - first_in_row == 1
|
79
|
+
",#{OSM_DAYS[weekdays[i - 1]]}"
|
80
|
+
else
|
81
|
+
"-#{OSM_DAYS[weekdays[i - 1]]}"
|
82
|
+
end
|
94
83
|
end
|
84
|
+
result += ",#{OSM_DAYS[weekdays[i]]}"
|
85
|
+
first_in_row = weekdays[i]
|
86
|
+
elsif i == weekdays.length - 1
|
87
|
+
result += if weekdays[i] - first_in_row == 1
|
88
|
+
",#{OSM_DAYS[weekdays[i]]}"
|
89
|
+
else
|
90
|
+
"-#{OSM_DAYS[weekdays[i]]}"
|
91
|
+
end
|
95
92
|
end
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
99
|
-
if result ==
|
100
|
-
|
101
|
-
end
|
102
|
-
return result
|
96
|
+
result = '' if result == 'Mo-Su'
|
97
|
+
result
|
103
98
|
end
|
104
99
|
|
105
100
|
def add_weekday(weekday)
|
106
|
-
if
|
107
|
-
|
108
|
-
|
109
|
-
|
101
|
+
return if @weekdays.include?(weekday) || @weekdays_over.include?(weekday)
|
102
|
+
|
103
|
+
@weekdays << weekday
|
104
|
+
@weekdays.sort!
|
110
105
|
end
|
111
106
|
|
112
107
|
def add_ph_weekday
|
@@ -114,10 +109,10 @@ module OpeningHoursConverter
|
|
114
109
|
end
|
115
110
|
|
116
111
|
def add_overwritten_weekday(weekday)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
112
|
+
return if @weekdays_over.include?(weekday) && @weekdays_over.include?(weekday)
|
113
|
+
|
114
|
+
@weekdays_over << weekday
|
115
|
+
@weekdays_over.sort!
|
121
116
|
end
|
122
117
|
|
123
118
|
def same_kind_as?(date)
|