diff options
Diffstat (limited to 'spec/ruby/core/time/iso8601_spec.rb')
| -rw-r--r-- | spec/ruby/core/time/iso8601_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/ruby/core/time/iso8601_spec.rb b/spec/ruby/core/time/iso8601_spec.rb new file mode 100644 index 0000000000..a6efc57b28 --- /dev/null +++ b/spec/ruby/core/time/iso8601_spec.rb @@ -0,0 +1,33 @@ +require_relative '../../spec_helper' + +describe "Time#iso8601" do + ruby_version_is "3.4" do + it "generates ISO-8601 strings in Z for UTC times" do + t = Time.utc(1985, 4, 12, 23, 20, 50, 521245) + t.iso8601.should == "1985-04-12T23:20:50Z" + t.iso8601(2).should == "1985-04-12T23:20:50.52Z" + t.iso8601(9).should == "1985-04-12T23:20:50.521245000Z" + end + + it "generates ISO-8601 string with timezone offset for non-UTC times" do + t = Time.new(1985, 4, 12, 23, 20, 50, "+02:00") + t.iso8601.should == "1985-04-12T23:20:50+02:00" + t.iso8601(2).should == "1985-04-12T23:20:50.00+02:00" + end + + it "year is always at least 4 digits" do + t = Time.utc(12, 4, 12) + t.iso8601.should == "0012-04-12T00:00:00Z" + end + + it "year can be more than 4 digits" do + t = Time.utc(40_000, 4, 12) + t.iso8601.should == "40000-04-12T00:00:00Z" + end + + it "year can be negative" do + t = Time.utc(-2000, 4, 12) + t.iso8601.should == "-2000-04-12T00:00:00Z" + end + end +end |
