|
From: Michael N. <mne...@us...> - 2002-07-26 17:51:36
|
Update of /cvsroot/ruby-dbi/src/lib/dbi
In directory usw-pr-cvs1:/tmp/cvs-serv1326
Modified Files:
dbi.rb
Log Message:
added methods Timestamp#to_time/to_date (Dave Thomas)
Index: dbi.rb
===================================================================
RCS file: /cvsroot/ruby-dbi/src/lib/dbi/dbi.rb,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- dbi.rb 3 Jul 2002 19:24:25 -0000 1.31
+++ dbi.rb 26 Jul 2002 17:51:31 -0000 1.32
@@ -263,7 +263,6 @@
def sec() @second end
def sec=(val) @second=val end
-
def to_s
"#{@hour}:#{@minute}:#{@second}"
end
@@ -277,9 +276,11 @@
if year.is_a? ::Time
@year, @month, @day = year.year, year.month, year.day
@hour, @minute, @second, @fraction = year.hour, year.min, year.sec, 0
+ @original_time = year
elsif year.is_a? ::Date
@year, @month, @day = year.year, year.month, year.day
@hour, @minute, @second, @fraction = 0, 0, 0, 0
+ @original_date = year
else
@year, @month, @day = year, month, day
@hour, @minute, @second, @fraction = hour, minute, second, fraction
@@ -297,8 +298,21 @@
"#{@year}-#{@month}-#{@day} #{@hour}:#{@minute}:#{@second}.#{@fraction}"
end
- # TODO: conversion functions to_date and to_time, perhaps to_date2
- # (date2/3.rb)
+ def to_time
+ if @original_time
+ @original_time
+ else
+ Time.local(@year, @month, @day, @hour, @minute, @second)
+ end
+ end
+
+ def to_date
+ if @original_date
+ @original_date
+ else
+ Date.new(@year, @month, @day)
+ end
+ end
end
|