This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
DEVPROD-838: Add user time format preference #2280
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc2f62a
Respect timeFormat
sophstad d7439bd
Merge branch 'main' of https://github.com/evergreen-ci/spruce into DE…
sophstad 17235c0
Add test
sophstad 531b8c0
Remove labels for existing fields
sophstad 3e570c7
Use time format constant
sophstad fde4455
Merge branch 'main' of https://github.com/evergreen-ci/spruce into DE…
sophstad 4ff87cf
Remove import cycle
sophstad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ export type DateCopyOptions = { | |
omitSeconds?: boolean; | ||
omitTimezone?: boolean; | ||
dateFormat?: string; | ||
timeFormat?: string; | ||
}; | ||
|
||
/** | ||
|
@@ -111,7 +112,7 @@ export type DateCopyOptions = { | |
* @param options.omitSeconds - if true, will not return the seconds | ||
* @param options.omitTimezone - if true, will not return the timezone | ||
* @param options.dateFormat - a date format string, such as "MMM d, yyyy" | ||
* @returns - a string representing the date in the format of "MMM d, yyyy h:mm:ss a z" | ||
* @returns - a string representing the date in either the user's specified format or the default, "MMM d, yyyy h:mm:ss aa z" | ||
*/ | ||
export const getDateCopy = ( | ||
time: string | number | Date, | ||
|
@@ -121,15 +122,19 @@ export const getDateCopy = ( | |
return ""; | ||
} | ||
const { dateOnly, omitSeconds, omitTimezone, tz } = options || {}; | ||
let { dateFormat } = options || {}; | ||
let { dateFormat, timeFormat } = options || {}; | ||
if (!dateFormat) { | ||
dateFormat = "MMM d, yyyy"; | ||
} | ||
if (!timeFormat) { | ||
timeFormat = "h:mm:ss aa"; | ||
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. nit. could we reuse the TimeFormat enum declared above instead of duplicating here? |
||
} | ||
if (omitSeconds) { | ||
timeFormat = timeFormat.replace(":ss", ""); | ||
} | ||
const finalDateFormat = dateOnly | ||
? dateFormat | ||
: `${dateFormat}, h:mm${omitSeconds ? "" : ":ss"} aa${ | ||
omitTimezone ? "" : " z" | ||
}`; | ||
: `${dateFormat}, ${timeFormat}${omitTimezone ? "" : " z"}`; | ||
if (tz) { | ||
return format(utcToZonedTime(time, tz), finalDateFormat, { | ||
timeZone: tz, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch!