Skip to content

Commit

Permalink
Fix frac seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin committed Jun 4, 2024
1 parent f7fa34e commit 9c3cfaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def deserialize_number(str)
def deserialize_time(value)
case value
when nil then nil
when /^\d+$/ then Time.at(value.to_i).utc
when /^[\d.]+$/ then Time.at(value.to_f).utc
else
begin
fractional_time = Time.parse(value).to_f
Expand Down
10 changes: 6 additions & 4 deletions gems/aws-sdk-core/spec/aws/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
module Aws
describe Util do
describe '.deserialize_time' do
let(:time) { Time.at(946_845_296.123) }

it 'correctly parses when given value is nil' do
expect(Util.deserialize_time(nil)).to be_nil
end

it 'correctly parses when given value is a numeric string' do
expect(Util.deserialize_time('946702800').to_s)
.to eq('2000-01-01 05:00:00 UTC')
value = time.to_f.to_s
expect(Util.deserialize_time(value)).to eq(time.utc)
end

it 'correctly parses when given value is a string' do
expect(Util.deserialize_time('2000-01-02T20:34:56.123Z').to_s)
.to eq('2000-01-02 20:34:56 UTC')
value = time.strftime '%Y-%m-%d %H:%M:%S.%N %z' # preserves frac secs
expect(Util.deserialize_time(value)).to eq(time.utc)
end
end
end
Expand Down

0 comments on commit 9c3cfaa

Please sign in to comment.