cotcube-helpers 0.1.5.1 → 0.1.5.4

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: e3d088e43fd870ff67a238501fd680f1c5688c7108bc90ace92e01cd8c33627b
4
- data.tar.gz: 72b07a1f0e502a29e9cb818d62a8d398fe5e094efade358300eab4578b64ceae
3
+ metadata.gz: 97c255de9c0dac3cad83de38b0b8e1eb21af6d27bdf751d58dcc013b9044a7bc
4
+ data.tar.gz: 01cb8859f054baf5c87d55d7b718d8261b48428a59e0e728acbb759855526804
5
5
  SHA512:
6
- metadata.gz: 7b92ec6b178328bd6944f61828848d1d1c4aa164e9a3680054345189503d237a809ea082441eeab476ff693eeebdf5bf27bec300b3606af589598da946ce1c0a
7
- data.tar.gz: 00d63e82c5ed3cfcc9986f4ec3222e2282a692ed0ad54602cb4e212b9285d8c51182d9c87a4e8b9672d2f305409b6f01d27437b73aa40df6872a35e4ea962b8e
6
+ metadata.gz: 6358bd447301dd4a001b3e4f3ab6e80cd8d2e3073eef1ef9f05fa5c907bf7fd3a19245bd4ea4667bfaebade359e1dc6ea5b24a8f24cf2a8f43bfbb070b6e2567
7
+ data.tar.gz: a8876e8e07211f0648b2e646b721e52912bcf117f5b6d811f744368a86ab5c030a2f7ad6542464486fd6502ce9f7c8c51ff9cc5e04e401f45c9289a69e8eb1f5
@@ -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
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
- ##### The following is the actual big magic line, as it creates the raw target array:
30
- #
31
- result = (starting.to_time.to_i..ending.to_time.to_i).step(step).to_a.map { |x| timezone.at(x) }
32
- #
33
- # ###################<3##
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
- # with step.to_i >= 86400 we are risking stuff like 25.hours to return bogus
36
- # also notice: When using this with swaps, you will loose 1 hour (#f**k_it)
37
- #
38
- # eventually, for dailies and above, return M-F default, return S-S when forced by empty ranges
39
- if step.to_i >= 86_400
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
- # The following lambda is completely misplaces here.
50
- # It should probably relocated to Cotcube::Bardata
51
- # NOTE: In this current version 12 belongs to it succeeding hour
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
- from = from_src.match(regex)
58
- to = to_src.match(regex)
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
- from_i = from[:hour].to_i * 3600 + from[:minute].to_i * 60 + (from[:morning] == 'a' ? 2 : 1) * 12 * 3600
61
- to_i = to[:hour].to_i * 3600 + to[:minute].to_i * 60 + (to[:morning] == 'a' ? 2 : 3) * 12 * 3600
55
+ from = from_src.match(regex)
56
+ to = to_src.match(regex)
62
57
 
63
- (0...5).to_a.map { |i| [from_i + i * 24 * 3600, to_i + i * 24 * 3600] }
64
- end
65
- convert_to_sec_since.call('9:00a.m - 5:00p.m.')
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
- ranges ||= [
68
- 61_200...144_000, # Sun 5pm .. Mon 4pm
69
- 147_600...230_400, # Mon 5pm .. Tue 4pm
70
- 234_000...316_800, # ...
71
- 320_400...403_200,
72
- 406_800...489_600
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
- # if there was a change towards daylight saving time, subtract 1 hour, otherwise add 1 hour
76
- result.map! do |time|
77
- if (not starting_with_dst) && time.dst?
78
- time - 3600
79
- elsif starting_with_dst && (not time.dst?)
80
- time + 3600
81
- else
82
- time
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
- result.select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_monday_morning }
84
+ result.select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_monday_morning }
85
+ end
87
86
  end
88
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.1
4
+ version: 0.1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf