struct Clear::TimeInDay

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(hours, minutes, seconds = 0) #

[View source]
def self.new(microseconds : UInt64 = 0) #

[View source]

Class Method Detail

def self.parse(str : String) #

Parse a string, of format HH:MM or HH:MM:SS


[View source]

Instance Method Detail

def +(t : Time::Span) #

[View source]
def +(x : self) #

[View source]
def -(t : Time::Span) #

[View source]
def hour #

[View source]
def inspect #
Description copied from class Object

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.


[View source]
def microseconds : UInt64 #

[View source]
def minutes #

[View source]
def seconds #

[View source]
def to_s(show_seconds : Bool = true) #
Description copied from class Object

Returns a string representation of this object.

Descendants must usually not override this method. Instead, they must override #to_s(io), which must append to the given IO object.


[View source]
def to_s(io, show_seconds : Bool = true) #

Return a string


[View source]
def to_tuple #

[View source]
def total_seconds #

[View source]