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

Add support for local timezone on ISO8601 output #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fetzi
Copy link

@fetzi fetzi commented Mar 21, 2018

To be able to provide a appropriate time representation the fix
conversion to UTC is removed. time.Time holds the information about the timezone corresponding to the actual object and this timezone should be used for jsonapi representation.

Also the time.RFC3339 format is used instead of the custom format constant.

to be able to provide a appropriate time representation the fix
conversion to UTC is removed. Also the time.RFC3339 format is used
instead of a custom format constant
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@fetzi
Copy link
Author

fetzi commented Mar 21, 2018

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Contributor

@aren55555 aren55555 left a comment

Choose a reason for hiding this comment

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

Given that the JSON API spec has a recommendation for using ISO 8601, I think we should try to stick to ISO 8601.

My simple understanding of ISO 8601 vs RFC 3339 is that they are very closely related however RFC 3339 is a simplification/profile of ISO 8601. I'm inclined to think that this library should aim to support ISO 8601 and that custom/wrapper golang types should be used to serialize RFC 3339 when needed by your use case.

It seems like what you are really after is the correct serialization/deserialization of the time zone information that was specified in the originating time value (whether that be in the JSON payload or a go variable of type time.Time). I think there should be a way to accomplish this without switching from ISO 8601 to RFC 3339.

@fetzi
Copy link
Author

fetzi commented Mar 22, 2018

@aren55555 yeah, the main goal of this PR is to allow a correct serialization/deserialization of the timezone information.

According to the date formatting:
I've tried to modify the iso8601TimeFormat constant to allow the serialization/deserialization of the timezone information and the updated constant defines the exact same format as time.RFC3339. Therefore I didn't see the need for a custom constant any more.

But if you favour the custom constant, it is absolutely no problem to use an updated version of it:
iso8601TimeFormat = "2006-01-02T15:04:05Z07:00"

What do you think?

@fetzi
Copy link
Author

fetzi commented May 23, 2018

@aren55555 any update on this PR?

@aren55555
Copy link
Contributor

I'm pretty sure time.Time implements the json.Marshaler and json.Unmarshaler interfaces with time.RFC3339... meaning if you just remove all this it should just end up in that format.

@fetzi
Copy link
Author

fetzi commented Sep 18, 2018

@aren55555 Parsing the time.Time values is done manually by calling time.Parse (needs layout information).

In the response part I tried to remove the Format call but then my added test case breaks. So I can confirm that the code in this PR is required to implement the expected behavior.

@penguinxr2
Copy link

I ran into the need for this as well, forcing times to UTC was unexpected.

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.

4 participants