Skip to content

Commit ac75d0a

Browse files
authored
Fix UFC offset when deserializing iso8601 timestamp values (#3037)
1 parent a458737 commit ac75d0a

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Ensure no UTC offset when deserializing `iso8601` timestamp format values.
5+
46
* Feature - Bump User Agent to version 2.1 to track business metrics. This changes the User Agent plugin order to be just before sending.
57

68
3.196.1 (2024-05-14)

gems/aws-sdk-core/lib/aws-sdk-core/util.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ def deserialize_number(str)
9090
end
9191
end
9292

93-
# @param [String, Integer] value
93+
# @param [String] value
9494
# @return [Time]
9595
def deserialize_time(value)
9696
case value
9797
when nil then nil
98-
when /^\d+$/ then Time.at(value.to_i)
98+
when /^[\d.]+$/ then Time.at(value.to_f).utc
9999
else
100100
begin
101-
fractional_time = Time.parse(value).utc.to_f
102-
Time.at(fractional_time)
101+
fractional_time = Time.parse(value).to_f
102+
Time.at(fractional_time).utc
103103
rescue ArgumentError
104104
raise "unhandled timestamp format `#{value}'"
105105
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../spec_helper'
4+
5+
module Aws
6+
describe Util do
7+
describe '.deserialize_time' do
8+
let(:time) { Time.at(946_845_296.123) }
9+
10+
it 'correctly parses when given value is nil' do
11+
expect(Util.deserialize_time(nil)).to be_nil
12+
end
13+
14+
it 'correctly parses when given value is a numeric string' do
15+
value = time.to_f.to_s
16+
expect(Util.deserialize_time(value)).to eq(time.utc)
17+
end
18+
19+
it 'correctly parses when given value is a string' do
20+
value = time.strftime '%Y-%m-%d %H:%M:%S.%N %z' # preserves frac secs
21+
expect(Util.deserialize_time(value)).to eq(time.utc)
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)