@@ -17,19 +17,23 @@ module TimeOperations
17
17
18
18
# Handles Time methods .utc, .gm. .local, .mktime dual signature:
19
19
# - year, month, day, hour, min, sec, usec
20
- # - sec, min, hour, day, month, year
21
- def self . compose ( time_class , utc_offset , p1 , p2 = nil , p3 = nil , p4 = nil , p5 = nil , p6 = nil , p7 = nil ,
22
- yday = undefined , is_dst = undefined , tz = undefined )
20
+ # - sec, min, hour, day, month, year, dummy, dummy, dummy, dummy
21
+ def self . compose_dual_signature ( time_class , utc_offset , p1 , p2 = nil , p3 = nil , p4 = nil , p5 = nil , p6 = nil , p7 = nil ,
22
+ yday = undefined , is_dst = undefined , tz = undefined )
23
23
if Primitive . undefined? ( tz )
24
24
unless Primitive . undefined? ( is_dst )
25
25
raise ArgumentError , 'wrong number of arguments (9 for 1..8)'
26
26
end
27
27
28
- year , month , mday , hour , min , sec , usec , is_dst = p1 , p2 , p3 , p4 , p5 , p6 , p7 , - 1
28
+ year , month , mday , hour , min , sec , usec , is_dst = p1 , p2 , p3 , p4 , p5 , p6 , p7 , nil
29
29
else
30
- year , month , mday , hour , min , sec , usec , is_dst = p6 , p5 , p4 , p3 , p2 , p1 , 0 , is_dst ? 1 : 0
30
+ year , month , mday , hour , min , sec , usec , is_dst = p6 , p5 , p4 , p3 , p2 , p1 , 0 , is_dst
31
31
end
32
32
33
+ compose ( time_class , utc_offset , year , month , mday , hour , min , sec , usec , is_dst )
34
+ end
35
+
36
+ def self . compose ( time_class , utc_offset , year , month , mday , hour , min , sec , usec , is_dst )
33
37
if Primitive . is_a? ( month , String ) or month . respond_to? ( :to_str )
34
38
month = StringValue ( month )
35
39
month = MonthValue [ month . upcase ] || month . to_i
@@ -59,14 +63,14 @@ def self.compose(time_class, utc_offset, p1, p2 = nil, p3 = nil, p4 = nil, p5 =
59
63
60
64
case utc_offset
61
65
when :utc
62
- is_dst = - 1
66
+ is_dst = nil
63
67
is_utc = true
64
68
utc_offset = nil
65
69
when :local
66
70
is_utc = false
67
71
utc_offset = nil
68
72
else
69
- is_dst = - 1
73
+ is_dst = nil
70
74
is_utc = false
71
75
end
72
76
@@ -88,8 +92,9 @@ def self.compose(time_class, utc_offset, p1, p2 = nil, p3 = nil, p4 = nil, p5 =
88
92
end
89
93
90
94
nsec ||= 0
95
+ dst_code = is_dst ? 1 : ( Primitive . nil? ( is_dst ) ? -1 : 0 )
91
96
92
- Primitive . time_s_from_array ( time_class , sec , min , hour , mday , month , year , nsec , is_dst , is_utc , utc_offset )
97
+ Primitive . time_s_from_array ( time_class , sec , min , hour , mday , month , year , nsec , dst_code , is_utc , utc_offset )
93
98
end
94
99
95
100
# MRI: time_init_parse()
@@ -108,7 +113,7 @@ def self.new_from_string(time_class, str, **options)
108
113
(?:\s * (?<offset>\S +))?
109
114
)?\z /x =~ str
110
115
111
- # convert seconds fraction to milliseconds
116
+ # convert seconds fraction to microseconds
112
117
usec = if subsec
113
118
ndigits = subsec . length
114
119
@@ -121,7 +126,8 @@ def self.new_from_string(time_class, str, **options)
121
126
nil
122
127
end
123
128
124
- return self . compose ( time_class , self . utc_offset_for_compose ( offset || options [ :in ] ) , year , month , mday , hour , min , sec , usec )
129
+ utc_offset = self . utc_offset_for_compose ( offset || options [ :in ] )
130
+ return self . compose ( time_class , utc_offset , year , month , mday , hour , min , sec , usec , nil )
125
131
end
126
132
127
133
raise ArgumentError , "can't parse: #{ str . inspect } "
0 commit comments