-
Notifications
You must be signed in to change notification settings - Fork 899
feat: edit workspace schedule page #1701
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
Changes from 1 commit
58ecefa
3f73a6c
30dff81
ecc6792
c0f28c3
d61a332
f60f59b
406d465
a6dff9d
7a14859
1158645
7a050db
1166924
947b4a0
4764e5c
ebc4965
747b52f
854f781
8bedc8a
6afbb74
5bacfb1
5b3adc3
81e7e05
531df3e
7ae590a
262d9e3
5d22197
eda8ad8
f59f056
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,83 @@ export const stripTimezone = (raw: string): string => { | |
|
||
/** | ||
* extractTimezone returns a leading timezone from a schedule string if one is | ||
* specified; otherwise DEFAULT_TIMEZONE | ||
* specified; otherwise the specified defaultTZ | ||
*/ | ||
export const extractTimezone = (raw: string): string => { | ||
export const extractTimezone = (raw: string, defaultTZ = DEFAULT_TIMEZONE): string => { | ||
greyscaled marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const matches = raw.match(/CRON_TZ=\S*\s/g) | ||
|
||
if (matches && matches.length) { | ||
return matches[0].replace(/CRON_TZ=/, "").trim() | ||
} else { | ||
return DEFAULT_TIMEZONE | ||
return defaultTZ | ||
} | ||
} | ||
|
||
/** | ||
* WeeklyFlag is an array represnting which days of the week are set or flagged | ||
greyscaled marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @remarks | ||
* | ||
* A WeeklyFlag has an array size of 7 and should never have its size modified. | ||
* The 0th index is Sunday | ||
* The 6th index is Saturday | ||
*/ | ||
export type WeeklyFlag = [boolean, boolean, boolean, boolean, boolean, boolean, boolean] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: This type is very helpful and needed because we get some static analysis on the size of the arrays. The semantic meaning is like a bit mask where in the array, each index corresponds to a day and whether that day is "set" (true) or unset "false". So in other words, it goes from Sunday -> Saturday. This sort of thing is easier to understand than bit masks, and maps very cleanly to setting values for the checkbox group. |
||
|
||
/** | ||
* dowToWeeklyFlag converts a dow cron string to a WeeklyFlag array. | ||
* | ||
* @example | ||
* | ||
* dowToWeeklyFlag("1") // [false, true, false, false, false, false, false] | ||
* dowToWeeklyFlag("1-5") // [false, true, true, true, true, true, false] | ||
* dowToWeeklyFlag("1,3-4,6") // [false, true, false, true, true, false, true] | ||
*/ | ||
export const dowToWeeklyFlag = (dow: string): WeeklyFlag => { | ||
if (dow === "*") { | ||
return [true, true, true, true, true, true, true] | ||
} | ||
|
||
const results: WeeklyFlag = [false, false, false, false, false, false, false] | ||
|
||
const commaSeparatedRangeOrNum = dow.split(",") | ||
|
||
for (const rangeOrNum of commaSeparatedRangeOrNum) { | ||
const flags = processRangeOrNum(rangeOrNum) | ||
|
||
flags.forEach((value, idx) => { | ||
if (value) { | ||
results[idx] = true | ||
} | ||
}) | ||
} | ||
|
||
return results | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: Before reading this function, I'd read https://github.com/coder/coder/pull/1701/files#r882361592 This builds upon |
||
|
||
/** | ||
* processRangeOrNum is a helper for dowToWeeklyFlag. It processes a range or | ||
* number (modulo 7) into a Weeklyflag boolean array. | ||
* | ||
* @example | ||
* | ||
* processRangeOrNum("1") // [false, true, false, false, false, false, false] | ||
* processRangeOrNum("1-5") // [false, true, true, true, true, true, false] | ||
*/ | ||
const processRangeOrNum = (rangeOrNum: string): WeeklyFlag => { | ||
const result: WeeklyFlag = [false, false, false, false, false, false, false] | ||
|
||
const isRange = /^[0-9]-[0-9]$/.test(rangeOrNum) | ||
|
||
if (isRange) { | ||
const [first, last] = rangeOrNum.split("-") | ||
|
||
for (let i = Number(first); i <= Number(last); i++) { | ||
result[i % 7] = true | ||
} | ||
} else { | ||
result[Number(rangeOrNum) % 7] = true | ||
} | ||
|
||
return result | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: This is a "private" method (only meant to be used in I'd review this before I'd review The algorithm does the following:
and returns the associated I have a method that focuses just on number or range, because in the parent function
So this function is called in a loop on each comma-separated group. |
Uh oh!
There was an error while loading. Please reload this page.