Module: Fugit
- Defined in:
- lib/fugit.rb,
lib/fugit/at.rb,
lib/fugit/nat.rb,
lib/fugit/cron.rb,
lib/fugit/misc.rb,
lib/fugit/parse.rb,
lib/fugit/duration.rb
Defined Under Namespace
Modules: At, Nat
Classes: Cron, Duration
Constant Summary
collapse
- VERSION =
'1.1.0'
Class Method Summary
collapse
Class Method Details
.determine_type(s) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/fugit/parse.rb', line 33
def self.determine_type(s)
case self.parse(s)
when ::Fugit::Cron then 'cron'
when ::Fugit::Duration then 'in'
when ::Time, ::EtOrbi::EoTime then 'at'
else nil
end
end
|
.do_parse(s, opts = {}) ⇒ Object
27
28
29
30
31
|
# File 'lib/fugit/parse.rb', line 27
def self.do_parse(s, opts={})
parse(s, opts) ||
fail(ArgumentError.new("found no time information in #{s.inspect}"))
end
|
.do_parse_at(s) ⇒ Object
13
|
# File 'lib/fugit/parse.rb', line 13
def self.do_parse_at(s); ::Fugit::At.do_parse(s); end
|
.do_parse_cron(s) ⇒ Object
10
|
# File 'lib/fugit/parse.rb', line 10
def self.do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
|
.do_parse_duration(s) ⇒ Object
11
|
# File 'lib/fugit/parse.rb', line 11
def self.do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
|
.do_parse_in(s) ⇒ Object
14
|
# File 'lib/fugit/parse.rb', line 14
def self.do_parse_in(s); do_parse_duration(s); end
|
.do_parse_nat(s) ⇒ Object
12
|
# File 'lib/fugit/parse.rb', line 12
def self.do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
|
.isostamp(show_date, show_time, show_usec, time) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/fugit/misc.rb', line 4
def self.isostamp(show_date, show_time, show_usec, time)
t = time || Time.now
s = StringIO.new
s << t.strftime('%Y-%m-%d') if show_date
s << t.strftime('T%H:%M:%S') if show_time
s << sprintf('.%06d', t.usec) if show_time && show_usec
s << 'Z' if show_time && time.utc?
s.string
end
|
.parse(s, opts = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fugit/parse.rb', line 16
def self.parse(s, opts={})
opts[:at] = opts[:in] if opts.has_key?(:in)
(opts[:cron] != false && parse_cron(s)) ||
(opts[:duration] != false && parse_duration(s)) ||
(opts[:at] != false && parse_at(s)) ||
(opts[:nat] != false && parse_nat(s)) ||
nil
end
|
.parse_at(s) ⇒ Object
7
|
# File 'lib/fugit/parse.rb', line 7
def self.parse_at(s); ::Fugit::At.parse(s); end
|
.parse_cron(s) ⇒ Object
4
|
# File 'lib/fugit/parse.rb', line 4
def self.parse_cron(s); ::Fugit::Cron.parse(s); end
|
.parse_duration(s) ⇒ Object
5
|
# File 'lib/fugit/parse.rb', line 5
def self.parse_duration(s); ::Fugit::Duration.parse(s); end
|
.parse_in(s) ⇒ Object
8
|
# File 'lib/fugit/parse.rb', line 8
def self.parse_in(s); parse_duration(s); end
|
.parse_nat(s) ⇒ Object
6
|
# File 'lib/fugit/parse.rb', line 6
def self.parse_nat(s); ::Fugit::Nat.parse(s); end
|
.time_to_plain_s(t = Time.now, z = true) ⇒ Object
22
23
24
25
|
# File 'lib/fugit/misc.rb', line 22
def self.time_to_plain_s(t=Time.now, z=true)
t.strftime('%Y-%m-%d %H:%M:%S') + (z && t.utc? ? ' Z' : '')
end
|
.time_to_s(t) ⇒ Object
17
18
19
20
|
# File 'lib/fugit/misc.rb', line 17
def self.time_to_s(t)
isostamp(true, true, false, t)
end
|
.time_to_zone_s(t = Time.now) ⇒ Object
27
28
29
30
|
# File 'lib/fugit/misc.rb', line 27
def self.time_to_zone_s(t=Time.now)
t.strftime('%Y-%m-%d %H:%M:%S %Z %z')
end
|