Project

General

Profile

Feature #10459 ยป rfc3339.patch

Antiarchitect (Andrey Voronkov), 10/30/2014 11:09 AM

View differences:

lib/time.rb (working copy)
28 28
# === Converting to a String
29 29
#
30 30
#   t = Time.now
31
#   t.iso8601  # => "2011-10-05T22:26:12-04:00"
32
#   t.rfc2822  # => "Wed, 05 Oct 2011 22:26:12 -0400"
33
#   t.httpdate # => "Thu, 06 Oct 2011 02:26:12 GMT"
31
#   t.rfc3339(9)  # => "2011-10-05T22:26:12.996992609-04:00"
32
#   t.rfc3339     # => "2011-10-05T22:26:12-04:00"
33
#   t.iso8601(9)  # => "2011-10-05T22:26:12.996992609-04:00"
34
#   t.iso8601     # => "2011-10-05T22:26:12-04:00"
35
#   t.rfc2822     # => "Wed, 05 Oct 2011 22:26:12 -0400"
36
#   t.httpdate    # => "Thu, 06 Oct 2011 02:26:12 GMT"
34 37
#
35 38
# === Time.parse
36 39
#
......
591 594
      end
592 595
    end
593 596
    alias iso8601 xmlschema
597
    alias rfc3339 xmlschema
594 598
  end # class << self
595 599

  
596 600
  #
test/test_time.rb (working copy)
98 98
  def test_rfc3339
99 99
    t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
100 100
    s = "1985-04-12T23:20:50.52Z"
101
    assert_equal(t, Time.iso8601(s))
102
    assert_equal(s, t.iso8601(2))
101
    assert_equal(t, Time.rfc3339(s))
102
    assert_equal(s, t.rfc3339(2))
103 103

  
104 104
    t = Time.utc(1996, 12, 20, 0, 39, 57)
105 105
    s = "1996-12-19T16:39:57-08:00"
106
    assert_equal(t, Time.iso8601(s))
106
    assert_equal(t, Time.rfc3339(s))
107 107
    # There is no way to generate time string with arbitrary timezone.
108 108
    s = "1996-12-20T00:39:57Z"
109
    assert_equal(t, Time.iso8601(s))
110
    assert_equal(s, t.iso8601)
109
    assert_equal(t, Time.rfc3339(s))
110
    assert_equal(s, t.rfc3339)
111 111

  
112 112
    t = Time.utc(1990, 12, 31, 23, 59, 60)
113 113
    s = "1990-12-31T23:59:60Z"
114
    assert_equal(t, Time.iso8601(s))
114
    assert_equal(t, Time.rfc3339(s))
115 115
    # leap second is representable only if timezone file has it.
116 116
    s = "1990-12-31T15:59:60-08:00"
117
    assert_equal(t, Time.iso8601(s))
117
    assert_equal(t, Time.rfc3339(s))
118 118

  
119 119
    begin
120 120
      Time.at(-1)
......
123 123
    else
124 124
      t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
125 125
      s = "1937-01-01T12:00:27.87+00:20"
126
      assert_equal(t, Time.iso8601(s))
126
      assert_equal(t, Time.rfc3339(s))
127 127
    end
128 128
  end