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.3.2'

Class Method Summary collapse

Class Method Details

.determine_type(s) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/fugit/parse.rb', line 35

def 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



29
30
31
32
33
# File 'lib/fugit/parse.rb', line 29

def do_parse(s, opts={})

  parse(s, opts) ||
  fail(ArgumentError.new("found no time information in #{s.inspect}"))
end

.do_parse_at(s) ⇒ Object



15
# File 'lib/fugit/parse.rb', line 15

def do_parse_at(s); ::Fugit::At.do_parse(s); end

.do_parse_cron(s) ⇒ Object



12
# File 'lib/fugit/parse.rb', line 12

def do_parse_cron(s); ::Fugit::Cron.do_parse(s); end

.do_parse_duration(s) ⇒ Object



13
# File 'lib/fugit/parse.rb', line 13

def do_parse_duration(s); ::Fugit::Duration.do_parse(s); end

.do_parse_in(s) ⇒ Object



16
# File 'lib/fugit/parse.rb', line 16

def do_parse_in(s); do_parse_duration(s); end

.do_parse_nat(s, opts = {}) ⇒ Object



14
# File 'lib/fugit/parse.rb', line 14

def do_parse_nat(s, opts={}); ::Fugit::Nat.do_parse(s, opts); end

.isostamp(show_date, show_time, show_usec, time) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fugit/misc.rb', line 6

def 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



18
19
20
21
22
23
24
25
26
27
# File 'lib/fugit/parse.rb', line 18

def 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[:nat] != false && parse_nat(s, opts)) ||
  (opts[:at] != false && parse_at(s)) ||
  nil
end

.parse_at(s) ⇒ Object



9
# File 'lib/fugit/parse.rb', line 9

def parse_at(s); ::Fugit::At.parse(s); end

.parse_cron(s) ⇒ Object



6
# File 'lib/fugit/parse.rb', line 6

def parse_cron(s); ::Fugit::Cron.parse(s); end

.parse_duration(s) ⇒ Object



7
# File 'lib/fugit/parse.rb', line 7

def parse_duration(s); ::Fugit::Duration.parse(s); end

.parse_in(s) ⇒ Object



10
# File 'lib/fugit/parse.rb', line 10

def parse_in(s); parse_duration(s); end

.parse_nat(s, opts = {}) ⇒ Object



8
# File 'lib/fugit/parse.rb', line 8

def parse_nat(s, opts={}); ::Fugit::Nat.parse(s, opts); end

.time_to_plain_s(t = Time.now, z = true) ⇒ Object



24
25
26
27
# File 'lib/fugit/misc.rb', line 24

def 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



19
20
21
22
# File 'lib/fugit/misc.rb', line 19

def time_to_s(t)

  isostamp(true, true, false, t)
end

.time_to_zone_s(t = Time.now) ⇒ Object



29
30
31
32
# File 'lib/fugit/misc.rb', line 29

def time_to_zone_s(t=Time.now)

  t.strftime('%Y-%m-%d %H:%M:%S %Z %z')
end