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
Member

@IlyaFaer IlyaFaer commented Nov 12, 2020

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

Closes #3089

@google-cla google-cla bot added the cla: yes label Nov 12, 2020
@IlyaFaer IlyaFaer requested a review from tritone Nov 12, 2020
@IlyaFaer IlyaFaer marked this pull request as ready for review Nov 12, 2020
@IlyaFaer IlyaFaer requested a review from as a code owner Nov 12, 2020
Copy link
Collaborator

@tritone tritone left a comment

Do we need to make changes to load as well?

Loading

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

@tritone tritone commented Nov 12, 2020

Loading

datastore/save.go Outdated Show resolved Hide resolved
Loading
datastore/save.go Outdated Show resolved Hide resolved
Loading
datastore/save.go Outdated Show resolved Hide resolved
Loading
datastore/save_test.go Show resolved Hide resolved
Loading
tbpg
tbpg approved these changes Nov 17, 2020
Copy link
Collaborator

@tbpg tbpg left a comment

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

Loading

Copy link
Collaborator

@tritone tritone left a comment

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

Loading

@tritone tritone requested a review from crwilcox Nov 30, 2020
@crwilcox
Copy link
Collaborator

@crwilcox crwilcox commented Dec 2, 2020

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

Loading

@tbpg
Copy link
Collaborator

@tbpg 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.

Loading

@crwilcox
Copy link
Collaborator

@crwilcox crwilcox commented Dec 2, 2020

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

Loading

@tbpg
Copy link
Collaborator

@tbpg 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.

Loading

@crwilcox
Copy link
Collaborator

@crwilcox 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.

Loading

@tritone tritone merged commit 9cc1a66 into googleapis:master Dec 2, 2020
3 checks passed
Loading
@IlyaFaer IlyaFaer deleted the civil_support branch Dec 3, 2020
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

@dnerdy dnerdy Dec 3, 2020

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))

Loading

@codyoss
Copy link
Member

@codyoss codyoss commented Dec 3, 2020

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants