cotcube-helpers 0.1.5.4 → 0.1.6
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 +4 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/array_ext.rb +20 -0
- data/lib/cotcube-helpers/range_ext.rb +33 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0417adfcb0f782bfa9e783dbd1c673a489fca39ce9a0f14fa965eb47aaa64b11
|
4
|
+
data.tar.gz: 1b14e149cc6b1bd437d1413dfa49b461c798868959cf97b164a0b3a2e1f72889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2babf733929f4ca0705ac2018b075e3b62df051c4918d01fcc6c11b49a7cad2ee68fd8ef26504edc5678c3057a97092de252a34cec2a953f638cd9262c2e65d
|
7
|
+
data.tar.gz: 1d9e367613f5b373c73cada786dee68d4e5ccc965573373b39d6419433a5f8131bc553773279d7ba58f2706a63be474448e15cc1e7bce1da63278ad384abeee0
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -74,4 +74,24 @@ class Array
|
|
74
74
|
end.reduce(:|)
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
|
79
|
+
# unless range.is_a? Range and
|
80
|
+
# (range.begin.nil? or range.begin.is_a?(Integer)) and
|
81
|
+
# (range.end.nil? or range.end.is_a?(Integer))
|
82
|
+
# raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
|
83
|
+
# end
|
84
|
+
|
85
|
+
raise ArgumentError, 'No block given.' unless block.is_a? Proc
|
86
|
+
|
87
|
+
inclusive = true unless exclusive
|
88
|
+
if inclusive && exclusive
|
89
|
+
raise ArgumentError,
|
90
|
+
"Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
|
91
|
+
end
|
92
|
+
|
93
|
+
index = find_index { |obj| block.call(obj) }
|
94
|
+
|
95
|
+
self[((inclusive ? index : index + 1)..)]
|
96
|
+
end
|
77
97
|
end
|
@@ -2,12 +2,17 @@
|
|
2
2
|
|
3
3
|
# Monkey patching the Ruby Core class Range
|
4
4
|
class Range
|
5
|
-
def to_time_intervals(step:,
|
5
|
+
def to_time_intervals(step:,
|
6
|
+
timezone: Time.find_zone('America/Chicago'),
|
7
|
+
# ranges: nil,
|
8
|
+
debug: false)
|
6
9
|
unless step.is_a? ActiveSupport::Duration
|
7
10
|
raise ArgumentError,
|
8
11
|
":step must be a 'ActiveSupport::Duration', like '15.minutes', but '#{step}' is a '#{step.class}'"
|
9
12
|
end
|
10
|
-
|
13
|
+
unless [15.minutes, 60.minutes, 1.hour, 1.day].include? step
|
14
|
+
raise ArgumentError, 'Sorry, currently supporting only 15.minutes, 1.hour, 1.day as :step'
|
15
|
+
end
|
11
16
|
|
12
17
|
valid_classes = [ActiveSupport::TimeWithZone, Time, Date, DateTime]
|
13
18
|
unless timezone.is_a? ActiveSupport::TimeZone
|
@@ -30,21 +35,22 @@ class Range
|
|
30
35
|
# here sub-day and super-day need to be distinguished, as they react differently to daylight time
|
31
36
|
# for super-day, just return an array containing all calendar days
|
32
37
|
if step.to_i >= 1.day
|
33
|
-
|
38
|
+
(starting.to_date..ending.to_date).to_a.map(&:to_datetime)
|
34
39
|
else
|
35
40
|
|
41
|
+
# sub-day is checked for DST
|
42
|
+
# noinspection RubyNilAnalysis
|
43
|
+
actual_starting = starting.to_time.to_i
|
44
|
+
actual_ending = ending.to_time.to_i
|
45
|
+
actual_ending -= 3600 if starting.dst? && (not ending.dst?)
|
46
|
+
actual_ending += 3600 if ending.dst? && (not starting.dst?)
|
47
|
+
|
36
48
|
##### The following is the actual big magic line, as it creates the raw target array:
|
37
49
|
#
|
38
|
-
result = (
|
50
|
+
result = (actual_starting..actual_ending).step(step).to_a.map { |x| timezone.at(x) }
|
39
51
|
#
|
40
52
|
# ###################<3##
|
41
53
|
|
42
|
-
|
43
|
-
# sub-day is checked for DST and filtered along provided ranges
|
44
|
-
# noinspection RubyNilAnalysis
|
45
|
-
starting_with_dst = result.first.dst?
|
46
|
-
|
47
|
-
# The following lambda is completely misplaces here.
|
48
54
|
# It should probably relocated to Cotcube::Bardata
|
49
55
|
# NOTE: In this current version 12 belongs to it succeeding hour
|
50
56
|
# i.e. 12am is right before 1am and 12pm right before 1pm
|
@@ -62,26 +68,29 @@ class Range
|
|
62
68
|
end
|
63
69
|
convert_to_sec_since.call('9:00a.m - 5:00p.m.')
|
64
70
|
|
65
|
-
ranges ||= [
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
]
|
71
|
+
# ranges ||= [
|
72
|
+
# 61_200...144_000, # Sun 5pm .. Mon 4pm
|
73
|
+
# 147_600...230_400, # Mon 5pm .. Tue 4pm
|
74
|
+
# 234_000...316_800, # ...
|
75
|
+
# 320_400...403_200,
|
76
|
+
# 406_800...489_600
|
77
|
+
# ]
|
72
78
|
|
73
79
|
# if there was a change towards daylight saving time, subtract 1 hour, otherwise add 1 hour
|
74
80
|
result.map! do |time|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
time
|
81
|
+
print "#{time}\t" if debug
|
82
|
+
if (not starting.dst?) && time.dst?
|
83
|
+
time -= 3600
|
84
|
+
print "Time reduced (not starting_DST, but current\t" if debug
|
85
|
+
elsif starting.dst? && (not time.dst?)
|
86
|
+
time += 3600
|
87
|
+
print "Time extended (starting DST, but not current\t" if debug
|
81
88
|
end
|
89
|
+
puts "#{time} " if debug
|
90
|
+
time
|
82
91
|
end
|
83
92
|
|
84
|
-
result.select_within(ranges: ranges) { |x| x.to_datetime.
|
93
|
+
result # .select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_sunday_morning }
|
85
94
|
end
|
86
95
|
end
|
87
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|