mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
added integer input/output support to
Redistat::Date so Unix timestamps can be used directly
This commit is contained in:
@@ -15,6 +15,8 @@ module Redistat
|
||||
from_date(input)
|
||||
elsif input.is_a?(::String)
|
||||
from_string(input)
|
||||
elsif input.is_a?(::Fixnum)
|
||||
from_integer(input)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,6 +27,10 @@ module Redistat
|
||||
def to_date
|
||||
::Date.civil(@year, @month, @day)
|
||||
end
|
||||
|
||||
def to_integer
|
||||
to_time.to_i
|
||||
end
|
||||
|
||||
def to_string(depth = :sec)
|
||||
output = ""
|
||||
@@ -38,6 +44,7 @@ module Redistat
|
||||
|
||||
alias :to_t :to_time
|
||||
alias :to_d :to_date
|
||||
alias :to_i :to_integer
|
||||
alias :to_s :to_string
|
||||
|
||||
|
||||
@@ -58,6 +65,10 @@ module Redistat
|
||||
end
|
||||
end
|
||||
|
||||
def from_integer(input)
|
||||
from_time(::Time.at(input))
|
||||
end
|
||||
|
||||
def from_string(input)
|
||||
from_time(::Time.parse(input))
|
||||
end
|
||||
@@ -78,4 +89,11 @@ class Time
|
||||
Redistat::Date.new(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
|
||||
class Fixnum
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
Reference in New Issue
Block a user