@@ -15,45 +15,40 @@ module TimeOperations
15
15
'JUL' => 7 , 'AUG' => 8 , 'SEP' => 9 , 'OCT' => 10 , 'NOV' => 11 , 'DEC' => 12
16
16
}
17
17
18
+ # Handles Time methods .utc, .gm. .local, .mktime dual signature:
19
+ # - year, month, day, hour, min, sec, usec
20
+ # - sec, min, hour, day, month, year
18
21
def self . compose ( time_class , utc_offset , p1 , p2 = nil , p3 = nil , p4 = nil , p5 = nil , p6 = nil , p7 = nil ,
19
22
yday = undefined , is_dst = undefined , tz = undefined )
20
23
if Primitive . undefined? ( tz )
21
24
unless Primitive . undefined? ( is_dst )
22
25
raise ArgumentError , 'wrong number of arguments (9 for 1..8)'
23
26
end
24
27
25
- year = p1
26
- month = p2
27
- mday = p3
28
- hour = p4
29
- min = p5
30
- sec = p6
31
- usec = p7
32
- is_dst = -1
28
+ year , month , mday , hour , min , sec , usec , is_dst = p1 , p2 , p3 , p4 , p5 , p6 , p7 , -1
33
29
else
34
- year = p6
35
- month = p5
36
- mday = p4
37
- hour = p3
38
- min = p2
39
- sec = p1
40
- usec = 0
41
- is_dst = is_dst ? 1 : 0
30
+ year , month , mday , hour , min , sec , usec , is_dst = p6 , p5 , p4 , p3 , p2 , p1 , 0 , is_dst ? 1 : 0
42
31
end
43
32
44
33
if Primitive . is_a? ( month , String ) or month . respond_to? ( :to_str )
45
34
month = StringValue ( month )
46
35
month = MonthValue [ month . upcase ] || month . to_i
47
36
48
37
raise ArgumentError , 'month argument out of range' unless month
49
- else
50
- month = Truffle ::Type . coerce_to ( month || 1 , Integer , :to_int )
51
38
end
52
39
53
- year = Primitive . is_a? ( year , String ) ? year . to_i : Truffle ::Type . coerce_to ( year , Integer , :to_int )
54
- mday = Primitive . is_a? ( mday , String ) ? mday . to_i : Truffle ::Type . coerce_to ( mday || 1 , Integer , :to_int )
55
- hour = Primitive . is_a? ( hour , String ) ? hour . to_i : Truffle ::Type . coerce_to ( hour || 0 , Integer , :to_int )
56
- min = Primitive . is_a? ( min , String ) ? min . to_i : Truffle ::Type . coerce_to ( min || 0 , Integer , :to_int )
40
+ year = year . to_i if Primitive . is_a? ( year , String )
41
+ mday = mday . to_i if Primitive . is_a? ( mday , String )
42
+ hour = hour . to_i if Primitive . is_a? ( hour , String )
43
+ min = min . to_i if Primitive . is_a? ( min , String )
44
+
45
+ # Ensure all the user provided numeric values fit into the Java Integer type.
46
+ # sec and nsec are handled separately.
47
+ year = Primitive . rb_num2int ( year )
48
+ month = Primitive . rb_num2int ( month || 1 )
49
+ mday = Primitive . rb_num2int ( mday || 1 )
50
+ hour = Primitive . rb_num2int ( hour || 0 )
51
+ min = Primitive . rb_num2int ( min || 0 )
57
52
58
53
nsec = nil
59
54
if Primitive . is_a? ( usec , String )
@@ -75,15 +70,6 @@ def self.compose(time_class, utc_offset, p1, p2 = nil, p3 = nil, p4 = nil, p5 =
75
70
is_utc = false
76
71
end
77
72
78
- # Ensure all the user provided numeric values fit into the Java Integer type.
79
- # sec and nsec are handled separately.
80
- Primitive . rb_num2int ( min )
81
- Primitive . rb_num2int ( hour )
82
- Primitive . rb_num2int ( mday )
83
- Primitive . rb_num2int ( month )
84
- Primitive . rb_num2int ( year )
85
-
86
- # handle sec and nsec
87
73
if Primitive . is_a? ( sec , String )
88
74
sec = sec . to_i
89
75
elsif nsec
0 commit comments