From c9008c16b0cbc83aa629a55bd4af9688a8bab67e Mon Sep 17 00:00:00 2001 From: G r e y Date: Wed, 8 Jun 2022 15:31:46 +0000 Subject: [PATCH 1/2] fix: show explicit schedule stop time 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. --- .../WorkspaceSchedule/WorkspaceSchedule.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 8ea1cc01c67c9..96f0f47dc419b 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -4,8 +4,10 @@ import Typography from "@material-ui/core/Typography" import ScheduleIcon from "@material-ui/icons/Schedule" import cronstrue from "cronstrue" import dayjs from "dayjs" +import advancedFormat from "dayjs/plugin/advancedFormat" import duration from "dayjs/plugin/duration" import relativeTime from "dayjs/plugin/relativeTime" +import timezone from "dayjs/plugin/timezone" import utc from "dayjs/plugin/utc" import { FC } from "react" import { Link as RouterLink } from "react-router-dom" @@ -15,27 +17,31 @@ import { extractTimezone, stripTimezone } from "../../util/schedule" import { isWorkspaceOn } from "../../util/workspace" import { Stack } from "../Stack/Stack" +dayjs.extend(advancedFormat) dayjs.extend(utc) dayjs.extend(duration) dayjs.extend(relativeTime) +dayjs.extend(timezone) export const Language = { autoStartDisplay: (schedule: string | undefined): string => { if (schedule) { return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false }) + } else { + return "Manual" } - return "Manual" }, autoStartLabel: (schedule: string | undefined): string => { const prefix = "Start" if (schedule) { - return `${prefix} (${extractTimezone(schedule)})` + return `${prefix} (${dayjs().tz(extractTimezone(schedule)).format("z")})` } else { return prefix } }, autoStopDisplay: (workspace: Workspace): string => { + const schedule = workspace.autostart_schedule const deadline = dayjs(workspace.latest_build.deadline).utc() // a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"' // SEE: #1834 @@ -52,7 +58,8 @@ export const Language = { if (now.isAfter(deadline)) { return "Workspace is shutting down" } else { - return now.to(deadline) + const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess() + return deadline.tz(timezone).format("HH:mm A") } } else if (!ttl || ttl < 1) { // If the workspace is not on, and the ttl is 0 or undefined, then the From f6b4d0d38a0194c41033828b3247cc659baddd53 Mon Sep 17 00:00:00 2001 From: G r e y Date: Wed, 8 Jun 2022 15:38:46 +0000 Subject: [PATCH 2/2] fixup! fix: show explicit schedule stop time --- site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx index 96f0f47dc419b..335043fb1da74 100644 --- a/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx +++ b/site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx @@ -33,9 +33,10 @@ export const Language = { }, autoStartLabel: (schedule: string | undefined): string => { const prefix = "Start" + const timezone = schedule ? extractTimezone(schedule) : dayjs.tz.guess() if (schedule) { - return `${prefix} (${dayjs().tz(extractTimezone(schedule)).format("z")})` + return `${prefix} (${dayjs().tz(timezone).format("z")})` } else { return prefix }