class Sequel::SQLTime

  1. lib/sequel/sql.rb
Superclass: Time

Time subclass that gets literalized with only the time value, so it operates like a standard SQL time type. This type does not support timezones, by design, so it will not work correctly with time with time zone types.

Methods

Public Class

  1. create
  2. date
  3. date
  4. parse

Public Instance

  1. inspect
  2. to_s

Attributes

date [W]

Set the date used for SQLTime instances.

Public Class methods

create(hour, minute, second, usec = 0)

Create a new SQLTime instance given an hour, minute, second, and usec.

[show source]
   # File lib/sequel/sql.rb
52 def create(hour, minute, second, usec = 0)
53   t = date
54   meth = Sequel.application_timezone == :utc ? :utc : :local
55   public_send(meth, t.year, t.month, t.day, hour, minute, second, usec)
56 end
date()

Use the date explicitly set, or the current date if there is not a date set.

[show source]
   # File lib/sequel/sql.rb
32 def date
33   @date || now
34 end
parse(*)

Set the correct date and timezone when parsing times.

[show source]
   # File lib/sequel/sql.rb
37 def parse(*)
38   t = super
39 
40   utc = Sequel.application_timezone == :utc
41   d = @date
42   if d || utc
43     meth = utc ? :utc : :local
44     d ||= t
45     t = public_send(meth, d.year, d.month, d.day, t.hour, t.min, t.sec, t.usec)
46   end
47 
48   t
49 end

Public Instance methods

inspect()

Show that this is an SQLTime, and the time represented

[show source]
   # File lib/sequel/sql.rb
60 def inspect
61  "#<#{self.class} #{to_s}>"
62 end
to_s(*args)

Return a string in HH:MM:SS format representing the time.

[show source]
   # File lib/sequel/sql.rb
65 def to_s(*args)
66   if args.empty?
67     strftime('%H:%M:%S')
68   else
69     # Superclass may have defined a method that takes a format string,
70     # and we shouldn't override in that case.
71     super
72   end
73 end