zones 1.0.1 → 1.1.0
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/README.md +51 -13
- data/lib/zones.rb +10 -8
- data/zones.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68effb6f43a7c0bc15f336624569d9f39c549cacd0b4afb319f4f40af29bd35b
|
4
|
+
data.tar.gz: 5eaa777bd12704f63a3d76b09dd6957f6e7896213c710377c8acdf7e7499b7bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef064dda2c373fd9faf62866e381432c76d72ed6735b0c1f1e544f21a8a0c4f7c909c8aabfc2756294e54862408012e63025b24da4d9693344ede3ba8ead648c
|
7
|
+
data.tar.gz: e7871c5dac1315da804bccf33c8a42f78196d1a13ff5dfbbca537a7d1cdfc8728f9a4f0126eb07c3a912389ce9bd403b4da5ff1f9c6bda360b04815806110580
|
data/README.md
CHANGED
@@ -5,13 +5,13 @@ A friendly Ruby gem for time parsing and time zone conversion.
|
|
5
5
|
## API
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
Time.
|
9
|
-
Time.
|
8
|
+
Time.to_tz(str, toz=nil, asz=nil) # create a new Time object with a time zone
|
9
|
+
Time.as_tz(str, asz="UTC", toz=nil) # overrides original time zone and swaps params
|
10
10
|
Time#to(zone) # converts a time to a new time zone
|
11
11
|
Time#as(zone) # keeps the time, but changes the time zone
|
12
12
|
|
13
|
-
String#to_tz # calls Time.
|
14
|
-
String#
|
13
|
+
String#to_tz # calls Time.to_tz
|
14
|
+
String#as_tz # calls Time.as_tz
|
15
15
|
String#to_day # calls Date.to_day
|
16
16
|
String#iso_date # parses and shows ISO date (YYYY-MM-DD)
|
17
17
|
```
|
@@ -21,17 +21,55 @@ String#iso_date # parses and shows ISO date (YYYY-MM-DD)
|
|
21
21
|
Parsing strings:
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
# no argument means to parse the value as is;
|
25
|
-
|
26
|
-
|
24
|
+
# no argument means to parse the value as is; 'as' ignores the time zone and defaults to UTC
|
25
|
+
"3 August 2013 11:43 +0415".to_tz # 2013-08-03 11:43:00 +0415
|
26
|
+
"3 August 2013 11:43 +0415".as_tz # 2013-08-03 11:43:00 +0000
|
27
27
|
|
28
|
-
# one argument
|
29
|
-
|
30
|
-
|
28
|
+
# one argument for `to_tz` means to parse naturally and then convert to that time zone
|
29
|
+
"3 August 2013 11:43 +0415".to_tz("US/Pacific") # 2013-08-03 00:28:00 -0700
|
30
|
+
"3 August 2013 11:43 +0415".to_tz("America/Caracas") # 2013-08-03 02:58:00 -0430
|
31
31
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
32
|
+
# one argument for `as_tz` means to ignore offset and use the parameter passed in
|
33
|
+
"3 August 2013 11:43 +0415".as_tz("US/Pacific") # 2013-08-03 11:43:00 -0700
|
34
|
+
"3 August 2013 11:43 +0415".as_tz("America/Caracas") # 2013-08-03 11:43:00 -0430
|
35
|
+
|
36
|
+
# use two arguments to indicate destination and source time zones, 'as' swaps the order
|
37
|
+
"3 August 2013 11:43 +0415".to_tz("US/Pacific", "America/Caracas") # 2013-08-03 09:13:00 -0700
|
38
|
+
"3 August 2013 11:43 +0415".as_tz("US/Pacific", "America/Caracas") # 2013-08-03 14:13:00 -0430
|
39
|
+
|
40
|
+
# the same as above, swapping functions and parameter order gives same results
|
41
|
+
"3 August 2013 11:43 +0415".to_tz("America/Caracas", "US/Pacific") # 2013-08-03 14:13:00 -0430
|
42
|
+
"3 August 2013 11:43 +0415".as_tz("America/Caracas", "US/Pacific") # 2013-08-03 09:13:00 -0700
|
43
|
+
```
|
44
|
+
|
45
|
+
Parsing strings using `to_tz`:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# no args means to parse the value as is
|
49
|
+
"3 August 2013 11:43 +0415".to_tz # 2013-08-03 11:43:00 +0415
|
50
|
+
|
51
|
+
# one arg will then convert to that time zone
|
52
|
+
"3 August 2013 11:43 +0415".to_tz("US/Pacific") # 2013-08-03 00:28:00 -0700
|
53
|
+
"3 August 2013 11:43 +0415".to_tz("America/Caracas") # 2013-08-03 02:58:00 -0430
|
54
|
+
|
55
|
+
# two args forces the second arg as the initial time zone
|
56
|
+
"3 August 2013 11:43 +0415".to_tz("US/Pacific", "America/Caracas") # 2013-08-03 09:13:00 -0700
|
57
|
+
"3 August 2013 11:43 +0415".to_tz("America/Caracas", "US/Pacific") # 2013-08-03 14:13:00 -0430
|
58
|
+
```
|
59
|
+
|
60
|
+
Parsing strings using `as_tz`:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# no args forces the timezone to be UTC
|
64
|
+
"3 August 2013 11:43 +0415".as_tz # 2013-08-03 11:43:00 +0000
|
65
|
+
|
66
|
+
# one arg ignore offset and forces the time zone as the arg
|
67
|
+
"3 August 2013 11:43 +0415".as_tz("US/Pacific") # 2013-08-03 11:43:00 -0700
|
68
|
+
"3 August 2013 11:43 +0415".as_tz("America/Caracas") # 2013-08-03 11:43:00 -0430
|
69
|
+
|
70
|
+
# two args forces the second arg as the initial time zone
|
71
|
+
"3 August 2013 11:43 +0415".as_tz("US/Pacific", "America/Caracas") # 2013-08-03 14:13:00 -0430
|
72
|
+
"3 August 2013 11:43 +0415".as_tz("America/Caracas", "US/Pacific") # 2013-08-03 09:13:00 -0700
|
35
73
|
```
|
36
74
|
|
37
75
|
Converting values:
|
data/lib/zones.rb
CHANGED
@@ -94,17 +94,19 @@ class Time
|
|
94
94
|
[ymd, hms, off]
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
# read values of time in asz, stated, or local timezone, optionally convert to toz timezone
|
98
|
+
def self.to_tz(str, toz=nil, asz=nil)
|
98
99
|
ymd, hms, off = parse_str(str)
|
99
100
|
out = Time.new(*ymd, *hms, asz ? TZInfo::Timezone.get(asz) : off)
|
100
101
|
toz ? out.to(toz) : out
|
101
102
|
end
|
102
103
|
|
103
|
-
|
104
|
-
|
104
|
+
# swap the order of to_tz and default asz to UTC
|
105
|
+
def self.as_tz(str, asz="UTC", toz=nil)
|
106
|
+
to_tz(str, toz, asz)
|
105
107
|
end
|
106
108
|
|
107
|
-
# same time
|
109
|
+
# same moment in time, different time zone (ie - change time and zone)
|
108
110
|
def to(zone)
|
109
111
|
cfg = TZInfo::Timezone.get(zone)
|
110
112
|
use = cfg.to_local(self)
|
@@ -112,7 +114,7 @@ class Time
|
|
112
114
|
Time.new(*ary, cfg)
|
113
115
|
end
|
114
116
|
|
115
|
-
# same time
|
117
|
+
# same values of time, different time zone (ie - change time zone only)
|
116
118
|
def as(zone)
|
117
119
|
cfg = TZInfo::Timezone.get(zone)
|
118
120
|
use = self
|
@@ -131,10 +133,10 @@ class String
|
|
131
133
|
end
|
132
134
|
|
133
135
|
def to_tz(*args)
|
134
|
-
Time.
|
136
|
+
Time.to_tz(self, *args)
|
135
137
|
end
|
136
138
|
|
137
|
-
def
|
138
|
-
Time.
|
139
|
+
def as_tz(*args)
|
140
|
+
Time.as_tz(self, *args)
|
139
141
|
end
|
140
142
|
end
|
data/zones.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zones
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A friendly Ruby gem for time parsing and time zone conversion
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
rubygems_version: 3.4.
|
43
|
+
rubygems_version: 3.4.16
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: A friendly Ruby gem for time parsing and time zone conversion
|