diff --git a/lib/redistat/date.rb b/lib/redistat/date.rb index e4f7a9b..48fb65e 100644 --- a/lib/redistat/date.rb +++ b/lib/redistat/date.rb @@ -78,6 +78,7 @@ module Redistat end def from_string(input) + input += "19700101000000"[input.size..-1] if input =~ /^\d\d\d[\d]+$/i from_time(::Time.parse(input)) end diff --git a/spec/date_spec.rb b/spec/date_spec.rb index 9c5955f..143481f 100644 --- a/spec/date_spec.rb +++ b/spec/date_spec.rb @@ -31,6 +31,14 @@ describe Redistat::Date do [:year, :month, :day, :hour, :min, :sec].each { |k| rdate.send(k).should == now.send(k) } end + it "should initialize from Redistat date String" do + now = Time.now + rdate = Redistat::Date.new(now.to_s) + [:year, :month, :day, :hour, :min, :sec].each { |k| + rdate.to_s(k).should == Redistat::Date.new(rdate.to_s(k)).to_s(k) + } + end + it "should convert to Time object" do now = Time.now rdate = Redistat::Date.new(now)