Class: DBI::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/dbi/utils/date.rb

Overview

Represents a Date.

DEPRECATED: Please use a regular Date or DateTime object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dayObject Also known as: mday

Returns the value of attribute day.



8
9
10
# File 'lib/dbi/utils/date.rb', line 8

def day
  @day
end

#monthObject Also known as: mon

Returns the value of attribute month.



8
9
10
# File 'lib/dbi/utils/date.rb', line 8

def month
  @month
end

#yearObject

Returns the value of attribute year.



8
9
10
# File 'lib/dbi/utils/date.rb', line 8

def year
  @year
end

Instance Method Details

#to_dateObject

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.



24
25
26
# File 'lib/dbi/utils/date.rb', line 24

def to_date
    @original_date || ::Date.new(@year, @month, @day)
end

#to_sObject

Returns a DBI::Date object as a string in YYYY-MM-DD format.



29
30
31
# File 'lib/dbi/utils/date.rb', line 29

def to_s
    sprintf("%04d-%02d-%02d", @year, @month, @day)
end

#to_timeObject

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.



18
19
20
# File 'lib/dbi/utils/date.rb', line 18

def to_time
    @original_time || ::Time.local(@year, @month, @day, 0, 0, 0)
end