struct Clear::TimeInDay
- Clear::TimeInDay
- Struct
- Value
- Object
Overview
Clear::TimeInDay
represents the "time" object of PostgreSQL
It can be converted automatically from/to a time
column.
It offers helpers which makes it usable also as a stand alone.
Usage example
time = Clear::TimeInDay.parse("12:33")
puts time.hour # 12
puts time.minutes # 0
Time.local.at(time) # Today at 12:33:00
time.to_s # 12:33:00
time.to_s(false) # don't show seconds => 12:33
time = time + 2.minutes # 12:35
As with Interval, you might wanna use it as a column (use underlying time
type in PostgreSQL):
class MyModel
include Clear::Model
column i : Clear::TimeInDay
end
Defined in:
clear/extensions/time/time_in_day.crConstructors
Class Method Summary
-
.parse(str : String)
Parse a string, of format HH:MM or HH:MM:SS
Instance Method Summary
- #+(t : Time::Span)
- #+(x : self)
- #-(t : Time::Span)
- #hour
-
#inspect
Returns a
String
representation of this object suitable to be embedded inside other expressions, sometimes providing more information about this object. - #microseconds : UInt64
- #minutes
- #seconds
-
#to_s(show_seconds : Bool = true)
Returns a string representation of this object.
-
#to_s(io, show_seconds : Bool = true)
Return a string
- #to_tuple
- #total_seconds
Constructor Detail
Class Method Detail
Instance Method Detail
Returns a String
representation of this object suitable
to be embedded inside other expressions, sometimes providing
more information about this object.
#inspect
(and #inspect(io)
) are the methods used when
you invoke #to_s
or #inspect
on an object that holds
other objects and wants to show them. For example when you
invoke Array#to_s
, #inspect
will be invoked on each element:
ary = ["one", "two", "three, etc."]
ary.inspect # => ["one", "two", "three, etc."]
Note that if Array invoked #to_s
on each of the elements
above, the output would have been this:
ary = ["one", "two", "three, etc."]
# If inspect invoked to_s on each element...
ary.inspect # => [one, two, three, etc.]
Note that it's not clear how many elements the array has,
or which are they, because #to_s
doesn't guarantee that
the string representation is clearly delimited (in the case
of String
the quotes are not shown).
Also note that sometimes the output of #inspect
will look
like a Crystal expression that will compile, but this isn't
always the case, nor is it necessary. Notably, Reference#inspect
and Struct#inspect
return values that don't compile.
Classes must usually not override this method. Instead,
they must override inspect(io)
, which must append to the
given IO
object.