Class DBI::Date
In: lib/dbi/utils/date.rb
Parent: Object

Represents a Date.

DEPRECATED: Please use a regular Date or DateTime object.

Methods

new   to_date   to_s   to_time  

External Aliases

month -> mon
  Aliases
month= -> mon=
day -> mday
day= -> mday=

Attributes

day  [RW] 
month  [RW] 
year  [RW] 

Public Class methods

DBI::Date.new(year = 0, month = 0, day = 0) DBI::Date.new(Date) DBI::Date.new(Time)

Creates and returns a new DBI::Date object. It‘s similar to the standard Date class’ constructor except that it also accepts a Date or Time object.

[Source]

    # File lib/dbi/utils/date.rb, line 42
42:         def initialize(year=0, month=0, day=0)
43:             case year
44:             when ::Date
45:                 @year, @month, @day = year.year, year.month, year.day 
46:                 @original_date = year
47:             when ::Time
48:                 @year, @month, @day = year.year, year.month, year.day 
49:                 @original_time = year
50:             else
51:                 @year, @month, @day = year, month, day
52:             end
53:         end

Public Instance methods

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.

[Source]

    # File lib/dbi/utils/date.rb, line 24
24:         def to_date
25:             @original_date || ::Date.new(@year, @month, @day)
26:         end

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

[Source]

    # File lib/dbi/utils/date.rb, line 29
29:         def to_s
30:             sprintf("%04d-%02d-%02d", @year, @month, @day)
31:         end

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.

[Source]

    # File lib/dbi/utils/date.rb, line 18
18:         def to_time
19:             @original_time || ::Time.local(@year, @month, @day, 0, 0, 0)
20:         end

[Validate]