Class: Sequel::SQLTime
Overview
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.
Class Attribute Summary collapse
-
.date ⇒ Object
Use the date explicitly set, or the current date if there is not a date set.
Class Method Summary collapse
-
.create(hour, minute, second, usec = 0) ⇒ Object
Create a new SQLTime instance given an hour, minute, second, and usec.
-
.parse ⇒ Object
Set the correct date and timezone when parsing times.
Instance Method Summary collapse
-
#inspect ⇒ Object
Show that this is an SQLTime, and the time represented.
-
#to_s(*args) ⇒ Object
Return a string in HH:MM:SS format representing the time.
Class Attribute Details
.date ⇒ Object
Use the date explicitly set, or the current date if there is not a date set.
32 33 34 |
# File 'lib/sequel/sql.rb', line 32 def date @date || now end |
Class Method Details
.create(hour, minute, second, usec = 0) ⇒ Object
Create a new SQLTime instance given an hour, minute, second, and usec.
52 53 54 55 56 |
# File 'lib/sequel/sql.rb', line 52 def create(hour, minute, second, usec = 0) t = date meth = Sequel.application_timezone == :utc ? :utc : :local public_send(meth, t.year, t.month, t.day, hour, minute, second, usec) end |
.parse ⇒ Object
Set the correct date and timezone when parsing times.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sequel/sql.rb', line 37 def parse(*) t = super utc = Sequel.application_timezone == :utc d = @date if d || utc meth = utc ? :utc : :local d ||= t t = public_send(meth, d.year, d.month, d.day, t.hour, t.min, t.sec, t.usec) end t end |
Instance Method Details
#inspect ⇒ Object
Show that this is an SQLTime, and the time represented
60 61 62 |
# File 'lib/sequel/sql.rb', line 60 def inspect "#<#{self.class} #{to_s}>" end |
#to_s(*args) ⇒ Object
Return a string in HH:MM:SS format representing the time.
65 66 67 68 69 70 71 72 73 |
# File 'lib/sequel/sql.rb', line 65 def to_s(*args) if args.empty? strftime('%H:%M:%S') else # Superclass may have defined a method that takes a format string, # and we shouldn't override in that case. super end end |