et-orbi 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CREDITS.md +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +41 -1
- data/lib/et-orbi.rb +1 -1
- data/lib/et-orbi/make.rb +21 -2
- 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: f18b492d498b8c0ff786a9f87e2e37dd71428aaf6ebaa1500b4f6e8fe2c0e200
|
4
|
+
data.tar.gz: 46d56c7b0561c3b8ac26475ad9cc8893501c1c61748c2d1d0497ade0fa08ea51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bdc09efbc0dcaf4ed532e4ec42f45a9a74577e6af132590fc78f0557f7aa7669dd8f37eeabda27feee2f65a995bcc36c55c4a9c7fe90b5105585657eb919525
|
7
|
+
data.tar.gz: 7a503eb5a07fe006d43d05a9ace9cc23839e91e6caf710c73afb000726cbee1abda561efd3adb43cd636504f3ae37580274ea80834f9c6f0bcca8091ed55e7dd
|
data/CHANGELOG.md
CHANGED
data/CREDITS.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
# et-orbi credits
|
3
3
|
|
4
|
+
* Stan Hu (https://github.com/stanhu) Chronic toubles, gh-24, gh-26, etc
|
4
5
|
* d-m-u (https://github.com/d-m-u) EoTime#==(Time), gh-20, gh-7
|
5
6
|
* Vais Salikhov (https://github.com/vais) missing US timezone aliases, gh-18 gh-19
|
6
7
|
* Wenhui Wang https://github.com/w11th .parse vs Chronic+ActiveSupport, fugit 11
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2017-
|
2
|
+
Copyright (c) 2017-2020, John Mettraux, jmettraux+flor@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ EtOrbi.parse('1970-01-01 03:00:00 Europe/Moscow')
|
|
37
37
|
```
|
38
38
|
|
39
39
|
More about `EtOrbi::EoTime` instances:
|
40
|
-
```
|
40
|
+
```ruby
|
41
41
|
eot = EtOrbi::EoTime.new(0, 'Europe/Moscow')
|
42
42
|
|
43
43
|
eot.to_local_time.class # => Time
|
@@ -69,6 +69,46 @@ EtOrbi.platform_info
|
|
69
69
|
# astz: ActiveSupport provided Time.zone
|
70
70
|
```
|
71
71
|
|
72
|
+
### Chronic integration
|
73
|
+
|
74
|
+
By default, et-orbi relies on [Chronic](https://github.com/mojombo/chronic) to parse strings like "tomorrow" or "friday 1pm", if `Chronic` is present.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
EtOrbi.parse('tomorrow')
|
78
|
+
# => #<EtOrbi::EoTime:0x007fbc6aa8a560 @seconds=1575687600.0, @zone=#<TZInfo::TimezoneProxy: Asia/Tokyo>, @time=nil>
|
79
|
+
EtOrbi.parse('tomorrow').to_s
|
80
|
+
# => "2019-12-07 12:00:00 +0900"
|
81
|
+
```
|
82
|
+
|
83
|
+
This is a poor design choice I replicated from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
84
|
+
|
85
|
+
Of course this leads to [issues](https://gitlab.com/gitlab-org/gitlab/issues/37014).
|
86
|
+
|
87
|
+
It's probably better to have Chronic do its work outside of et-orbi, like in:
|
88
|
+
```ruby
|
89
|
+
EtOrbi.parse(Chronic.parse('tomorrow').to_s).to_s
|
90
|
+
# => "2019-12-07 12:00:00 +0900"
|
91
|
+
```
|
92
|
+
|
93
|
+
If one has Chronic present in his project but doesn't want it to interfere with et-orbi, it can be disabled at `parse` call:
|
94
|
+
```ruby
|
95
|
+
EtOrbi.parse('tomorrow')
|
96
|
+
# => #<EtOrbi::EoTime:0x007ffb5b2a2390 @seconds=1575687600.0, @zone=#<TZInfo::TimezoneProxy: Asia/Tokyo>, @time=nil>
|
97
|
+
EtOrbi.parse('tomorrow', enable_chronic: false)
|
98
|
+
# ArgumentError: No time information in "tomorrow"
|
99
|
+
# from /home/jmettraux/w/et-orbi/lib/et-orbi/make.rb:31:in `rescue in parse'
|
100
|
+
```
|
101
|
+
or at the et-orbi level:
|
102
|
+
```ruby
|
103
|
+
irb(main):007:0> EtOrbi.chronic_enabled = false
|
104
|
+
# => false
|
105
|
+
irb(main):008:0> EtOrbi.chronic_enabled?
|
106
|
+
# => false
|
107
|
+
EtOrbi.parse('tomorrow')
|
108
|
+
# ArgumentError: No time information in "tomorrow"
|
109
|
+
# from /home/jmettraux/w/et-orbi/lib/et-orbi/make.rb:31:in `rescue in parse'
|
110
|
+
```
|
111
|
+
|
72
112
|
### Rails?
|
73
113
|
|
74
114
|
If Rails is present, `Time.zone` is provided and EtOrbi will use it, unless `ENV['TZ']` is set to a valid timezone name. Setting `ENV['TZ']` to nil can give back precedence to `Time.zone`.
|
data/lib/et-orbi.rb
CHANGED
data/lib/et-orbi/make.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
|
2
2
|
module EtOrbi
|
3
3
|
|
4
|
+
@chronic_enabled = true
|
5
|
+
#
|
6
|
+
def self.chronic_enabled?
|
7
|
+
@chronic_enabled
|
8
|
+
end
|
9
|
+
def self.chronic_enabled=(b)
|
10
|
+
@chronic_enabled = b
|
11
|
+
end
|
12
|
+
|
4
13
|
class << self
|
5
14
|
|
6
15
|
def now(zone=nil)
|
@@ -12,8 +21,7 @@ module EtOrbi
|
|
12
21
|
|
13
22
|
str, str_zone = extract_zone(str)
|
14
23
|
|
15
|
-
if
|
16
|
-
|
24
|
+
if t = chronic_parse(str, opts)
|
17
25
|
str = [ t.strftime('%F %T'), str_zone ].compact.join(' ')
|
18
26
|
end
|
19
27
|
|
@@ -60,6 +68,17 @@ module EtOrbi
|
|
60
68
|
|
61
69
|
protected
|
62
70
|
|
71
|
+
def chronic_parse(str, opts)
|
72
|
+
|
73
|
+
return false unless defined?(::Chronic)
|
74
|
+
return false unless opts.fetch(:enable_chronic) { self.chronic_enabled? }
|
75
|
+
|
76
|
+
os = opts
|
77
|
+
.select { |k, _| Chronic::Parser::DEFAULT_OPTIONS.keys.include?(k) }
|
78
|
+
|
79
|
+
::Chronic.parse(str, os)
|
80
|
+
end
|
81
|
+
|
63
82
|
def make_from_time(t, zone)
|
64
83
|
|
65
84
|
z =
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: et-orbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.7.6
|
101
|
+
rubygems_version: 2.7.6.2
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: time with zones
|