mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
added some more helpers to Date, Time and Fixnum
classes
This commit is contained in:
@@ -82,26 +82,30 @@ module Redistat
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module DateHelper
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Date
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
include Redistat::DateHelper
|
||||
def to_time
|
||||
Time.parse(self.to_s)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
|
||||
class Time
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
include Redistat::DateHelper
|
||||
end
|
||||
|
||||
class Fixnum
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
include Redistat::DateHelper
|
||||
def to_time
|
||||
Time.at(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
@@ -64,4 +64,10 @@ describe Redistat::Date do
|
||||
end
|
||||
end
|
||||
|
||||
it "should add helper methods to Date, Time and Fixnum classes" do
|
||||
Date.today.to_time.should == Time.parse(Date.today.to_s)
|
||||
Time.now.to_i.to_time.should == Time.at(Time.now.to_i)
|
||||
Date.today.to_rs.to_date.should == Date.today
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user