Skip to content

Commit

Permalink
Add documentation for utils/dates.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Dec 9, 2024
1 parent 6f56fdf commit 1081ce6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/src/utils/dates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { format, parseISO } from "date-fns";

/**
* Converts a Galaxy time string to a Date object.
* @param {string} galaxyTime - The Galaxy time string in ISO format.
* @returns {Date} The parsed Date object.
*/
export function galaxyTimeToDate(galaxyTime: string): Date {
// We likely don't have tzinfo, but this will always be UTC coming
// from Galaxy so append Z to assert that prior to parsing
Expand All @@ -10,10 +15,20 @@ export function galaxyTimeToDate(galaxyTime: string): Date {
return date;
}

/**
* Formats a UTC Date object into a human-readable string.
* @param {Date} utcDate - The UTC Date object.
* @returns {string} The formatted date string.
*/
export function localizeUTCPretty(utcDate: Date): string {
return format(utcDate, "eeee MMM do H:mm:ss yyyy zz");
}

/**
* Converts a Galaxy time string to a human-readable formatted date string.
* @param {string} galaxyTime - The Galaxy time string in ISO format.
* @returns {string} The formatted date string.
*/
export function formatGalaxyPrettyDateString(galaxyTime: string): string {
const date = galaxyTimeToDate(galaxyTime);
return localizeUTCPretty(date);
Expand Down

0 comments on commit 1081ce6

Please sign in to comment.