cbor icon indicating copy to clipboard operation
cbor copied to clipboard

feature: Add option to return RFC3339 string while decoding tag 0 & 1 into interface{}

Open ssuriyan7 opened this issue 1 year ago • 2 comments

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.

ssuriyan7 avatar Feb 22 '24 04:02 ssuriyan7

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

fxamacker avatar Feb 24 '24 16:02 fxamacker

Waiting for https://github.com/fxamacker/cbor/pull/503 to merge as this option should be implemented on top of that change.

ssuriyan7 avatar Mar 06 '24 02:03 ssuriyan7

Hey @ssuriyan7 the PR got merged tonight:

  • #503

fxamacker avatar Mar 14 '24 01:03 fxamacker

Closed by #506

fxamacker avatar Apr 01 '24 02:04 fxamacker