Skip to content

Commit

Permalink
Use epoch seconds instead of milliseconds in cbor encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Jan 21, 2025
1 parent d1fcccd commit fbb2bf0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions gems/aws-sdk-core/lib/aws-sdk-core/cbor/decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def decode_item
when :tag
case (tag = read_tag)
when TAG_TYPE_EPOCH
type = peek_type
item = decode_item
item /= 1000.0 if type == :integer
Time.at(item)
when TAG_TYPE_BIGNUM, TAG_TYPE_NEG_BIGNUM
read_bignum(tag)
Expand Down
4 changes: 2 additions & 2 deletions gems/aws-sdk-core/lib/aws-sdk-core/cbor/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def add_tag(tag)

def add_time(value)
head(MAJOR_TYPE_TAG, TAG_TYPE_EPOCH)
epoch_ms = (value.to_f * 1000).to_i
add_integer(epoch_ms)
epoch = value.to_f
add_double(epoch)
end

def bignum_to_bytes(value)
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/spec/aws/cbor/decoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def decode_half_bytes(half)
end

it 'decodes integer times' do
expect(cbor64_decode('wRsAAAFvYQ3z8A=='))
expect(cbor64_decode('wftB14MjtYAAAA=='))
.to eq(Time.parse('2020-01-01 12:21:42Z'))
end

Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/spec/aws/cbor/encoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def cbor64_encode(value)
end

it 'encodes times' do
expect(cbor64_encode(time)).to eq('wRsAAAFvYQ3z8A==')
expect(cbor64_encode(time)).to eq('wftB14MjtYAAAA==')
end

it 'encodes BigDecimals' do
Expand Down

0 comments on commit fbb2bf0

Please sign in to comment.