-
Notifications
You must be signed in to change notification settings - Fork 478
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
Handle when Lambda events are sent unix epoch dates in milliseconds #1710
Conversation
`save-state` and `set-output` commands used in GitHub Actions are deprecated and [GitHub recommends using environment files](https://github.blog/changelog/2023-07-24-github-actions-update-on-save-state-and-set-output-commands/). This PR updates the usage of `set-output` to `$GITHUB_OUTPUT` Instructions for envvar usage from GitHub docs: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
@@ -12,6 +12,7 @@ namespace Amazon.Lambda.Serialization.Json | |||
/// </summary> | |||
internal class JsonNumberToDateTimeDataConverter : JsonConverter | |||
{ | |||
private const long YEAR_5000_IN_SECONDS = 157753180800; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a little confused when checking the math. At first I assumed this was seconds-since-epoch, but appears to be since year 1. https://dotnetfiddle.net/0VesSV
Not a big deal functionally though, same principle applies. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment to make it clearer.
Issue #, if available:
#839
Description of changes:
When Kinesis streams are used to handle DynamoDB events they send the approximate date a unix epoch in milliseconds. When coming from a DynamoDB stream event they are seconds which is the normal format.
Since there isn't a way to detect the source of the event the serializers are updated to look to see if the
long
in the event would be greater then the number of seconds for the year5000
. If so then assume the value is in milliseconds. The other alternative I could have done is try to create theDateTime
with the millisecond epoch and if I got an out of range exception fallback to creating the DateTime from milliseconds but I wanted to avoid control flow by exceptions.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.