aixm 1.2.0 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1dc4f9cb88ab4e481f835ca4d309142c6a17910b396f4293a6d9e7d3f946ec6
4
- data.tar.gz: 244adc808983bc3e810fb5847051a89dbd0893df3d2c709943d2c7231acfb434
3
+ metadata.gz: ce948465612571ae319c68d7f0eff0664d41c696440fb190298ac475b0e3105d
4
+ data.tar.gz: 402358be48d240b24baef522ace4c501b1c685073ef28be35ce70985a5eaa9e8
5
5
  SHA512:
6
- metadata.gz: ac00f735cca36dc6b1b0ec00c671dcbcbdb1e14c0d051fc8d865737e9ac1363d5648f5df69098b0daf721688c541a79188cac3603a07e01f8719fde3c8070d91
7
- data.tar.gz: 59d6ffb78fcb04104838bc4fb0ba50e7f3c5d526e921410e4300d08dafa08a2aa9cd1d637d374d7e5428d05c56e5f66186377a2f32fb6bff6c14ce5539044884
6
+ metadata.gz: ee675af09c87b12e15bd50e2b2a2c8f00b457cb6ec53c8ee3d16d1b1b5965e410687c2f24f51c49a9673cef00d882f2ef6101e6af780161d33f6f898ff903f9f
7
+ data.tar.gz: da8135812e7dd27baeb8068b8eefd6004467370763170737c18258b09cdc520bf09aad70fd6eb4c567dd39d5920c46ac1fd87a0ca5e30895c33b684fdf52ab73
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Nothing so far
4
4
 
5
+ ## 1.2.1
6
+
7
+ #### Additions
8
+ * Rounding of `AIXM::Schedule::Time`
9
+
5
10
  ## 1.2.0
6
11
 
7
12
  #### Additions
@@ -23,7 +23,7 @@ module AIXM
23
23
  include AIXM::Concerns::HashEquality
24
24
  extend Forwardable
25
25
 
26
- EVENTS = %i(sunrise sunset).freeze
26
+ EVENTS = { sunrise: :up, sunset: :down }.freeze
27
27
  PRECEDENCES = { first: :min, last: :max }.freeze
28
28
  DATELESS_DATE = ::Date.parse('0000-01-01').freeze
29
29
 
@@ -32,7 +32,7 @@ module AIXM
32
32
 
33
33
  # Event or alternative to time
34
34
  #
35
- # @return [Symbol, nil] any from {EVENTS}
35
+ # @return [Symbol, nil] any key from {EVENTS}
36
36
  attr_reader :event
37
37
 
38
38
  # Minutes added or subtracted from event
@@ -47,6 +47,10 @@ module AIXM
47
47
 
48
48
  # Parse the given representation of time.
49
49
  #
50
+ # @note Unlike its twin from the stdlib, this class differs between
51
+ # +AIXM.time('00:00')+ (beginning of day) and +AIXM.time('24:00')+
52
+ # (end of day).
53
+ #
50
54
  # @example
51
55
  # AIXM.time('08:00')
52
56
  # AIXM.time(:sunrise)
@@ -58,8 +62,8 @@ module AIXM
58
62
  #
59
63
  # @param time_or_event [Time, DateTime, String, Symbol] either time as
60
64
  # stdlib Time or DateTime, "HH:MM" (implicitly UTC), "HH:MM [+-]00:00",
61
- # "HH:MM UTC" or event from {EVENTS} as Symbol
62
- # @param or [Symbol] alternative event from {EVENTS}
65
+ # "HH:MM UTC" or any key from {EVENTS}
66
+ # @param or [Symbol] alternative event, any key from {EVENTS}
63
67
  # @param plus [Integer] minutes added to event
64
68
  # @param minus [Integer] minutes subtracted from event
65
69
  # @param whichever_comes [Symbol] any key from {PRECEDENCES}
@@ -127,7 +131,8 @@ module AIXM
127
131
  return self unless hour || min
128
132
  min ||= time.min
129
133
  hour ||= time.hour
