tzinfo 1.2.6 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -1
- data/.yardopts +3 -0
- data/CHANGES.md +482 -380
- data/LICENSE +12 -12
- data/README.md +368 -114
- data/lib/tzinfo.rb +64 -29
- data/lib/tzinfo/country.rb +141 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +389 -144
- data/lib/tzinfo/data_sources.rb +8 -0
- data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
- data/lib/tzinfo/data_sources/country_info.rb +42 -0
- data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
- data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +143 -0
- data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
- data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
- data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +575 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +286 -0
- data/lib/tzinfo/data_timezone.rb +33 -47
- data/lib/tzinfo/datetime_with_offset.rb +153 -0
- data/lib/tzinfo/format1.rb +10 -0
- data/lib/tzinfo/format1/country_definer.rb +17 -0
- data/lib/tzinfo/format1/country_index_definition.rb +64 -0
- data/lib/tzinfo/format1/timezone_definer.rb +64 -0
- data/lib/tzinfo/format1/timezone_definition.rb +39 -0
- data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
- data/lib/tzinfo/format2.rb +10 -0
- data/lib/tzinfo/format2/country_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definition.rb +46 -0
- data/lib/tzinfo/format2/timezone_definer.rb +94 -0
- data/lib/tzinfo/format2/timezone_definition.rb +73 -0
- data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
- data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
- data/lib/tzinfo/info_timezone.rb +26 -21
- data/lib/tzinfo/linked_timezone.rb +33 -52
- data/lib/tzinfo/offset_timezone_period.rb +42 -0
- data/lib/tzinfo/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +128 -0
- data/lib/tzinfo/timestamp.rb +548 -0
- data/lib/tzinfo/timestamp_with_offset.rb +85 -0
- data/lib/tzinfo/timezone.rb +989 -502
- data/lib/tzinfo/timezone_offset.rb +84 -74
- data/lib/tzinfo/timezone_period.rb +151 -217
- data/lib/tzinfo/timezone_proxy.rb +70 -79
- data/lib/tzinfo/timezone_transition.rb +77 -109
- data/lib/tzinfo/transitions_timezone_period.rb +63 -0
- data/lib/tzinfo/untaint_ext.rb +18 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- metadata +43 -99
- metadata.gz.sig +0 -0
- data/Rakefile +0 -107
- data/lib/tzinfo/country_index_definition.rb +0 -31
- data/lib/tzinfo/country_info.rb +0 -42
- data/lib/tzinfo/data_timezone_info.rb +0 -55
- data/lib/tzinfo/linked_timezone_info.rb +0 -26
- data/lib/tzinfo/offset_rationals.rb +0 -77
- data/lib/tzinfo/ruby_core_support.rb +0 -176
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -138
- data/lib/tzinfo/time_or_datetime.rb +0 -340
- data/lib/tzinfo/timezone_definition.rb +0 -36
- data/lib/tzinfo/timezone_index_definition.rb +0 -54
- data/lib/tzinfo/timezone_info.rb +0 -30
- data/lib/tzinfo/timezone_transition_definition.rb +0 -104
- data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
- data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
- data/lib/tzinfo/zoneinfo_data_source.rb +0 -496
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -298
- data/test/tc_country.rb +0 -236
- data/test/tc_country_index_definition.rb +0 -69
- data/test/tc_country_info.rb +0 -16
- data/test/tc_country_timezone.rb +0 -173
- data/test/tc_data_source.rb +0 -218
- data/test/tc_data_timezone.rb +0 -99
- data/test/tc_data_timezone_info.rb +0 -18
- data/test/tc_info_timezone.rb +0 -34
- data/test/tc_linked_timezone.rb +0 -155
- data/test/tc_linked_timezone_info.rb +0 -23
- data/test/tc_offset_rationals.rb +0 -23
- data/test/tc_ruby_core_support.rb +0 -168
- data/test/tc_ruby_country_info.rb +0 -110
- data/test/tc_ruby_data_source.rb +0 -165
- data/test/tc_time_or_datetime.rb +0 -660
- data/test/tc_timezone.rb +0 -1359
- data/test/tc_timezone_definition.rb +0 -113
- data/test/tc_timezone_index_definition.rb +0 -73
- data/test/tc_timezone_info.rb +0 -11
- data/test/tc_timezone_london.rb +0 -143
- data/test/tc_timezone_melbourne.rb +0 -142
- data/test/tc_timezone_new_york.rb +0 -142
- data/test/tc_timezone_offset.rb +0 -126
- data/test/tc_timezone_period.rb +0 -555
- data/test/tc_timezone_proxy.rb +0 -136
- data/test/tc_timezone_transition.rb +0 -366
- data/test/tc_timezone_transition_definition.rb +0 -295
- data/test/tc_timezone_utc.rb +0 -27
- data/test/tc_transition_data_timezone_info.rb +0 -433
- data/test/tc_zoneinfo_country_info.rb +0 -78
- data/test/tc_zoneinfo_data_source.rb +0 -1204
- data/test/tc_zoneinfo_timezone_info.rb +0 -1234
- data/test/test_utils.rb +0 -188
- data/test/ts_all.rb +0 -7
- data/test/ts_all_ruby.rb +0 -5
- data/test/ts_all_zoneinfo.rb +0 -9
- data/test/tzinfo-data/tzinfo/data.rb +0 -8
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -315
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -218
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -261
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -186
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -321
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -265
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -220
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -927
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -596
- data/test/tzinfo-data/tzinfo/data/version.rb +0 -14
- data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
- data/test/zoneinfo/America/New_York +0 -0
- data/test/zoneinfo/Australia/Melbourne +0 -0
- data/test/zoneinfo/EST +0 -0
- data/test/zoneinfo/Etc/UTC +0 -0
- data/test/zoneinfo/Europe/Amsterdam +0 -0
- data/test/zoneinfo/Europe/Andorra +0 -0
- data/test/zoneinfo/Europe/London +0 -0
- data/test/zoneinfo/Europe/Paris +0 -0
- data/test/zoneinfo/Europe/Prague +0 -0
- data/test/zoneinfo/Factory +0 -0
- data/test/zoneinfo/iso3166.tab +0 -275
- data/test/zoneinfo/leapseconds +0 -61
- data/test/zoneinfo/posix/Europe/London +0 -0
- data/test/zoneinfo/posixrules +0 -0
- data/test/zoneinfo/right/Europe/London +0 -0
- data/test/zoneinfo/zone.tab +0 -439
- data/test/zoneinfo/zone1970.tab +0 -369
- data/tzinfo.gemspec +0 -21
@@ -1,110 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCRubyCountryInfo < Minitest::Test
|
6
|
-
|
7
|
-
def test_code
|
8
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
|
9
|
-
assert_equal('ZZ', ci.code)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_name
|
13
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
|
14
|
-
assert_equal('Zzz', ci.name)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_zone_identifiers_empty
|
18
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
|
19
|
-
assert(ci.zone_identifiers.empty?)
|
20
|
-
assert(ci.zone_identifiers.frozen?)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_zone_identifiers_no_block
|
24
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz')
|
25
|
-
assert(ci.zone_identifiers.empty?)
|
26
|
-
assert(ci.zone_identifiers.frozen?)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_zone_identifiers
|
30
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
|
31
|
-
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
|
32
|
-
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
|
33
|
-
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
|
34
|
-
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
|
38
|
-
assert(ci.zone_identifiers.frozen?)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_zone_identifiers_after_freeze
|
42
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
|
43
|
-
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
|
44
|
-
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
|
45
|
-
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
|
46
|
-
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
|
47
|
-
end
|
48
|
-
|
49
|
-
ci.freeze
|
50
|
-
|
51
|
-
assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_zones_empty
|
55
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
|
56
|
-
assert(ci.zones.empty?)
|
57
|
-
assert(ci.zones.frozen?)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_zones_no_block
|
61
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz')
|
62
|
-
assert(ci.zones.empty?)
|
63
|
-
assert(ci.zones.frozen?)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_zones
|
67
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
|
68
|
-
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
|
69
|
-
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
|
70
|
-
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
|
71
|
-
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
|
72
|
-
end
|
73
|
-
|
74
|
-
assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
|
75
|
-
CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
|
76
|
-
CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
|
77
|
-
CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
|
78
|
-
ci.zones)
|
79
|
-
assert(ci.zones.frozen?)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_zones_after_freeze
|
83
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
|
84
|
-
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
|
85
|
-
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
|
86
|
-
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
|
87
|
-
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
|
88
|
-
end
|
89
|
-
|
90
|
-
ci.freeze
|
91
|
-
|
92
|
-
assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
|
93
|
-
CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
|
94
|
-
CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
|
95
|
-
CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
|
96
|
-
ci.zones)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_deferred_evaluate
|
100
|
-
block_called = false
|
101
|
-
|
102
|
-
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
|
103
|
-
block_called = true
|
104
|
-
end
|
105
|
-
|
106
|
-
assert_equal(false, block_called)
|
107
|
-
ci.zones
|
108
|
-
assert_equal(true, block_called)
|
109
|
-
end
|
110
|
-
end
|
data/test/tc_ruby_data_source.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
using TaintExt if Module.const_defined?(:TaintExt)
|
6
|
-
|
7
|
-
class TCRubyDataSource < Minitest::Test
|
8
|
-
def setup
|
9
|
-
@data_source = RubyDataSource.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_initialize_not_found
|
13
|
-
# A failure to load tzinfo/data in initialize will not cause an exception.
|
14
|
-
# Attempts to load data files will subsequently fail.
|
15
|
-
code = <<-EOF
|
16
|
-
begin
|
17
|
-
ds = TZInfo::RubyDataSource.new
|
18
|
-
puts 'Initialized'
|
19
|
-
ds.load_timezone_info('Europe/London')
|
20
|
-
rescue Exception => e
|
21
|
-
puts e.class
|
22
|
-
end
|
23
|
-
EOF
|
24
|
-
|
25
|
-
assert_sub_process_returns(['Initialized', 'TZInfo::InvalidTimezoneIdentifier'], code)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_load_timezone_info_data
|
29
|
-
info = @data_source.load_timezone_info('Europe/London')
|
30
|
-
assert_kind_of(DataTimezoneInfo, info)
|
31
|
-
assert_equal('Europe/London', info.identifier)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_load_timezone_info_linked
|
35
|
-
info = @data_source.load_timezone_info('UTC')
|
36
|
-
assert_kind_of(LinkedTimezoneInfo, info)
|
37
|
-
assert_equal('UTC', info.identifier)
|
38
|
-
assert_equal('Etc/UTC', info.link_to_identifier)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_load_timezone_info_does_not_exist
|
42
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
43
|
-
@data_source.load_timezone_info('Nowhere/Special')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_load_timezone_info_invalid
|
48
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
49
|
-
@data_source.load_timezone_info('../Definitions/UTC')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_load_timezone_info_nil
|
54
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
55
|
-
@data_source.load_timezone_info(nil)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_load_timezone_info_case
|
60
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
61
|
-
@data_source.load_timezone_info('europe/london')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_load_timezone_info_plus
|
66
|
-
info = @data_source.load_timezone_info('Etc/GMT+1')
|
67
|
-
assert_equal('Etc/GMT+1', info.identifier)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_load_timezone_info_minus
|
71
|
-
info = @data_source.load_timezone_info('Etc/GMT-1')
|
72
|
-
assert_equal('Etc/GMT-1', info.identifier)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_load_timezone_info_tainted
|
76
|
-
skip_if_has_bug_14060
|
77
|
-
|
78
|
-
safe_test(:unavailable => :skip) do
|
79
|
-
identifier = 'Europe/Amsterdam'.dup.taint
|
80
|
-
assert(identifier.tainted?)
|
81
|
-
info = @data_source.load_timezone_info(identifier)
|
82
|
-
assert_equal('Europe/Amsterdam', info.identifier)
|
83
|
-
assert(identifier.tainted?)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_load_timezone_info_tainted_and_frozen
|
88
|
-
skip_if_has_bug_14060
|
89
|
-
|
90
|
-
safe_test do
|
91
|
-
info = @data_source.load_timezone_info('Europe/Amsterdam'.dup.taint.freeze)
|
92
|
-
assert_equal('Europe/Amsterdam', info.identifier)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_timezone_identifiers
|
97
|
-
all = @data_source.timezone_identifiers
|
98
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.timezones, all)
|
99
|
-
assert_equal(true, all.frozen?)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_data_timezone_identifiers
|
103
|
-
all_data = @data_source.data_timezone_identifiers
|
104
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.data_timezones, all_data)
|
105
|
-
assert_equal(true, all_data.frozen?)
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_linked_timezone_identifiers
|
109
|
-
all_linked = @data_source.linked_timezone_identifiers
|
110
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.linked_timezones, all_linked)
|
111
|
-
assert_equal(true, all_linked.frozen?)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_load_country_info
|
115
|
-
info = @data_source.load_country_info('GB')
|
116
|
-
assert_equal('GB', info.code)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_load_country_info_not_exist
|
120
|
-
assert_raises(InvalidCountryCode) do
|
121
|
-
@data_source.load_country_info('ZZ')
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_load_country_info_invalid
|
126
|
-
assert_raises(InvalidCountryCode) do
|
127
|
-
@data_source.load_country_info('../Countries/GB')
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_load_country_info_nil
|
132
|
-
assert_raises(InvalidCountryCode) do
|
133
|
-
@data_source.load_country_info(nil)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_load_country_info_case
|
138
|
-
assert_raises(InvalidCountryCode) do
|
139
|
-
@data_source.load_country_info('gb')
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_load_country_info_tainted
|
144
|
-
safe_test(:unavailable => :skip) do
|
145
|
-
code = 'NL'.dup.taint
|
146
|
-
assert(code.tainted?)
|
147
|
-
info = @data_source.load_country_info(code)
|
148
|
-
assert_equal('NL', info.code)
|
149
|
-
assert(code.tainted?)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_load_country_info_tainted_and_frozen
|
154
|
-
safe_test do
|
155
|
-
info = @data_source.load_country_info('NL'.dup.taint.freeze)
|
156
|
-
assert_equal('NL', info.code)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_country_codes
|
161
|
-
codes = @data_source.country_codes
|
162
|
-
assert_equal(TZInfo::Data::Indexes::Countries.countries.keys, codes)
|
163
|
-
assert_equal(true, codes.frozen?)
|
164
|
-
end
|
165
|
-
end
|
data/test/tc_time_or_datetime.rb
DELETED
@@ -1,660 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
require 'rational' unless defined?(Rational)
|
3
|
-
|
4
|
-
include TZInfo
|
5
|
-
|
6
|
-
class TCTimeOrDateTime < Minitest::Test
|
7
|
-
# Ruby 1.8.7 (built with GCC 8.3.0 on Ubuntu 19.04) fails to perform DateTime
|
8
|
-
# arithmetic operations correctly when sub-seconds are used. Detect this and
|
9
|
-
# disable the affected tests.
|
10
|
-
DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN = (DateTime.new(2019, 12, 22, 15, 0, Rational(1, 1000)) + Rational(1, 86400)).strftime('%Q') != '1577026801001'
|
11
|
-
puts "DateTime sub-second arithmetic is broken on this platform" if DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
12
|
-
|
13
|
-
def test_initialize_time
|
14
|
-
assert_nothing_raised do
|
15
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_initialize_time_local
|
20
|
-
tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3))
|
21
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_time)
|
22
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_orig)
|
23
|
-
assert(tdt.to_time.utc?)
|
24
|
-
assert(tdt.to_orig.utc?)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_intialize_time_local_usec
|
28
|
-
tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3, 721123))
|
29
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_time)
|
30
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_orig)
|
31
|
-
assert(tdt.to_time.utc?)
|
32
|
-
assert(tdt.to_orig.utc?)
|
33
|
-
end
|
34
|
-
|
35
|
-
if Time.utc(2013, 1, 1).respond_to?(:nsec)
|
36
|
-
def test_initialize_time_local_nsec
|
37
|
-
tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)))
|
38
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_time)
|
39
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_orig)
|
40
|
-
assert(tdt.to_time.utc?)
|
41
|
-
assert(tdt.to_orig.utc?)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_initialize_time_utc_local
|
46
|
-
# Check that local Time instances on systems using UTC as the system
|
47
|
-
# time zone are still converted to UTC Time instances.
|
48
|
-
|
49
|
-
# Note that this will only test will only work correctly on platforms where
|
50
|
-
# setting the TZ environment variable has an effect. If setting TZ has no
|
51
|
-
# effect, then this test will still pass.
|
52
|
-
|
53
|
-
old_tz = ENV['TZ']
|
54
|
-
begin
|
55
|
-
ENV['TZ'] = 'UTC'
|
56
|
-
tdt = TimeOrDateTime.new(Time.local(2014, 1, 11, 17, 18, 41))
|
57
|
-
assert_equal(Time.utc(2014, 1, 11, 17, 18, 41), tdt.to_time)
|
58
|
-
assert_equal(Time.utc(2014, 1, 11, 17, 18, 41), tdt.to_orig)
|
59
|
-
assert(tdt.to_time.utc?)
|
60
|
-
assert(tdt.to_orig.utc?)
|
61
|
-
ensure
|
62
|
-
ENV['TZ'] = old_tz
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_initialize_datetime_offset
|
67
|
-
tdt = TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3).new_offset(Rational(5, 24)))
|
68
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), tdt.to_datetime)
|
69
|
-
assert_equal(0, tdt.to_datetime.offset)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_initialize_datetime
|
73
|
-
assert_nothing_raised do
|
74
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_initialize_timestamp
|
79
|
-
assert_nothing_raised do
|
80
|
-
TimeOrDateTime.new(1143214323)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_initialize_timestamp_string
|
85
|
-
assert_nothing_raised do
|
86
|
-
TimeOrDateTime.new('1143214323')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
unless RubyCoreSupport.time_supports_64bit
|
91
|
-
# Only define this test for non-64bit platforms. Some 64-bit Rubies support
|
92
|
-
# greater than 64-bit, others support less than the full range. In either
|
93
|
-
# case, times at the far ends of the range are so far in the future or past
|
94
|
-
# that they are not going to turn up in timezone data.
|
95
|
-
def test_initialize_timestamp_supported_range
|
96
|
-
assert_equal((2 ** 31) - 1, TimeOrDateTime.new((2 ** 31) - 1).to_orig)
|
97
|
-
|
98
|
-
assert_raises(RangeError) do
|
99
|
-
TimeOrDateTime.new(2 ** 31)
|
100
|
-
end
|
101
|
-
|
102
|
-
if RubyCoreSupport.time_supports_negative
|
103
|
-
assert_equal(-(2 ** 31), TimeOrDateTime.new(-(2 ** 31)).to_orig)
|
104
|
-
|
105
|
-
assert_raises(RangeError) do
|
106
|
-
TimeOrDateTime.new(-(2 ** 31) - 1)
|
107
|
-
end
|
108
|
-
else
|
109
|
-
assert_equal(0, TimeOrDateTime.new(0).to_orig)
|
110
|
-
|
111
|
-
assert_raises(RangeError) do
|
112
|
-
TimeOrDateTime.new(-1)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_to_time
|
119
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
|
120
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_time)
|
121
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123),
|
122
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721123)).to_time)
|
123
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
|
124
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_time)
|
125
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123),
|
126
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000))).to_time)
|
127
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
|
128
|
-
TimeOrDateTime.new(1143214323).to_time)
|
129
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
|
130
|
-
TimeOrDateTime.new('1143214323').to_time)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_to_time_trunc_to_usec
|
134
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123),
|
135
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(7211239, 10000000))).to_time)
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_to_time_after_freeze
|
139
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).freeze.to_time)
|
140
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(1143214323).freeze.to_time)
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_to_datetime
|
144
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
|
145
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_datetime)
|
146
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000)),
|
147
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721123)).to_datetime)
|
148
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000)),
|
149
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000))).to_datetime)
|
150
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
|
151
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_datetime)
|
152
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
|
153
|
-
TimeOrDateTime.new(1143214323).to_datetime)
|
154
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
|
155
|
-
TimeOrDateTime.new('1143214323').to_datetime)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_to_datetime_ruby186_bug
|
159
|
-
# DateTime.new in Ruby 1.8.6 won't allow a time to be specified using
|
160
|
-
# fractions of a second that is within the 60th second of a minute.
|
161
|
-
|
162
|
-
# TimeOrDateTime has a workaround for this issue.
|
163
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 59) + Rational(721123, 86400000000),
|
164
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 59, 721123)).to_datetime)
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_to_datetime_trunc_to_usec
|
168
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000)),
|
169
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(9, 10))).to_datetime)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_to_datetime_after_freeze
|
173
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).freeze.to_datetime)
|
174
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(1143214323).freeze.to_datetime)
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_to_i
|
178
|
-
assert_equal(1143214323,
|
179
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_i)
|
180
|
-
assert_equal(1143214323,
|
181
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).to_i)
|
182
|
-
assert_equal(1143214323,
|
183
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_i)
|
184
|
-
assert_equal(1143214323,
|
185
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).to_i)
|
186
|
-
assert_equal(1143214323,
|
187
|
-
TimeOrDateTime.new(1143214323).to_i)
|
188
|
-
assert_equal(1143214323,
|
189
|
-
TimeOrDateTime.new('1143214323').to_i)
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_to_i_after_freeze
|
193
|
-
assert_equal(1143214323, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).freeze.to_i)
|
194
|
-
assert_equal(1143214323, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).freeze.to_i)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_to_orig
|
198
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
|
199
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_orig)
|
200
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721000),
|
201
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).to_orig)
|
202
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
|
203
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_orig)
|
204
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)),
|
205
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).to_orig)
|
206
|
-
assert_equal(1143214323,
|
207
|
-
TimeOrDateTime.new(1143214323).to_orig)
|
208
|
-
assert_equal(1143214323,
|
209
|
-
TimeOrDateTime.new('1143214323').to_orig)
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_to_s
|
213
|
-
assert_equal("Time: #{Time.utc(2006, 3, 24, 15, 32, 3).to_s}",
|
214
|
-
TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_s)
|
215
|
-
assert_equal("DateTime: #{DateTime.new(2006, 3, 24, 15, 32, 3)}",
|
216
|
-
TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_s)
|
217
|
-
assert_equal('Timestamp: 1143214323',
|
218
|
-
TimeOrDateTime.new(1143214323).to_s)
|
219
|
-
assert_equal('Timestamp: 1143214323',
|
220
|
-
TimeOrDateTime.new('1143214323').to_s)
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_year
|
224
|
-
assert_equal(2006, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).year)
|
225
|
-
assert_equal(2006, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).year)
|
226
|
-
assert_equal(2006, TimeOrDateTime.new(1143214323).year)
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_mon
|
230
|
-
assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).mon)
|
231
|
-
assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).mon)
|
232
|
-
assert_equal(3, TimeOrDateTime.new(1143214323).mon)
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_month
|
236
|
-
assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).month)
|
237
|
-
assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).month)
|
238
|
-
assert_equal(3, TimeOrDateTime.new(1143214323).month)
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_mday
|
242
|
-
assert_equal(24, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).mday)
|
243
|
-
assert_equal(24, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).mday)
|
244
|
-
assert_equal(24, TimeOrDateTime.new(1143214323).mday)
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_day
|
248
|
-
assert_equal(24, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).day)
|
249
|
-
assert_equal(24, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).day)
|
250
|
-
assert_equal(24, TimeOrDateTime.new(1143214323).day)
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_hour
|
254
|
-
assert_equal(15, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).hour)
|
255
|
-
assert_equal(15, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).hour)
|
256
|
-
assert_equal(15, TimeOrDateTime.new(1143214323).hour)
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_min
|
260
|
-
assert_equal(32, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).min)
|
261
|
-
assert_equal(32, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).min)
|
262
|
-
assert_equal(32, TimeOrDateTime.new(1143214323).min)
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_sec
|
266
|
-
assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).sec)
|
267
|
-
assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).sec)
|
268
|
-
assert_equal(3, TimeOrDateTime.new(1143214323).sec)
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_usec
|
272
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).usec)
|
273
|
-
assert_equal(721123, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721123)).usec)
|
274
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).usec)
|
275
|
-
assert_equal(721123, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123,1000000))).usec)
|
276
|
-
assert_equal(0, TimeOrDateTime.new(1143214323).usec)
|
277
|
-
end
|
278
|
-
|
279
|
-
def test_usec_after_to_i
|
280
|
-
val = TimeOrDateTime.new(Time.utc(2013, 2, 4, 22, 10, 33, 598000))
|
281
|
-
assert_equal(Time.utc(2013, 2, 4, 22, 10, 33).to_i, val.to_i)
|
282
|
-
assert_equal(598000, val.usec)
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_compare_timeordatetime_time
|
286
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
|
287
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
|
288
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
|
289
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
|
290
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
|
291
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
|
292
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
|
293
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
|
294
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
|
295
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
|
296
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
|
297
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
|
298
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
|
299
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
|
300
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
|
301
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
|
302
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
|
303
|
-
|
304
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500001)))
|
305
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)))
|
306
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 499999)))
|
307
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000 + DATETIME_RESOLUTION)))
|
308
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)))
|
309
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000 - DATETIME_RESOLUTION)))
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_compare_timeordatetime_datetime
|
313
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
|
314
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
|
315
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
|
316
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
|
317
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
|
318
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
|
319
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
|
320
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
|
321
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
|
322
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
|
323
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
|
324
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
|
325
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
|
326
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
|
327
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
|
328
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
|
329
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
|
330
|
-
|
331
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000))))
|
332
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))))
|
333
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000))))
|
334
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000))))
|
335
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))))
|
336
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000))))
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_compare_timeordatetime_timestamp
|
340
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214324))
|
341
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1174750323))
|
342
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
|
343
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214322))
|
344
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1111678323))
|
345
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214324))
|
346
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1174750323))
|
347
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
|
348
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214322))
|
349
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1111678323))
|
350
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
|
351
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
|
352
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214324))
|
353
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1174750323))
|
354
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214323))
|
355
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214322))
|
356
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1111678323))
|
357
|
-
end
|
358
|
-
|
359
|
-
def test_compare_time
|
360
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 4))
|
361
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2007, 3, 24, 15, 32, 3))
|
362
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
|
363
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 2))
|
364
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2005, 3, 24, 15, 32, 3))
|
365
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 4))
|
366
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2007, 3, 24, 15, 32, 3))
|
367
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
|
368
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 2))
|
369
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2005, 3, 24, 15, 32, 3))
|
370
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
|
371
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
|
372
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 4))
|
373
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> Time.utc(2007, 3, 24, 15, 32, 3))
|
374
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 3))
|
375
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 2))
|
376
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> Time.utc(2005, 3, 24, 15, 32, 3))
|
377
|
-
|
378
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500001))
|
379
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000))
|
380
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 499999))
|
381
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000 + DATETIME_RESOLUTION))
|
382
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000))
|
383
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000 - DATETIME_RESOLUTION))
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_compare_datetime
|
387
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
|
388
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
|
389
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
|
390
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
|
391
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
|
392
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
|
393
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
|
394
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
|
395
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
|
396
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
|
397
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
|
398
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
|
399
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
|
400
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
|
401
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
|
402
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
|
403
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
|
404
|
-
|
405
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000)))
|
406
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000)))
|
407
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000)))
|
408
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000)))
|
409
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000)))
|
410
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000)))
|
411
|
-
end
|
412
|
-
|
413
|
-
def test_compare_timestamp
|
414
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214324)
|
415
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1174750323)
|
416
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214323)
|
417
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214322)
|
418
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1111678323)
|
419
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214324)
|
420
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1174750323)
|
421
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214323)
|
422
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214322)
|
423
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1111678323)
|
424
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> 1143214323)
|
425
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> 1143214323)
|
426
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> 1143214324)
|
427
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> 1174750323)
|
428
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> 1143214323)
|
429
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> 1143214322)
|
430
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> 1111678323)
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_compare_timestamp_str
|
434
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214324')
|
435
|
-
assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1174750323')
|
436
|
-
assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214323')
|
437
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214322')
|
438
|
-
assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1111678323')
|
439
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214324')
|
440
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1174750323')
|
441
|
-
assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214323')
|
442
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214322')
|
443
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1111678323')
|
444
|
-
assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> '1143214323')
|
445
|
-
assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> '1143214323')
|
446
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> '1143214324')
|
447
|
-
assert_equal(-1, TimeOrDateTime.new(1143214323) <=> '1174750323')
|
448
|
-
assert_equal(0, TimeOrDateTime.new(1143214323) <=> '1143214323')
|
449
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> '1143214322')
|
450
|
-
assert_equal(1, TimeOrDateTime.new(1143214323) <=> '1111678323')
|
451
|
-
end
|
452
|
-
|
453
|
-
def test_compare_non_comparable
|
454
|
-
assert_nil(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Object.new)
|
455
|
-
assert_nil(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Object.new)
|
456
|
-
assert_nil(TimeOrDateTime.new(1143214323) <=> Object.new)
|
457
|
-
end
|
458
|
-
|
459
|
-
def test_eql
|
460
|
-
assert_equal(true, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
|
461
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
|
462
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(1143214323)))
|
463
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new('1143214323')))
|
464
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4))))
|
465
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(Object.new))
|
466
|
-
|
467
|
-
assert_equal(true, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000))))
|
468
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)))))
|
469
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 722000))))
|
470
|
-
assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).eql?(Object.new))
|
471
|
-
|
472
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
|
473
|
-
assert_equal(true, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
|
474
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(1143214323)))
|
475
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new('1143214323')))
|
476
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4))))
|
477
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(Object.new))
|
478
|
-
|
479
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000))))
|
480
|
-
assert_equal(true, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)))))
|
481
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(722, 1000)))))
|
482
|
-
assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).eql?(Object.new))
|
483
|
-
|
484
|
-
|
485
|
-
assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
|
486
|
-
assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
|
487
|
-
assert_equal(true, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(1143214323)))
|
488
|
-
assert_equal(true, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new('1143214323')))
|
489
|
-
assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(1143214324)))
|
490
|
-
assert_equal(false, TimeOrDateTime.new(1143214323).eql?(Object.new))
|
491
|
-
end
|
492
|
-
|
493
|
-
def test_hash
|
494
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3).hash, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).hash)
|
495
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3).hash, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).hash)
|
496
|
-
assert_equal(1143214323.hash, TimeOrDateTime.new(1143214323).hash)
|
497
|
-
assert_equal(1143214323.hash, TimeOrDateTime.new('1143214323').hash)
|
498
|
-
end
|
499
|
-
|
500
|
-
def test_add
|
501
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + 0).to_orig)
|
502
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) + 0).to_orig)
|
503
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + 0).to_orig)
|
504
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + 0).to_orig)
|
505
|
-
assert_equal(1143214323, (TimeOrDateTime.new(1143214323) + 0).to_orig)
|
506
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
|
507
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) + 1).to_orig)
|
508
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
|
509
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + 1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
510
|
-
assert_equal(1143214324, (TimeOrDateTime.new(1143214323) + 1).to_orig)
|
511
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
|
512
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) + (-1)).to_orig)
|
513
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
|
514
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + (-1)).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
515
|
-
assert_equal(1143214322, (TimeOrDateTime.new(1143214323) + (-1)).to_orig)
|
516
|
-
end
|
517
|
-
|
518
|
-
def test_subtract
|
519
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - 0).to_orig)
|
520
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - 0).to_orig)
|
521
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - 0).to_orig)
|
522
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - 0).to_orig)
|
523
|
-
assert_equal(1143214323, (TimeOrDateTime.new(1143214323) - 0).to_orig)
|
524
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
|
525
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - 1).to_orig)
|
526
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
|
527
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - 1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
528
|
-
assert_equal(1143214322, (TimeOrDateTime.new(1143214323) - 1).to_orig)
|
529
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
|
530
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - (-1)).to_orig)
|
531
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
|
532
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - (-1)).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
533
|
-
assert_equal(1143214324, (TimeOrDateTime.new(1143214323) - (-1)).to_orig)
|
534
|
-
end
|
535
|
-
|
536
|
-
def test_add_with_convert
|
537
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(0).to_orig)
|
538
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721000), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).add_with_convert(0).to_orig)
|
539
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(0).to_orig)
|
540
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(0).to_orig)
|
541
|
-
assert_equal(1143214323, TimeOrDateTime.new(1143214323).add_with_convert(0).to_orig)
|
542
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
|
543
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).add_with_convert(1).to_orig)
|
544
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
|
545
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
546
|
-
assert_equal(1143214324, TimeOrDateTime.new(1143214323).add_with_convert(1).to_orig)
|
547
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
|
548
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).add_with_convert(-1).to_orig)
|
549
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
|
550
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(-1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
|
551
|
-
assert_equal(1143214322, TimeOrDateTime.new(1143214323).add_with_convert(-1).to_orig)
|
552
|
-
|
553
|
-
if RubyCoreSupport.time_supports_negative
|
554
|
-
assert_equal(Time.utc(1969, 12, 31, 23, 59, 59), TimeOrDateTime.new(Time.utc(1970, 1, 1, 0, 0, 0)).add_with_convert(-1).to_orig)
|
555
|
-
assert_equal(-1, TimeOrDateTime.new(0).add_with_convert(-1).to_orig)
|
556
|
-
assert_equal(Time.utc(1969, 12, 31, 23, 59, 59, 892000), TimeOrDateTime.new(Time.utc(1970, 1, 1, 0, 0, 0, 892000)).add_with_convert(-1).to_orig)
|
557
|
-
|
558
|
-
if RubyCoreSupport.time_supports_64bit
|
559
|
-
assert_equal(Time.utc(1901, 12, 13, 20, 45, 51), TimeOrDateTime.new(Time.utc(1901, 12, 13, 20, 45, 52)).add_with_convert(-1).to_orig)
|
560
|
-
assert_equal(-2147483649, TimeOrDateTime.new(-2147483648).add_with_convert(-1).to_orig)
|
561
|
-
assert_equal(Time.utc(1901, 12, 13, 20, 45, 51, 892000), TimeOrDateTime.new(Time.utc(1901, 12, 13, 20, 45, 52, 892000)).add_with_convert(-1).to_orig)
|
562
|
-
else
|
563
|
-
assert_equal(DateTime.new(1901, 12, 13, 20, 45, 51), TimeOrDateTime.new(Time.utc(1901, 12, 13, 20, 45, 52)).add_with_convert(-1).to_orig)
|
564
|
-
assert_equal(DateTime.new(1901, 12, 13, 20, 45, 51), TimeOrDateTime.new(-2147483648).add_with_convert(-1).to_orig)
|
565
|
-
assert_equal(DateTime.new(1901, 12, 13, 20, 45, 51 + Rational(892,1000)), TimeOrDateTime.new(Time.utc(1901, 12, 13, 20, 45, 52, 892000)).add_with_convert(-1).to_orig)
|
566
|
-
end
|
567
|
-
else
|
568
|
-
assert_equal(DateTime.new(1969, 12, 31, 23, 59, 59), TimeOrDateTime.new(Time.utc(1970, 1, 1, 0, 0, 0)).add_with_convert(-1).to_orig)
|
569
|
-
assert_equal(DateTime.new(1969, 12, 31, 23, 59, 59), TimeOrDateTime.new(0).add_with_convert(-1).to_orig)
|
570
|
-
assert_equal(RubyCoreSupport.datetime_new(1969, 12, 31, 23, 59, 59 + Rational(892,1000)), TimeOrDateTime.new(Time.utc(1970, 1, 1, 0, 0, 0, 892000)).add_with_convert(-1).to_orig)
|
571
|
-
end
|
572
|
-
|
573
|
-
if RubyCoreSupport.time_supports_64bit
|
574
|
-
assert_equal(Time.utc(2038, 1, 19, 3, 14, 8), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 7)).add_with_convert(1).to_orig)
|
575
|
-
assert_equal(2147483648, TimeOrDateTime.new(2147483647).add_with_convert(1).to_orig)
|
576
|
-
assert_equal(Time.utc(2038, 1, 19, 3, 14, 8, 892000), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 7, 892000)).add_with_convert(1).to_orig)
|
577
|
-
else
|
578
|
-
assert_equal(DateTime.new(2038, 1, 19, 3, 14, 8), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 7)).add_with_convert(1).to_orig)
|
579
|
-
assert_equal(DateTime.new(2038, 1, 19, 3, 14, 8), TimeOrDateTime.new(2147483647).add_with_convert(1).to_orig)
|
580
|
-
assert_equal(DateTime.new(2038, 1, 19, 3, 14, 8 + Rational(892,1000)), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 7, 892000)).add_with_convert(1).to_orig)
|
581
|
-
|
582
|
-
assert_equal(Time.utc(2038, 1, 19, 3, 14, 7, 892000), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 6, 892000)).add_with_convert(1).to_orig)
|
583
|
-
end
|
584
|
-
end
|
585
|
-
|
586
|
-
def test_wrap_time
|
587
|
-
t = TimeOrDateTime.wrap(Time.utc(2006, 3, 24, 15, 32, 3))
|
588
|
-
assert_instance_of(TimeOrDateTime, t)
|
589
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), t.to_orig)
|
590
|
-
end
|
591
|
-
|
592
|
-
def test_wrap_datetime
|
593
|
-
t = TimeOrDateTime.wrap(DateTime.new(2006, 3, 24, 15, 32, 3))
|
594
|
-
assert_instance_of(TimeOrDateTime, t)
|
595
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), t.to_orig)
|
596
|
-
end
|
597
|
-
|
598
|
-
def test_wrap_timestamp
|
599
|
-
t = TimeOrDateTime.wrap(1143214323)
|
600
|
-
assert_instance_of(TimeOrDateTime, t)
|
601
|
-
assert_equal(1143214323, t.to_orig)
|
602
|
-
end
|
603
|
-
|
604
|
-
def test_wrap_timestamp_str
|
605
|
-
t = TimeOrDateTime.wrap('1143214323')
|
606
|
-
assert_instance_of(TimeOrDateTime, t)
|
607
|
-
assert_equal(1143214323, t.to_orig)
|
608
|
-
end
|
609
|
-
|
610
|
-
def test_wrap_timeordatetime
|
611
|
-
t = TimeOrDateTime.new(1143214323)
|
612
|
-
t2 = TimeOrDateTime.wrap(t)
|
613
|
-
assert_same(t, t2)
|
614
|
-
end
|
615
|
-
|
616
|
-
def test_wrap_block_time
|
617
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), TimeOrDateTime.wrap(Time.utc(2006, 3, 24, 15, 32, 3)) {|t|
|
618
|
-
assert_instance_of(TimeOrDateTime, t)
|
619
|
-
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), t.to_orig)
|
620
|
-
t + 1
|
621
|
-
})
|
622
|
-
end
|
623
|
-
|
624
|
-
def test_wrap_block_datetime
|
625
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), TimeOrDateTime.wrap(DateTime.new(2006, 3, 24, 15, 32, 3)) {|t|
|
626
|
-
assert_instance_of(TimeOrDateTime, t)
|
627
|
-
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), t.to_orig)
|
628
|
-
t + 1
|
629
|
-
})
|
630
|
-
end
|
631
|
-
|
632
|
-
def test_wrap_block_timestamp
|
633
|
-
assert_equal(1143214324, TimeOrDateTime.wrap(1143214323) {|t|
|
634
|
-
assert_instance_of(TimeOrDateTime, t)
|
635
|
-
assert_equal(1143214323, t.to_orig)
|
636
|
-
t + 1
|
637
|
-
})
|
638
|
-
end
|
639
|
-
|
640
|
-
def test_wrap_block_timestamp_str
|
641
|
-
assert_equal(1143214324, TimeOrDateTime.wrap('1143214323') {|t|
|
642
|
-
assert_instance_of(TimeOrDateTime, t)
|
643
|
-
assert_equal(1143214323, t.to_orig)
|
644
|
-
t + 1
|
645
|
-
})
|
646
|
-
end
|
647
|
-
|
648
|
-
def test_wrap_block_timeordatetime
|
649
|
-
t1 = TimeOrDateTime.new(1143214323)
|
650
|
-
|
651
|
-
t2 = TimeOrDateTime.wrap(t1) {|t|
|
652
|
-
assert_same(t1, t)
|
653
|
-
t + 1
|
654
|
-
}
|
655
|
-
|
656
|
-
assert t2
|
657
|
-
assert_instance_of(TimeOrDateTime, t2)
|
658
|
-
assert_equal(1143214324, t2.to_orig)
|
659
|
-
end
|
660
|
-
end
|