Sha256: 03b464479f0284ab9c948e2a5e9048a9a787308d0c443a2c4db6b18369adbef3

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

describe "Time" do
  describe "conversions" do
    describe "to_formatted_s" do
      before do
        @time = Time.utc(2005, 2, 21, 17, 44, 30.12345678901)
      end
      
      it "should use default conversion if no parameter is given" do
        @time.to_s.should == @time.to_default_s
      end
      
      it "should use default conversion if parameter is unknown" do
        @time.to_s(:doesnt_exist).should == @time.to_default_s
      end
      
      it "should convert to db format" do
        @time.to_s(:db).should == "2005-02-21 17:44:30"
      end
      
      it "should convert to short format" do
        @time.to_s(:short).should == "21 Feb 17:44"
      end
      
      it "should convert to time format" do
        @time.to_s(:time).should == "17:44"
      end
      
      it "should convert to number format" do
        @time.to_s(:number).should == "20050221174430"
      end
      
      it "should convert to nsec format" do
        @time.to_s(:nsec).should == "20050221174430123451232"
        # Hmm. Looks like RubyMotion has an issue with nanosecs in string time formatting. It should actually be "20050221174430123456789"
      end
      
      it "should convert to long format" do
        @time.to_s(:long).should == "February 21, 2005 17:44"
      end
      
      it "should convert to long_ordinal format" do
        @time.to_s(:long_ordinal).should == "February 21st, 2005 17:44"
      end
    end
    
    describe "custom date format" do
      it "should convert to custom format" do
        Time::DATE_FORMATS[:custom] = '%Y%m%d%H%M%S'
        Time.local(2005, 2, 21, 14, 30, 0).to_s(:custom).should == '20050221143000'
        Time::DATE_FORMATS.delete(:custom)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
motion-support-0.3.0 spec/motion-support/core_ext/time/conversion_spec.rb
motion-support-0.2.6 spec/motion-support/core_ext/time/conversion_spec.rb
motion-support-0.2.5 spec/motion-support/core_ext/time/conversion_spec.rb