Skip to content

Conversation

@Itz-Agasta
Copy link

Description

This PR fixes a bug where timestamps returned by MongoDB with year 0 caused json.Marshal to fail with the error:

"Time.MarshalJSON: year outside of range [0,9999]"

The ReformatDate function in utils/typeutils/reformat.go previously only adjusted negative years and years > 9999. Year == 0 slipped through unmodified and triggered the runtime error.

Fixes #421

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Ran: go build ./... -> success

@Itz-Agasta Itz-Agasta changed the base branch from master to staging October 4, 2025 17:46
@vaibhav-datazip vaibhav-datazip added the hacktoberfest Issues open for Hacktoberfest contributors label Oct 7, 2025
parsed = parsed.AddDate(0-parsed.Year(), 0, 0)
// even after data being parsed if year doesn't lie in range [1,9999] it failed to get marshaled
if parsed.Year() <= 0 {
parsed = parsed.AddDate(1-parsed.Year(), 0, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Itz-Agasta
hey can you provide the example using which you tested? I mean if possible the mongodb script if possible.

@ImDoubD-datazip
Copy link
Collaborator

closing this. The PR for this has been raised by @vaibhav-datazip .
PR: #592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest Issues open for Hacktoberfest contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: MongoDB timestamps with year 0 cause JSON marshaling error

3 participants