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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3ad790bb200e2bb944f6d8b69abb66a3f5563c0d601fd51839c19fa9b2585ed
4
- data.tar.gz: 1a9c61b4371a23fb0e4c4db5dfdf5ffb0fd440415f811e232a580e6ce71d37f0
3
+ metadata.gz: f18b492d498b8c0ff786a9f87e2e37dd71428aaf6ebaa1500b4f6e8fe2c0e200
4
+ data.tar.gz: 46d56c7b0561c3b8ac26475ad9cc8893501c1c61748c2d1d0497ade0fa08ea51
5
5
  SHA512:
6
- metadata.gz: 5f6032e29f4f91a638c5d524cd94854128ad9f59d2a017989088dd44c130098bbce44460f0d57396e3dd81a155b770fdcc3454be8069513924aa1dfe1807ea0d
7
- data.tar.gz: 2b9b2e1b4dd3c49c103d856509096ca0672c3efff4b9e3d5affb87559de010416c9944de55cd4284a8f3bc949ef2f6251fe0fd56c7a055aa516f63b046a09c28
6
+ metadata.gz: 1bdc09efbc0dcaf4ed532e4ec42f45a9a74577e6af132590fc78f0557f7aa7669dd8f37eeabda27feee2f65a995bcc36c55c4a9c7fe90b5105585657eb919525
7
+ data.tar.gz: 7a503eb5a07fe006d43d05a9ace9cc23839e91e6caf710c73afb000726cbee1abda561efd3adb43cd636504f3ae37580274ea80834f9c6f0bcca8091ed55e7dd
@@ -2,6 +2,11 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## et-orbi 1.2.3 released 2020-03-06
6
+
7
+ - Introduce EtOrbi.chronic_enabled = false and EtOrbi.chronic_enabled?, gh-26
8
+
9
+
5
10
  ## et-orbi 1.2.2 released 2019-08-19
6
11
 
7
12
  - Let EoTime#== accept EoTime or ::Time instances, gh-20, gh-7
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
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2019, John Mettraux, jmettraux+flor@gmail.com
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`.
@@ -13,6 +13,6 @@ require 'et-orbi/zone'
13
13
 
14
14
  module EtOrbi
15
15
 
16
- VERSION = '1.2.2'
16
+ VERSION = '1.2.3'
17
17
  end
18
18
 
@@ -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 defined?(::Chronic) && t = ::Chronic.parse(str, opts)
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.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: 2019-08-19 00:00:00.000000000 Z
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