time_calc 0.0.1 → 0.0.2
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 +5 -5
- data/Changelog.md +10 -0
- data/lib/time_calc/types.rb +16 -4
- data/lib/time_calc/version.rb +1 -1
- data/lib/time_calc.rb +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 277cc038ff0318d9b8aacb51c60ae7fda0730e24e913f89fd145dc4abb8420c4
|
4
|
+
data.tar.gz: 233d29d03a7d4be6bf6656ca567b16066096af9c4a47f102dc9aafdd52691759
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1977f5b4e572a304ef4ccb440c1b7ecc16cfe922d7e34f1163b85507cc4143fcfb8607c1a5f8b66b677986b6926af97cbd548560f0c4c056aabcb6e9faa34de1
|
7
|
+
data.tar.gz: 0f53ed256fa451adb9f30ccf256ac957c5370f0d0cbeba8d8dbe648066051ccbcea3ca45475a0a1234cd092014dd0059a14a21aa088f416b94c4efa341ad9295
|
data/Changelog.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# TimeCalc changelog
|
2
|
+
|
3
|
+
## 0.0.2 / 2019-07-08
|
4
|
+
|
5
|
+
* Alias `TimeCalc[tm]` for those who disapporve on `TimeCalc.(tm)`;
|
6
|
+
* More accurate zone infor preservation when time is in local timezone of current machine.
|
7
|
+
|
8
|
+
## 0.0.1 / 2019-07-05
|
9
|
+
|
10
|
+
First release. Rip-off of [time_math2](https://github.com/zverok/time_math2) with full API redesign and dropping of some less-used features ("resamplers").
|
data/lib/time_calc/types.rb
CHANGED
@@ -28,10 +28,8 @@ class TimeCalc
|
|
28
28
|
|
29
29
|
def merge_time(value, **attrs)
|
30
30
|
_merge(value, **attrs)
|
31
|
-
.tap { |h|
|
32
|
-
|
33
|
-
h[:utc_offset] = value.zone if value.zone.respond_to?(:utc_to_local) # Ruby 2.6 real timezones
|
34
|
-
}
|
31
|
+
.tap { |h| h[:sec] += h.delete(:subsec) }
|
32
|
+
.then { |h| fix_time_zone(h, value) }
|
35
33
|
.values.then { |components| Time.new(*components) }
|
36
34
|
end
|
37
35
|
|
@@ -50,6 +48,20 @@ class TimeCalc
|
|
50
48
|
|
51
49
|
private
|
52
50
|
|
51
|
+
REAL_TIMEZONE = ->(z) { z.respond_to?(:utc_to_local) } # Ruby 2.6 real timezones
|
52
|
+
|
53
|
+
def fix_time_zone(attrs, origin)
|
54
|
+
case origin.zone
|
55
|
+
when nil, '' # "" is JRuby's way to say "no zone known"
|
56
|
+
attrs
|
57
|
+
when String
|
58
|
+
# Y U NO Hash#except, Ruby???
|
59
|
+
attrs.slice(*attrs.keys.-([:utc_offset])) # Then it would be default, then it would set system's zone
|
60
|
+
when REAL_TIMEZONE
|
61
|
+
attrs.merge(utc_offset: origin.zone) # When passed in place of utc_offset, timezone object becomes Time's zone
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
def _merge(value, attrs)
|
54
66
|
attr_names = ATTRS.fetch(value.class)
|
55
67
|
attr_names.to_h { |u| [u, value.public_send(u)] }.merge(**attrs.slice(*attr_names))
|
data/lib/time_calc/version.rb
CHANGED
data/lib/time_calc.rb
CHANGED
@@ -60,6 +60,7 @@ require_relative 'time_calc/value'
|
|
60
60
|
class TimeCalc
|
61
61
|
class << self
|
62
62
|
alias call new
|
63
|
+
alias [] new
|
63
64
|
|
64
65
|
# Shortcut for `TimeCalc.(Time.now)`
|
65
66
|
# @return [TimeCalc]
|
@@ -118,6 +119,9 @@ class TimeCalc
|
|
118
119
|
# ```ruby
|
119
120
|
# TimeCalc.(Time.now).round(:hour)
|
120
121
|
# # => 2019-07-03 23:00:00 +0300
|
122
|
+
#
|
123
|
+
# # There is another shortcut for those who disapprove on `.()`
|
124
|
+
# TimeCalc[Time.now].+(1, :month)
|
121
125
|
# ```
|
122
126
|
#
|
123
127
|
# See {.from} if you need to perform several math operations on same value.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Shepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
@@ -173,6 +173,7 @@ executables: []
|
|
173
173
|
extensions: []
|
174
174
|
extra_rdoc_files: []
|
175
175
|
files:
|
176
|
+
- Changelog.md
|
176
177
|
- LICENSE.txt
|
177
178
|
- README.md
|
178
179
|
- lib/time_calc.rb
|
@@ -203,8 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
204
|
- !ruby/object:Gem::Version
|
204
205
|
version: '0'
|
205
206
|
requirements: []
|
206
|
-
|
207
|
-
rubygems_version: 2.6.14
|
207
|
+
rubygems_version: 3.0.3
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: Easy time math
|