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

feat(datastore): support civil package types save #3202

Merged
merged 8 commits into from Dec 2, 2020

Conversation

IlyaFaer
Copy link

Support saving properties of civil package types: Date, Time and DateTime.

Closes #3089

@IlyaFaer IlyaFaer added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: datastore Issues related to the Datastore API. labels Nov 12, 2020
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 12, 2020
@IlyaFaer IlyaFaer marked this pull request as ready for review November 12, 2020 07:41
@IlyaFaer IlyaFaer requested a review from a team as a code owner November 12, 2020 07:41
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Do we need to make changes to load as well?

datastore/save.go Outdated Show resolved Hide resolved
datastore/save.go Outdated Show resolved Hide resolved
datastore/save.go Outdated Show resolved Hide resolved
@tritone
Copy link
Contributor

tritone commented Nov 12, 2020

FYI @BenWhitehead @crwilcox

datastore/save.go Outdated Show resolved Hide resolved
datastore/save.go Outdated Show resolved Hide resolved
datastore/save.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tbpg tbpg left a comment

Choose a reason for hiding this comment

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

LGTM. Let's make sure to have a user test with a pseudo-version before tagging a release. Please wait for @tritone.

Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Looks good to me. @crwilcox @BenWhitehead could you please take a look before we merge?

@crwilcox
Copy link
Contributor

crwilcox commented Dec 2, 2020

What is the experience for someone who doesn't have civil?

@tbpg
Copy link
Contributor

tbpg commented Dec 2, 2020

What is the experience for someone who doesn't have civil?

No changes. This should only change behavior for people who are using civil.

@crwilcox
Copy link
Contributor

crwilcox commented Dec 2, 2020

@tbpg so there is no chance of panics or anything from a missing import?

@tbpg
Copy link
Contributor

tbpg commented Dec 2, 2020

@crwilcox, no. I don't think there is a way to cause a panic from a missing import in Go. If something is used, it is imported, otherwise there is a compile-time error.

@crwilcox
Copy link
Contributor

crwilcox commented Dec 2, 2020

Thank you for clearing things up @tbpg. I had missed that the package already depended on civil which is why I was a bit confused how this worked. lgtm.

@tritone tritone merged commit 9cc1a66 into googleapis:master Dec 2, 2020
@IlyaFaer IlyaFaer deleted the civil_support branch December 3, 2020 08:43
Comment on lines +386 to +394
case typeOfCivilDate:
date := civil.DateOf(pValue.(time.Time))
v.Set(reflect.ValueOf(date))
case typeOfCivilDateTime:
dateTime := civil.DateTimeOf(pValue.(time.Time))
v.Set(reflect.ValueOf(dateTime))
case typeOfCivilTime:
timeVal := civil.TimeOf(pValue.(time.Time))
v.Set(reflect.ValueOf(timeVal))
Copy link

Choose a reason for hiding this comment

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

Thank you @IlyaFaer for working on this!

I'm following up via #3089.

There's an issue loading civil dates and times on a machine when the timezone is set to anything other than UTC. Time properties are loaded in a machine's local location (see #916) and therefore need to be converted to UTC before using them to create civil values.

I think this is the adjustment that's needed:

case typeOfCivilDate:
	date := civil.DateOf(pValue.(time.Time).In(time.UTC))
	v.Set(reflect.ValueOf(date))
case typeOfCivilDateTime:
	dateTime := civil.DateTimeOf(pValue.(time.Time).In(time.UTC))
	v.Set(reflect.ValueOf(dateTime))
case typeOfCivilTime:
	timeVal := civil.TimeOf(pValue.(time.Time).In(time.UTC))
	v.Set(reflect.ValueOf(timeVal))

@codyoss
Copy link
Member

codyoss commented Dec 3, 2020

@dnerdy Would you please open an issue for this, thanks for finding this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datastore: support civil.Date for properties
6 participants