File: time_spec.rb

package info (click to toggle)
ruby-extlib 0.9.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 576 kB
  • sloc: ruby: 7,014; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'spec_helper'
require 'extlib/time'

require 'json'

describe Time, "#to_json" do

  before do
    @expected = "\"2008-03-28T22:54:20Z\""
  end

  it "should transform itself into a ISO 8601 compatible string" do
    Time.utc(2008, 3, 28, 22, 54, 20).to_json.should == @expected
    Time.xmlschema("2008-03-28T22:54:20Z").to_json.should == @expected
    Time.xmlschema("2008-03-28T17:54:20-05:00").to_json.should == @expected
  end
end

describe Time, "#to_time" do
  it "should return a copy of its self" do
    time = Time.now
    time.to_time.should == time
  end
end

describe Time, "#to_datetime" do
  it "should return an equivalent DateTime" do
    time = Time.now
    time.to_datetime.should == DateTime.parse(time.to_s)
  end
end