Skip to content

Commit afb9130

Browse files
committed
Refactor and simplify conversion of seconds fraction into nanoseconds for Time.new(String)
1 parent 422f5ba commit afb9130

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/main/ruby/truffleruby/core/truffle/time_operations.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,7 @@ def self.new_from_string(time_class, str, **options)
113113
(?:\s* (?<offset>\S+))?
114114
)?\z/x =~ str
115115

116-
# convert seconds fraction to nanoseconds
117-
nsec = if subsec
118-
ndigits = subsec.length
119-
120-
if ndigits <= 9
121-
subsec.to_i * 10.pow(9 - ndigits)
122-
else
123-
subsec.to_i / 10.pow(ndigits - 9)
124-
end
125-
else
126-
nil
127-
end
128-
116+
nsec = subsec[0...9].ljust(9, '0').to_i if subsec
129117
utc_offset = self.utc_offset_for_compose(offset || options[:in])
130118
return self.compose(time_class, utc_offset, year, month, mday, hour, min, sec, nsec, nil)
131119
end

0 commit comments

Comments
 (0)