@@ -300,11 +300,11 @@ def _dump(limit = nil)
300
300
private :_dump
301
301
302
302
class << self
303
- def at ( sec , usec = undefined , unit = undefined , **kwargs )
303
+ def at ( sec , sub_sec = undefined , unit = undefined , **kwargs )
304
304
# **kwargs is used here because 'in' is a ruby keyword
305
305
offset = kwargs [ :in ] ? Truffle ::Type . coerce_to_utc_offset ( kwargs [ :in ] ) : nil
306
306
307
- result = if Primitive . undefined? ( usec )
307
+ result = if Primitive . undefined? ( sub_sec )
308
308
if Primitive . object_kind_of? ( sec , Time )
309
309
copy = allocate
310
310
copy . send ( :initialize_copy , sec )
@@ -321,11 +321,11 @@ def at(sec, usec=undefined, unit=undefined, **kwargs)
321
321
return result
322
322
end
323
323
324
- if Primitive . object_kind_of? ( sec , Time ) && Primitive . object_kind_of? ( usec , Integer )
324
+ if Primitive . object_kind_of? ( sec , Time ) && Primitive . object_kind_of? ( sub_sec , Integer )
325
325
raise TypeError , "can't convert Time into an exact number"
326
326
end
327
327
328
- second_arg_scale =
328
+ sub_sec_scale =
329
329
if Primitive . undefined? ( unit ) || :microsecond == unit || :usec == unit
330
330
1_000
331
331
elsif :millisecond == unit
@@ -336,21 +336,17 @@ def at(sec, usec=undefined, unit=undefined, **kwargs)
336
336
raise ArgumentError , "unexpected unit: #{ unit } "
337
337
end
338
338
339
- usec = 0 if Primitive . undefined? ( usec )
339
+ sec = Truffle ::Type . coerce_to_exact_num ( sec )
340
+ sub_sec = Primitive . undefined? ( sub_sec ) ? 0 : Truffle ::Type . coerce_to_exact_num ( sub_sec )
340
341
341
- s = Truffle ::Type . coerce_to_exact_num ( sec )
342
- u = Truffle ::Type . coerce_to_exact_num ( usec )
342
+ seconds , sec_frac = sec . divmod ( 1 )
343
343
344
- sec = s . to_i
345
- nsec_frac = s % 1.0
344
+ nsec = ( sec_frac * 1_000_000_000 ) . round + ( sub_sec * sub_sec_scale ) . to_i
346
345
347
- sec -= 1 if s < 0 && nsec_frac > 0
348
- nsec = ( nsec_frac * 1_000_000_000 + 0.5 ) . to_i + ( u * second_arg_scale ) . to_i
349
-
350
- sec += nsec / 1_000_000_000
346
+ seconds += nsec / 1_000_000_000
351
347
nsec %= 1_000_000_000
352
348
353
- time = Primitive . time_at self , sec , nsec
349
+ time = Primitive . time_at self , seconds , nsec
354
350
time = Primitive . time_localtime ( time , offset ) if offset
355
351
time
356
352
end
0 commit comments