lib/et-orbi/make.rb in et-orbi-1.2.2 vs lib/et-orbi/make.rb in et-orbi-1.2.3
- old
+ new
@@ -1,8 +1,17 @@
module EtOrbi
+ @chronic_enabled = true
+ #
+ def self.chronic_enabled?
+ @chronic_enabled
+ end
+ def self.chronic_enabled=(b)
+ @chronic_enabled = b
+ end
+
class << self
def now(zone=nil)
EoTime.new(Time.now.to_f, zone)
@@ -10,12 +19,11 @@
def parse(str, opts={})
str, str_zone = extract_zone(str)
- if defined?(::Chronic) && t = ::Chronic.parse(str, opts)
-
+ if t = chronic_parse(str, opts)
str = [ t.strftime('%F %T'), str_zone ].compact.join(' ')
end
begin
DateTime.parse(str)
@@ -57,9 +65,20 @@
end
end
alias make make_time
protected
+
+ def chronic_parse(str, opts)
+
+ return false unless defined?(::Chronic)
+ return false unless opts.fetch(:enable_chronic) { self.chronic_enabled? }
+
+ os = opts
+ .select { |k, _| Chronic::Parser::DEFAULT_OPTIONS.keys.include?(k) }
+
+ ::Chronic.parse(str, os)
+ end
def make_from_time(t, zone)
z =
zone ||