Sha256: 4ef0a46c0f544dd4b6ba8839ea870d2c2867e496d10dc319e88bd50570be25b1

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
include TwitterCldr

describe DateTime do
  describe "#localize" do
    it "should localize with the given locale, English by default" do
      date = DateTime.now
      loc_date = date.localize
      loc_date.should be_a(LocalizedDateTime)
      loc_date.locale.should == :en
      loc_date.base_obj.should == date

      loc_date = DateTime.now.localize(:it)
      loc_date.should be_a(LocalizedDateTime)
      loc_date.locale.should == :it
    end
  end
end

describe LocalizedDateTime do
  context "with an unsupported type" do
    it "raise an error because 'albatross' is not a supported type" do
      date_time = DateTime.now.localize(:it)
      lambda { date_time.to_albatross_s }.should raise_error("Method not supported")
    end
  end

  describe "#to_date" do
    it "should convert to a date" do
      date = DateTime.new(1987, 9, 20, 22, 5).localize.to_date
      date.should be_a(LocalizedDate)
      date.base_obj.strftime("%Y-%m-%d").should == "1987-09-20"
    end
  end

  describe "#to_time" do
    it "should convert to a time" do
      time = DateTime.new(1987, 9, 20, 22, 5).localize.to_time
      time.should be_a(LocalizedTime)
      time.base_obj.getgm.strftime("%H:%M:%S").should == "22:05:00"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.0.0 spec/ext/calendars/datetime_spec.rb