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.



12
13
14
# File 'lib/dbi/utils/date.rb', line 12

def day
  @day
end

#monthObject 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

#yearObject

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



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

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.



33
34
35
# File 'lib/dbi/utils/date.rb', line 33

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.



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