Skip to content

Commit 0f72a6d

Browse files
committed
fixup! fix: derive running ws stop time from deadline
1 parent 24ccaee commit 0f72a6d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import cronstrue from "cronstrue"
66
import dayjs from "dayjs"
77
import duration from "dayjs/plugin/duration"
88
import relativeTime from "dayjs/plugin/relativeTime"
9+
import utc from "dayjs/plugin/utc"
910
import { FC } from "react"
1011
import { Link as RouterLink } from "react-router-dom"
1112
import { Workspace } from "../../api/typesGenerated"
@@ -14,6 +15,7 @@ import { extractTimezone, stripTimezone } from "../../util/schedule"
1415
import { isWorkspaceOn } from "../../util/workspace"
1516
import { Stack } from "../Stack/Stack"
1617

18+
dayjs.extend(utc)
1719
dayjs.extend(duration)
1820
dayjs.extend(relativeTime)
1921

@@ -34,18 +36,21 @@ export const Language = {
3436
}
3537
},
3638
autoStopDisplay: (workspace: Workspace): string => {
37-
const deadline = workspace.latest_build.deadline
39+
const deadline = dayjs(workspace.latest_build.deadline).utc()
40+
// a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
41+
// SEE: #1834
42+
const hasDeadline = deadline.year() > 1
3843
const ttl = workspace.ttl
3944

40-
if (isWorkspaceOn(workspace)) {
45+
if (isWorkspaceOn(workspace) && hasDeadline) {
4146
// Workspace is on --> derive from latest_build.deadline. Note that the
4247
// user may modify their workspace object (ttl) while the workspace is
4348
// running and depending on system semantics, the deadline may still
4449
// represent the previously defined ttl. Thus, we always derive from the
4550
// deadline as the source of truth.
46-
const now = dayjs()
51+
const now = dayjs().utc()
4752
if (now.isAfter(deadline)) {
48-
return "Workspace is shutting down now"
53+
return "Workspace is shutting down"
4954
} else {
5055
return now.to(deadline)
5156
}

0 commit comments

Comments
 (0)