File: utc_spec.rb

package info (click to toggle)
jruby 9.4.8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 89,244 kB
  • sloc: ruby: 548,574; java: 276,189; yacc: 25,873; ansic: 6,178; xml: 6,111; sh: 1,855; sed: 94; makefile: 78; jsp: 48; tcl: 40; exp: 12
file content (68 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require_relative '../../spec_helper'
require_relative 'shared/gm'
require_relative 'shared/gmtime'
require_relative 'shared/time_params'

describe "Time#utc?" do
  it "returns true only if time represents a time in UTC (GMT)" do
    Time.now.utc?.should == false
    Time.now.utc.utc?.should == true
  end

  it "treats time as UTC what was created in different ways" do
    Time.now.utc.utc?.should == true
    Time.now.gmtime.utc?.should == true
    Time.now.getgm.utc?.should == true
    Time.now.getutc.utc?.should == true
    Time.utc(2022).utc?.should == true
  end

  it "does treat time with 'UTC' offset as UTC" do
    Time.new(2022, 1, 1, 0, 0, 0, "UTC").utc?.should == true
    Time.now.localtime("UTC").utc?.should == true
    Time.at(Time.now, in: 'UTC').utc?.should == true

    ruby_version_is "3.1" do
      Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").utc?.should == true
      Time.now(in: "UTC").utc?.should == true
    end
  end

  it "does treat time with Z offset as UTC" do
    Time.new(2022, 1, 1, 0, 0, 0, "Z").utc?.should == true
    Time.now.localtime("Z").utc?.should == true
    Time.at(Time.now, in: 'Z').utc?.should == true

    ruby_version_is "3.1" do
      Time.new(2022, 1, 1, 0, 0, 0, in: "Z").utc?.should == true
      Time.now(in: "Z").utc?.should == true
    end
  end

  ruby_version_is "3.1" do
    it "does treat time with -00:00 offset as UTC" do
      Time.new(2022, 1, 1, 0, 0, 0, "-00:00").utc?.should == true
      Time.now.localtime("-00:00").utc?.should == true
      Time.at(Time.now, in: '-00:00').utc?.should == true
    end
  end

  it "does not treat time with +00:00 offset as UTC" do
    Time.new(2022, 1, 1, 0, 0, 0, "+00:00").utc?.should == false
  end

  it "does not treat time with 0 offset as UTC" do
    Time.new(2022, 1, 1, 0, 0, 0, 0).utc?.should == false
  end
end

describe "Time.utc" do
  it_behaves_like :time_gm, :utc
  it_behaves_like :time_params, :utc
  it_behaves_like :time_params_10_arg, :utc
  it_behaves_like :time_params_microseconds, :utc
end

describe "Time#utc" do
  it_behaves_like :time_gmtime, :utc
end