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

chore: refactor time.Duration -> int64 milliseconds for FE consumption #1944

Merged
merged 8 commits into from
Jun 2, 2022

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jun 1, 2022

This PR changes all public-facing codersdk types to use a plain int64 (milliseconds) instead of time.Duration (nanoseconds) as this is the conventional type in the FE world.
Also makes autostart_schedule a *string as it may not be present.
Also also adds a utils/ptr package with some useful methods.

@johnstcn johnstcn requested a review from a team June 1, 2022 14:29
@johnstcn johnstcn self-assigned this Jun 1, 2022
@johnstcn johnstcn removed the request for review from a team June 1, 2022 14:30
@Emyrk
Copy link
Member

Emyrk commented Jun 1, 2022

Do you want to make it an actual type and write a json marshal?

type MillisecondDuration time.Duration

This means the sdk and cli would have an actual duration type.

@johnstcn
Copy link
Member Author

johnstcn commented Jun 1, 2022

Do you want to make it an actual type and write a json marshal?

type MillisecondDuration time.Duration

This means the sdk and cli would have an actual duration type.

Maybe later; doing it with a type alias means you lose all the existing methods on the type and struct-embedding can get weird.

@johnstcn johnstcn marked this pull request as ready for review June 1, 2022 16:32
@johnstcn johnstcn requested a review from a team as a code owner June 1, 2022 16:32
@johnstcn johnstcn requested a review from a team June 1, 2022 16:36
@presleyp
Copy link
Contributor

presleyp commented Jun 1, 2022

A lot of the stories say "228 years after start" now, maybe they need to be updated?

coderd/util/ptr/ptr.go Outdated Show resolved Hide resolved
site/src/testHelpers/entities.ts Outdated Show resolved Hide resolved
@johnstcn
Copy link
Member Author

johnstcn commented Jun 1, 2022

A lot of the stories say "228 years after start" now, maybe they need to be updated?

I think I've repaired the temporal anomaly now. :-)

@johnstcn johnstcn requested a review from greyscaled June 1, 2022 21:28
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

LGTM!

transition: "stop",
},
autostart_schedule: undefined,
ttl_ms: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

I'm unfamiliar with stories, but since we're using omitempty, should we perhaps not define these here? There's a slight change in semantic meaning between x: undefined and omitting it entirely. In the former case, the key is defined on the object and does not mimic API behavior 1:1.

@johnstcn johnstcn merged commit dcf03d8 into main Jun 2, 2022
@johnstcn johnstcn deleted the cj/codersdk-time-duration branch June 2, 2022 10:23
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
#1944)

* Changes all public-facing codersdk types to use a plain int64 (milliseconds) instead of time.Duration.
* Makes autostart_schedule a *string as it may not be present.
* Adds a utils/ptr package with some useful methods.
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.

None yet

6 participants