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

feature: Add TimeTagToAny option to produce RFC3339 when decoding time into interface{} #496

Closed
ssuriyan7 opened this issue Feb 22, 2024 · 4 comments
Assignees

Comments

@ssuriyan7
Copy link
Contributor

ssuriyan7 commented Feb 22, 2024

Is your feature request related to a problem? Please describe.
When decoding a cbor data item, tagged with either tag 0 or tag 1, into an empty interface type, unmarshal returns a value of type time.Time. I would like a new decoding option with which unmarshal returns a RFC3339 string. This is needed to ensure compatibility in a project which expects unmarshal to return only certain types (bool, float64, string, []interface{}, map[string]interface{}, or nil).

Describe the solution you'd like
A new decode Option TimeTagToAnyMode whose default mode TimeTagToGoTime returns a time.Time value (current behavior). TimeTagToRFC3339String returns a time string in RFC3339 format and TimeTagToRFC3339NanoString returns a time string with nano seconds in RFC3339 format.

Additional context
I'd be happy to contribute the changes needed for this feature.

@fxamacker
Copy link
Owner

Hey @ssuriyan7 thanks for opening this feature request!

Please feel free to open a PR to implement TimeTagToAnyMode decoding option. Maybe with these option names:

  • TimeTagToTime
  • TimeTagToRFC3339
  • TimeTagToRFC3339Nano

@ssuriyan7
Copy link
Contributor Author

Waiting for #503 to merge as this option should be implemented on top of that change.

@fxamacker
Copy link
Owner

Hey @ssuriyan7 the PR got merged tonight:

@fxamacker
Copy link
Owner

Closed by #506

@fxamacker fxamacker changed the title feature: Add option to return RFC3339 string while decoding tag 0 & 1 into interface{} feature: Add TimeTagToAny option to produce RFC3339 when decoding time into interface{} May 26, 2024
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

No branches or pull requests

2 participants