| Class | DBI::Timestamp |
| In: |
lib/dbi/utils/timestamp.rb
|
| Parent: | Object |
Represents a Timestamp.
DEPRECATED: Please use a regular DateTime object.
| month | -> | mon |
| Aliases | ||
| month= | -> | mon= |
| day | -> | mday |
| day= | -> | mday= |
| minute | -> | min |
| minute= | -> | min= |
| second | -> | sec |
| second= | -> | sec= |
| day | [RW] | |
| fraction | [W] | |
| hour | [RW] | |
| minute | [RW] | |
| month | [RW] | |
| second | [RW] | |
| year | [RW] |
DBI::Timestamp(year=0,month=0,day=0,hour=0,min=0,sec=0,fraction=nil) DBI::Timestamp(Time) DBI::Timestamp(Date)
Creates and returns a new DBI::Timestamp object. This is similar to a Time object in the standard library, but it also contains fractional seconds, expressed in nanoseconds. In addition, the constructor accepts either a Date or Time object.
# File lib/dbi/utils/timestamp.rb, line 21
21: def initialize(year=0, month=0, day=0, hour=0, min=0, sec=0, fraction=nil)
22: case year
23: when ::Time
24: @year, @month, @day = year.year, year.month, year.day
25: @hour, @minute, @second, @fraction = year.hour, year.min, year.sec, nil
26: @original_time = year
27: when ::Date
28: @year, @month, @day = year.year, year.month, year.day
29: @hour, @minute, @second, @fraction = 0, 0, 0, nil
30: @original_date = year
31: else
32: @year, @month, @day = year, month, day
33: @hour, @minute, @second, @fraction = hour, min, sec, fraction
34: end
35: end
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.
# File lib/dbi/utils/timestamp.rb, line 45
45: def ==(timestamp)
46: @year == timestamp.year and @month == timestamp.month and
47: @day == timestamp.day and @hour == timestamp.hour and
48: @minute == timestamp.minute and @second == timestamp.second and
49: (fraction() == timestamp.fraction)
50: rescue
51: false
52: end
Returns fractional seconds, or 0 if not set.
# File lib/dbi/utils/timestamp.rb, line 55
55: def fraction
56: @fraction || 0
57: end
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.
# File lib/dbi/utils/timestamp.rb, line 71
71: def to_s
72: string = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
73: @year, @month, @day, @hour, @minute, @second)
74:
75: if @fraction
76: fraction = ("%.9f" % (@fraction.to_i / 1e9)).
77: to_s[1..-1].gsub(/0{1,8}$/, "")
78: string += fraction
79: end
80:
81: string
82: end