cotcube-helpers 0.1.5.1 → 0.1.5.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/range_ext.rb +47 -48
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97c255de9c0dac3cad83de38b0b8e1eb21af6d27bdf751d58dcc013b9044a7bc
|
4
|
+
data.tar.gz: 01cb8859f054baf5c87d55d7b718d8261b48428a59e0e728acbb759855526804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6358bd447301dd4a001b3e4f3ab6e80cd8d2e3073eef1ef9f05fa5c907bf7fd3a19245bd4ea4667bfaebade359e1dc6ea5b24a8f24cf2a8f43bfbb070b6e2567
|
7
|
+
data.tar.gz: a8876e8e07211f0648b2e646b721e52912bcf117f5b6d811f744368a86ab5c030a2f7ad6542464486fd6502ce9f7c8c51ff9cc5e04e401f45c9289a69e8eb1f5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.1.5.4 (January 02, 2021)
|
2
|
+
|
3
|
+
|
4
|
+
## 1.5.1.3 (January 02, 2021)
|
5
|
+
- hotfixing the hotfix (hello CI tools, c ya coming)
|
6
|
+
|
7
|
+
## 1.5.1.2 (January 02, 2021)
|
8
|
+
- hotfix problem in Range.to_time_intervals
|
9
|
+
|
1
10
|
## 0.1.5.1 (January 02, 2021)
|
2
11
|
- Hotfixing parallelize
|
3
12
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.5.
|
1
|
+
0.1.5.4
|
@@ -7,6 +7,7 @@ class Range
|
|
7
7
|
raise ArgumentError,
|
8
8
|
":step must be a 'ActiveSupport::Duration', like '15.minutes', but '#{step}' is a '#{step.class}'"
|
9
9
|
end
|
10
|
+
raise ArgumentError, "Sorry, currently supporting only 15.minutes, 1.hour, 1.day as :step" unless [15.minutes, 60.minutes, 1.hour, 1.day].include? step
|
10
11
|
|
11
12
|
valid_classes = [ActiveSupport::TimeWithZone, Time, Date, DateTime]
|
12
13
|
unless timezone.is_a? ActiveSupport::TimeZone
|
@@ -26,63 +27,61 @@ class Range
|
|
26
27
|
":self.end seems not to be proper time value: #{ending} is a #{ending.class}"
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
# here sub-day and super-day need to be distinguished, as they react differently to daylight time
|
31
|
+
# for super-day, just return an array containing all calendar days
|
32
|
+
if step.to_i >= 1.day
|
33
|
+
return (starting.to_date..ending.to_date).to_a.map{|x| x.to_datetime}
|
34
|
+
else
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
return result.select do |x|
|
41
|
-
(not ranges.nil?) && ranges.empty? ? true : (not [6, 0].include?(x.wday))
|
42
|
-
end
|
43
|
-
end
|
36
|
+
##### The following is the actual big magic line, as it creates the raw target array:
|
37
|
+
#
|
38
|
+
result = (starting.to_time.to_i..ending.to_time.to_i).step(step).to_a.map { |x| timezone.at(x) }
|
39
|
+
#
|
40
|
+
# ###################<3##
|
44
41
|
|
45
|
-
# sub-day is checked for DST and filtered along provided ranges
|
46
|
-
# noinspection RubyNilAnalysis
|
47
|
-
starting_with_dst = result.first.dst?
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# i.e. 12am is right before 1am and 12pm right before 1pm
|
53
|
-
convert_to_sec_since = lambda do |clocking|
|
54
|
-
from_src, to_src = clocking.split(' - ')
|
55
|
-
regex = /^(?<hour>\d+):(?<minute>\d+)(?<morning>[pa]).?m.*/
|
43
|
+
# sub-day is checked for DST and filtered along provided ranges
|
44
|
+
# noinspection RubyNilAnalysis
|
45
|
+
starting_with_dst = result.first.dst?
|
56
46
|
|
57
|
-
|
58
|
-
to
|
47
|
+
# The following lambda is completely misplaces here.
|
48
|
+
# It should probably relocated to Cotcube::Bardata
|
49
|
+
# NOTE: In this current version 12 belongs to it succeeding hour
|
50
|
+
# i.e. 12am is right before 1am and 12pm right before 1pm
|
51
|
+
convert_to_sec_since = lambda do |clocking|
|
52
|
+
from_src, to_src = clocking.split(' - ')
|
53
|
+
regex = /^(?<hour>\d+):(?<minute>\d+)(?<morning>[pa]).?m.*/
|
59
54
|
|
60
|
-
|
61
|
-
|
55
|
+
from = from_src.match(regex)
|
56
|
+
to = to_src.match(regex)
|
62
57
|
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
from_i = from[:hour].to_i * 3600 + from[:minute].to_i * 60 + (from[:morning] == 'a' ? 2 : 1) * 12 * 3600
|
59
|
+
to_i = to[:hour].to_i * 3600 + to[:minute].to_i * 60 + (to[:morning] == 'a' ? 2 : 3) * 12 * 3600
|
60
|
+
|
61
|
+
(0...5).to_a.map { |i| [from_i + i * 24 * 3600, to_i + i * 24 * 3600] }
|
62
|
+
end
|
63
|
+
convert_to_sec_since.call('9:00a.m - 5:00p.m.')
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
ranges ||= [
|
66
|
+
61_200...144_000, # Sun 5pm .. Mon 4pm
|
67
|
+
147_600...230_400, # Mon 5pm .. Tue 4pm
|
68
|
+
234_000...316_800, # ...
|
69
|
+
320_400...403_200,
|
70
|
+
406_800...489_600
|
71
|
+
]
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
# if there was a change towards daylight saving time, subtract 1 hour, otherwise add 1 hour
|
74
|
+
result.map! do |time|
|
75
|
+
if (not starting_with_dst) && time.dst?
|
76
|
+
time - 3600
|
77
|
+
elsif starting_with_dst && (not time.dst?)
|
78
|
+
time + 3600
|
79
|
+
else
|
80
|
+
time
|
81
|
+
end
|
83
82
|
end
|
84
|
-
end
|
85
83
|
|
86
|
-
|
84
|
+
result.select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_monday_morning }
|
85
|
+
end
|
87
86
|
end
|
88
87
|
end
|