zones 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zones.rb +49 -43
- data/zones.gemspec +1 -1
- metadata +3 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f86231105060ba0d2a2e5de9b5d5e1a12697442eab2f53e25141ae9e364c595
|
4
|
+
data.tar.gz: 435fd13071ba665a0e3c8f4cca2162a804ca160ffee145ca179558a4e22f383d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10f84f521cefa6e9ef0d3933338d8c6666dde86908fb18cf8d530ffe71535e95cb8c028a1537356edba17ce5d36a6fdf71a86dfc040208a178b0ea8282adfa48
|
7
|
+
data.tar.gz: 5929966234fda57b8b1fac23ace116f43369e3a68a994ad4413d56ed001c415efc22e850e27f2a2de9175bfb8bd6a363575d14d408a7618a69b246c18b6e3fc6
|
data/lib/zones.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
require "tzinfo"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?)?$'); // Timezone part.
|
3
|
+
# ==[ Dart uses the folllowing ]==
|
4
|
+
#
|
5
|
+
# date ::= yeardate time_opt timezone_opt
|
6
|
+
# yeardate ::= year colon_opt month colon_opt day
|
7
|
+
# year ::= sign_opt digit{4,6}
|
8
|
+
# colon_opt :: <empty> | ':'
|
9
|
+
# sign ::= '+' | '-'
|
10
|
+
# sign_opt ::= <empty> | sign
|
11
|
+
# month ::= digit{2}
|
12
|
+
# day ::= digit{2}
|
13
|
+
# time_opt ::= <empty> | (' ' | 'T') hour minutes_opt
|
14
|
+
# minutes_opt ::= <empty> | colon_opt digit{2} seconds_opt
|
15
|
+
# seconds_opt ::= <empty> | colon_opt digit{2} millis_opt
|
16
|
+
# micros_opt ::= <empty> | ('.' | ',') digit+
|
17
|
+
# timezone_opt ::= <empty> | space_opt timezone
|
18
|
+
# space_opt :: ' ' | <empty>
|
19
|
+
# timezone ::= 'z' | 'Z' | sign digit{2} timezonemins_opt
|
20
|
+
# timezonemins_opt ::= <empty> | colon_opt digit{2}
|
21
|
+
#
|
22
|
+
# static final RegExp _parseFormat =
|
23
|
+
# RegExp(r'^([+-]?\d{4,6})-?(\d\d)-?(\d\d)' // Day part.
|
24
|
+
# r'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d+))?)?)?' // Time part.
|
25
|
+
# r'( ?[zZ]| ?([-+])(\d\d)(?::?(\d\d))?)?)?$'); // Timezone part.
|
27
26
|
|
28
27
|
class Date
|
29
28
|
def self.parse_str(str)
|
@@ -64,7 +63,7 @@ class Time
|
|
64
63
|
when %r!^((?:19|20)\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)?\.?(\d+)?([-+]\d\d:?\d\d)?!
|
65
64
|
ymd = [$1.to_i, $2.to_i, $3.to_i]
|
66
65
|
hms = [$4.to_i, $5.to_i, "#{$6}.#{$7}".to_f]
|
67
|
-
off = $8.sub(/(\d)(\d\d)$/,
|
66
|
+
off = $8.sub(/(\d)(\d\d)$/,'\1:\2') if $8 && !ignore_offset
|
68
67
|
when %r!^
|
69
68
|
(?:(0[1-9]|[12]\d|3[01]|[1-9][-/ ])[-/ ]? # $1: day
|
70
69
|
((?>[a-z]{3,9}))[-/ ]? # $2: month
|
@@ -107,15 +106,15 @@ class Time
|
|
107
106
|
end
|
108
107
|
|
109
108
|
# parse time and honor desired timezone
|
110
|
-
def self.to_tz(str,
|
109
|
+
def self.to_tz(str, zone=nil, ignore_offset=false)
|
111
110
|
ymd, hms, off = parse_str(str, ignore_offset)
|
112
111
|
out = Time.new(*ymd, *hms, off)
|
113
|
-
if
|
112
|
+
if zone
|
114
113
|
if off
|
115
|
-
out = out.to_tz(
|
114
|
+
out = out.to_tz(zone)
|
116
115
|
else
|
117
116
|
utc = out.utc
|
118
|
-
off = TZInfo::Timezone.get(
|
117
|
+
off = TZInfo::Timezone.get(zone).utc_to_local(utc) - utc
|
119
118
|
out = Time.new(*ymd, *hms, off)
|
120
119
|
end
|
121
120
|
else
|
@@ -124,25 +123,32 @@ class Time
|
|
124
123
|
end
|
125
124
|
|
126
125
|
# ignore supplied timezone, use local
|
127
|
-
def self.to_tz!(str,
|
128
|
-
to_tz(str,
|
126
|
+
def self.to_tz!(str, zone=nil)
|
127
|
+
to_tz(str, zone, true)
|
129
128
|
end
|
130
129
|
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
130
|
+
# NOTE: We can clean this up too...
|
131
|
+
# this 1-liner works, but returns a TZInfo::TimeWithOffset???
|
132
|
+
# def in_tz(zone); TZInfo::Timezone.get(zone).to_local(self); end
|
133
|
+
|
134
|
+
# same time moment, different time zone offset
|
135
|
+
def in_tz(zone)
|
136
|
+
cfg = TZInfo::Timezone.get(zone)
|
137
|
+
use = cfg.to_local(self)
|
138
|
+
ary = use.to_a[1,5].reverse.push(strftime("%S.%6N").to_f)
|
139
|
+
Time.new(*ary, cfg)
|
137
140
|
end
|
138
141
|
|
139
|
-
#
|
140
|
-
def
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
# same time values, different time zone offset
|
143
|
+
def as_tz(zone)
|
144
|
+
cfg = TZInfo::Timezone.get(zone)
|
145
|
+
use = self
|
146
|
+
ary = use.to_a[1,5].reverse.push(strftime("%S.%6N").to_f)
|
147
|
+
Time.new(*ary, cfg)
|
145
148
|
end
|
149
|
+
|
150
|
+
alias_method :to_tz , :in_tz
|
151
|
+
alias_method :to_tz!, :as_tz
|
146
152
|
end
|
147
153
|
|
148
154
|
class String
|
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: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem makes it easy to work with time zones.
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -16,7 +16,6 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- ".ruby-version"
|
20
19
|
- Gemfile
|
21
20
|
- LICENSE
|
22
21
|
- README.md
|
@@ -41,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
requirements: []
|
44
|
-
rubygems_version: 3.
|
43
|
+
rubygems_version: 3.4.14
|
45
44
|
signing_key:
|
46
45
|
specification_version: 4
|
47
46
|
summary: Easy time parsing and conversion between time zones
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.6.5
|