@@ -30,10 +30,17 @@ def self.compose_dual_signature(time_class, utc_offset, p1, p2 = nil, p3 = nil,
30
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 )
33
+ nsec = nil
34
+ if Primitive . is_a? ( usec , String )
35
+ nsec = usec . to_i * 1000
36
+ elsif usec
37
+ nsec = ( usec * 1000 ) . to_i
38
+ end
39
+
40
+ compose ( time_class , utc_offset , year , month , mday , hour , min , sec , nsec , is_dst )
34
41
end
35
42
36
- def self . compose ( time_class , utc_offset , year , month , mday , hour , min , sec , usec , is_dst )
43
+ def self . compose ( time_class , utc_offset , year , month , mday , hour , min , sec , nsec , is_dst )
37
44
if Primitive . is_a? ( month , String ) or month . respond_to? ( :to_str )
38
45
month = StringValue ( month )
39
46
month = MonthValue [ month . upcase ] || month . to_i
@@ -54,13 +61,6 @@ def self.compose(time_class, utc_offset, year, month, mday, hour, min, sec, usec
54
61
hour = Primitive . rb_num2int ( hour || 0 )
55
62
min = Primitive . rb_num2int ( min || 0 )
56
63
57
- nsec = nil
58
- if Primitive . is_a? ( usec , String )
59
- nsec = usec . to_i * 1000
60
- elsif usec
61
- nsec = ( usec * 1000 ) . to_i
62
- end
63
-
64
64
case utc_offset
65
65
when :utc
66
66
is_dst = nil
@@ -113,21 +113,21 @@ def self.new_from_string(time_class, str, **options)
113
113
(?:\s * (?<offset>\S +))?
114
114
)?\z /x =~ str
115
115
116
- # convert seconds fraction to microseconds
117
- usec = if subsec
116
+ # convert seconds fraction to nanoseconds
117
+ nsec = if subsec
118
118
ndigits = subsec . length
119
119
120
- if ndigits <= 6
121
- subsec . to_i * 10 . pow ( 6 - ndigits )
120
+ if ndigits <= 9
121
+ subsec . to_i * 10 . pow ( 9 - ndigits )
122
122
else
123
- subsec . to_r / 10 . pow ( ndigits - 6 ) # convert to Rational to not loose precision
123
+ subsec . to_i / 10 . pow ( ndigits - 9 )
124
124
end
125
125
else
126
126
nil
127
127
end
128
128
129
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 )
130
+ return self . compose ( time_class , utc_offset , year , month , mday , hour , min , sec , nsec , nil )
131
131
end
132
132
133
133
raise ArgumentError , "can't parse: #{ str . inspect } "
0 commit comments