130
- hour = (hour + 1) % 24 if wrap && min < time.min
134
+ hour = hour + 1 if wrap && min < time.min
135
+ hour = hour % 24 unless min.zero?
131
136
  self.class.new("%02d:%02d" % [hour, min])
132
137
  end
133
138
 
@@ -144,17 +149,17 @@ module AIXM
144
149
  #
145
150
  # @param on [AIXM::Date] defaults to today
146
151
  # @param xy [AIXM::XY]
152
+ # @param round [Integer, nil] round up (sunrise) or down (sunset) to the
153
+ # given minutes or +nil+ in order not to round round
147
154
  # @return [AIXM::Schedule::Time, self]
148
- def resolve(on:, xy:)
155
+ def resolve(on:, xy:, round: nil)
149
156
  if resolved?
150
157
  self
151
158
  else
152
159
  sun_time = self.class.new(Sun.send(event, on.to_date, xy.lat, xy.long).utc + (delta * 60))
153
- if time
154
- self.class.new([sun_time.time, self.time].send(PRECEDENCES.fetch(precedence)))
155
- else
156
- sun_time
157
- end
160
+ sun_time = self.class.new([sun_time.time, self.time].send(PRECEDENCES.fetch(precedence))) if time
161
+ sun_time = sun_time.round(EVENTS.fetch(event) => round) if round
162
+ sun_time
158
163
  end
159
164
  end
160
165
 
@@ -165,6 +170,22 @@ module AIXM
165
170
  !event
166
171
  end
167
172
 
173
+ # Round this time up or down.
174
+ #
175
+ # @param up [Integer, nil] round up to the next given minutes
176
+ # @param down [Integer, nil] round down to the next given minutes
177
+ # @return [AIXM::Schedule::Time, self]
178
+ def round(up: nil, down: nil)
179
+ step = up || down || fail(ArgumentError, "either up or down is mandatory")
180
+ rounded_min = min / step * step
181
+ if rounded_min == min
182
+ self
183
+ else
184
+ rounded_min = (rounded_min + step) % 60 if up
185
+ at(min: rounded_min, wrap: !!up)
186
+ end
187
+ end
188
+
168
189
  # Stdlib Time equivalent using the value of {DATELESS_DATE} to represent a
169
190
  # time only.
170
191
  #
@@ -232,7 +253,7 @@ module AIXM
232
253
  end
233
254
 
234
255
  def event=(value)
235
- fail ArgumentError if value && !EVENTS.include?(value)
256
+ fail ArgumentError if value && !EVENTS.has_key?(value)
236
257
  @event = value
237
258
  end
238
259
 
data/lib/aixm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module AIXM
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.2.1".freeze
3
3
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aixm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
@@ -30,7 +30,7 @@ cert_chain:
30
30
  1+2Y1+i+4jd1B7qxIgOLxQTNIJiwE0sqU1itFfuesfgUACS7M0IV9u9Bp4hBGNEw
31
31
  5JcY2h7owdMxXIvgk1oakgldFJc=
32
32
  -----END CERTIFICATE-----
33
- date: 2022-04-21 00:00:00.000000000 Z
33
+ date: 2022-04-23 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: builder
metadata.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ?9{�N�a��Ƌ9y�ń$����*�ʈ��{���1;V� �!��*1�b[߷LD�d�:�A.��VV�?e�GT^5��[ ���� �2wsξS�3����2�Eh�d��S><�ׇ!����RyM AG�����9�I���1�D鹵�Y�WG��~<�IíH���L[O޾����G�d^�v{�r��d����g�!�<8�ӷh�$�m�A�D� ;�ϲqWģ�ΦlT�B��w���Ć�
1
+ }�j�%�1dZX{I������:�bq�K�@�b�b��l��heP�c M��AV.蚲�%�i:OX�+�`<���En2��ʎT���!)b��@ЅZ>1�ח�
2
+ S4�z���4D�qvh��܋w��%U7�(���Z�oH@�C�v�ǟ������82ʿk�E(I@��>�[&���|�x4�o�{�ǍqEP���v�$��&��aI �ټ�"�iz�;c���M�X����7(�؝
3
+ F}Ue�h�0