Search code examples
gogoogle-cloud-platformgoogle-cloud-datastore

Dates locale in Google Cloud Datastore


I'm storing dates in Google Cloud Datastore using the Go client library. The dates are managed in the go code as time.Time type. What is a bit unclear from the documentation is how the dates are retrieved. The docs says they are retrieved as local time and my question is: "local time of the server or the client?"

Also, I would expect the date to be retrieved with the same locale as saved.


Solution

  • The datastore package sets the time's location to the local location of the Go program.

    More details:

    Times are saved as Unix nanoseconds in the datastore service. The location is not saved.

    The datastore package uses the time.Unix function to convert Unix nanoseconds to a time.Time value. The time.Unix function sets the location to the local location.