Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure RFC dates between years 0001 and 0099 are parsed correctly #1516

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

clockworkgr
Copy link
Contributor

This fixes an issue where an RFC3339 Date like 0001-01-01T00:00:00Z (which is used as the default/empty/ value in CommitSig.Timestamp when BlockIdFlag is ABSENT) was parsed as 1901-01-01T00:00:00Z due to the way Date.UTC() treats years 0 to 99.

This led to incorrect timestamps being generated.

Unit test has been added.

@clockworkgr
Copy link
Contributor Author

Related: confio/cosmjs-types#89

@clockworkgr
Copy link
Contributor Author

This change, combined with the fact we no longer allow empty/unset fields in cosmjs-types means that this:

#704 (comment)

must be addressed by no longer treating the timestamp as optional.

packages/encoding/src/rfc3339.ts Outdated Show resolved Hide resolved
function decodeCommitSignature(data: RpcSignature): CommitSignature {
return {
blockIdFlag: decodeBlockIdFlag(data.block_id_flag),
validatorAddress: data.validator_address ? fromHex(data.validator_address) : undefined,
timestamp: decodeOptionalTime(data.timestamp),
timestamp: data.timestamp ? fromRfc3339WithNanoseconds(data.timestamp) : undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna run this past @ethanfrey who brought up the original issue that that hacky decodeOptionalTime() was supposed to solve?

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. Could you add a CHANGELOG entry for this?

packages/encoding/src/rfc3339.ts Outdated Show resolved Hide resolved
@webmaster128 webmaster128 merged commit bc79f8e into cosmos:main Dec 4, 2023
12 of 13 checks passed
@webmaster128
Copy link
Member

Released in 0.32.1 – thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants