File: now_spec.rb

package info (click to toggle)
ruby3.4 3.4.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 154,784 kB
  • sloc: ruby: 1,259,653; ansic: 829,955; yacc: 28,233; pascal: 7,359; sh: 3,864; python: 1,799; cpp: 1,158; asm: 808; makefile: 801; javascript: 414; lisp: 109; perl: 62; awk: 36; sed: 4; xml: 4
file content (57 lines) | stat: -rw-r--r-- 1,638 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
require_relative '../../spec_helper'
require_relative 'shared/now'

describe "Time.now" do
  it_behaves_like :time_now, :now

  ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/17485
    describe ":in keyword argument" do
      it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do
        time = Time.now(in: "+05:00")

        time.utc_offset.should == 5*60*60
        time.zone.should == nil

        time = Time.now(in: "-09:00")

        time.utc_offset.should == -9*60*60
        time.zone.should == nil
      end

      it "could be UTC offset as a number of seconds" do
        time = Time.now(in: 5*60*60)

        time.utc_offset.should == 5*60*60
        time.zone.should == nil

        time = Time.now(in: -9*60*60)

        time.utc_offset.should == -9*60*60
        time.zone.should == nil
      end

      it "returns a Time with UTC offset specified as a single letter military timezone" do
        Time.now(in: "W").utc_offset.should == 3600 * -10
      end

      it "could be a timezone object" do
        zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
        time = Time.now(in: zone)

        time.utc_offset.should == 5*3600+30*60
        time.zone.should == zone

        zone = TimeSpecs::TimezoneWithName.new(name: "PST")
        time = Time.now(in: zone)

        time.utc_offset.should == -9*60*60
        time.zone.should == zone
      end

      it "raises ArgumentError if format is invalid" do
        -> { Time.now(in: "+09:99") }.should raise_error(ArgumentError)
        -> { Time.now(in: "ABC") }.should raise_error(ArgumentError)
      end
    end
  end
end