class Sequel::SQLTime

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.

Attributes

date[W]

Set the date used for SQLTime instances.

Public Class Methods

create(hour, minute, second, usec = 0) click to toggle source

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

   # 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() click to toggle source

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

   # File lib/sequel/sql.rb
32 def date
33   @date || now
34 end
parse(*) click to toggle source

Set the correct date and timezone when parsing times.

Calls superclass method
   # 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() click to toggle source

Show that this is an SQLTime, and the time represented

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

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

Calls superclass method
   # 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