Skip to content

Commit 9cc6d7b

Browse files
authored
fix: show explicit schedule stop time (#2171)
This does not fully resolve all requests in #2141, but just the piece of when the workspace is actually stopping. Next, we will adjust the default extension from 90 minutes to 4 hours. Lastly, we can look at customizing the extension time in the extension flow or with a pre-emptive prompt next to the stop time.
1 parent b390250 commit 9cc6d7b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import Typography from "@material-ui/core/Typography"
44
import ScheduleIcon from "@material-ui/icons/Schedule"
55
import cronstrue from "cronstrue"
66
import dayjs from "dayjs"
7+
import advancedFormat from "dayjs/plugin/advancedFormat"
78
import duration from "dayjs/plugin/duration"
89
import relativeTime from "dayjs/plugin/relativeTime"
10+
import timezone from "dayjs/plugin/timezone"
911
import utc from "dayjs/plugin/utc"
1012
import { FC } from "react"
1113
import { Link as RouterLink } from "react-router-dom"
@@ -15,27 +17,32 @@ import { extractTimezone, stripTimezone } from "../../util/schedule"
1517
import { isWorkspaceOn } from "../../util/workspace"
1618
import { Stack } from "../Stack/Stack"
1719

20+
dayjs.extend(advancedFormat)
1821
dayjs.extend(utc)
1922
dayjs.extend(duration)
2023
dayjs.extend(relativeTime)
24+
dayjs.extend(timezone)
2125

2226
export const Language = {
2327
autoStartDisplay: (schedule: string | undefined): string => {
2428
if (schedule) {
2529
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
30+
} else {
31+
return "Manual"
2632
}
27-
return "Manual"
2833
},
2934
autoStartLabel: (schedule: string | undefined): string => {
3035
const prefix = "Start"
36+
const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess()
3137

3238
if (schedule) {
33-
return `${prefix} (${extractTimezone(schedule)})`
39+
return `${prefix} (${dayjs().tz(timezone).format("z")})`
3440
} else {
3541
return prefix
3642
}
3743
},
3844
autoStopDisplay: (workspace: Workspace): string => {
45+
const schedule = workspace.autostart_schedule
3946
const deadline = dayjs(workspace.latest_build.deadline).utc()
4047
// a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
4148
// SEE: #1834
@@ -52,7 +59,8 @@ export const Language = {
5259
if (now.isAfter(deadline)) {
5360
return "Workspace is shutting down"
5461
} else {
55-
return now.to(deadline)
62+
const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess()
63+
return deadline.tz(timezone).format("HH:mm A")
5664
}
5765
} else if (!ttl || ttl < 1) {
5866
// If the workspace is not on, and the ttl is 0 or undefined, then the

0 commit comments

Comments
 (0)