Class: DBI::Timestamp
- Inherits:
-
Object
- Object
- DBI::Timestamp
- Defined in:
- lib/dbi/utils/timestamp.rb
Overview
Represents a Timestamp.
DEPRECATED: Please use a regular DateTime object.
Instance Attribute Summary collapse
-
#day ⇒ Object
(also: #mday)
Returns the value of attribute day.
-
#fraction ⇒ Object
Returns fractional seconds, or 0 if not set.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#minute ⇒ Object
(also: #min)
Returns the value of attribute minute.
-
#month ⇒ Object
(also: #mon)
Returns the value of attribute month.
-
#second ⇒ Object
(also: #sec)
Returns the value of attribute second.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
-
#==(timestamp) ⇒ Object
Returns true if
timestamp
has a year, month, day, hour, minute, second and fraction equal to the comparing object. -
#to_date ⇒ Object
Returns a new Date object based on the year, month and day or, if a Date object was passed to the constructor, returns that object.
-
#to_s ⇒ Object
Returns a DBI::Timestamp object as a string in YYYY-MM-DD HH:MM:SS format.
-
#to_time ⇒ Object
Returns a new Time object based on the year, month and day or, if a Time object was passed to the constructor, returns that object.
Instance Attribute Details
#day ⇒ Object Also known as: mday
Returns the value of attribute day.
8 9 10 |
# File 'lib/dbi/utils/timestamp.rb', line 8 def day @day end |
#fraction ⇒ Object
Returns fractional seconds, or 0 if not set.
55 56 57 |
# File 'lib/dbi/utils/timestamp.rb', line 55 def fraction @fraction || 0 end |
#hour ⇒ Object
Returns the value of attribute hour.
9 10 11 |
# File 'lib/dbi/utils/timestamp.rb', line 9 def hour @hour end |
#minute ⇒ Object Also known as: min
Returns the value of attribute minute.
9 10 11 |
# File 'lib/dbi/utils/timestamp.rb', line 9 def minute @minute end |
#month ⇒ Object Also known as: mon
Returns the value of attribute month.
8 9 10 |
# File 'lib/dbi/utils/timestamp.rb', line 8 def month @month end |
#second ⇒ Object Also known as: sec
Returns the value of attribute second.
9 10 11 |
# File 'lib/dbi/utils/timestamp.rb', line 9 def second @second end |
#year ⇒ Object
Returns the value of attribute year.
8 9 10 |
# File 'lib/dbi/utils/timestamp.rb', line 8 def year @year end |
Instance Method Details
#==(timestamp) ⇒ Object
Returns true if timestamp
has a year, month, day, hour, minute, second and fraction equal to the comparing object.
Returns false if the comparison fails for any reason.
45 46 47 48 49 50 51 52 |
# File 'lib/dbi/utils/timestamp.rb', line 45 def ==() @year == .year and @month == .month and @day == .day and @hour == .hour and @minute == .minute and @second == .second and (fraction() == .fraction) rescue false end |
#to_date ⇒ Object
Returns a new Date object based on the year, month and day or, if a Date object was passed to the constructor, returns that object.
92 93 94 |
# File 'lib/dbi/utils/timestamp.rb', line 92 def to_date @original_date || ::Date.new(@year, @month, @day) end |
#to_s ⇒ Object
Returns a DBI::Timestamp object as a string in YYYY-MM-DD HH:MM:SS format. If a fraction is present, then it is appended in “.FF” format.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dbi/utils/timestamp.rb', line 71 def to_s string = sprintf("%04d-%02d-%02d %02d:%02d:%02d", @year, @month, @day, @hour, @minute, @second) if @fraction fraction = ("%.9f" % (@fraction.to_i / 1e9)). to_s[1..-1].gsub(/0{1,8}$/, "") string += fraction end string end |
#to_time ⇒ Object
Returns a new Time object based on the year, month and day or, if a Time object was passed to the constructor, returns that object.
86 87 88 |
# File 'lib/dbi/utils/timestamp.rb', line 86 def to_time @original_time || ::Time.local(@year, @month, @day, @hour, @minute, @second) end |