Class: DBI::Date
- Inherits:
-
Object
- Object
- DBI::Date
- Defined in:
- lib/dbi/utils/date.rb
Overview
Represents a Date.
DEPRECATED: Please use a regular Date or DateTime object.
Instance Attribute Summary collapse
-
#day ⇒ Object
(also: #mday)
Returns the value of attribute day.
-
#month ⇒ Object
(also: #mon)
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
-
#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::Date object as a string in YYYY-MM-DD 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.
12 13 14 |
# File 'lib/dbi/utils/date.rb', line 12 def day @day end |
#month ⇒ Object Also known as: mon
Returns the value of attribute month.
12 13 14 |
# File 'lib/dbi/utils/date.rb', line 12 def month @month end |
#year ⇒ Object
Returns the value of attribute year.
12 13 14 |
# File 'lib/dbi/utils/date.rb', line 12 def year @year end |
Instance Method Details
#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.
28 29 30 |
# File 'lib/dbi/utils/date.rb', line 28 def to_date @original_date || ::Date.new(@year, @month, @day) end |
#to_s ⇒ Object
Returns a DBI::Date object as a string in YYYY-MM-DD format.
33 34 35 |
# File 'lib/dbi/utils/date.rb', line 33 def to_s sprintf("%04d-%02d-%02d", @year, @month, @day) 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.
22 23 24 |
# File 'lib/dbi/utils/date.rb', line 22 def to_time @original_time || ::Time.local(@year, @month, @day, 0, 0, 0) end |