Skip to content

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

Merged
johnstcn merged 8 commits into
mainfrom
cj/codersdk-time-duration
Jun 2, 2022
Merged

chore: refactor time.Duration -> int64 milliseconds for FE consumption#1944
johnstcn merged 8 commits into
mainfrom
cj/codersdk-time-duration

Conversation

@johnstcn
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

presleyp commented Jun 1, 2022

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

Comment thread coderd/util/ptr/ptr.go Outdated
Comment thread site/src/testHelpers/entities.ts Outdated
Comment thread site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx Outdated
Comment thread site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx Outdated
Comment thread site/src/testHelpers/entities.ts Outdated
@johnstcn
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 force-pushed the cj/codersdk-time-duration branch from 717f451 to b9b3edf Compare June 2, 2022 09:46
@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.

6 participants