mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
> Related issue: #9956 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Martin Angers <martin.n.angers@gmail.com> Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com> Co-authored-by: Roberto Dip <rroperzh@gmail.com> Co-authored-by: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com> Co-authored-by: Dante Catalfamo <43040593+dantecatalfamo@users.noreply.github.com> Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
25 lines
826 B
TypeScript
25 lines
826 B
TypeScript
import { format, formatDistanceToNow, intlFormat } from "date-fns";
|
|
|
|
/** Utility to create a string from a date in this format:
|
|
`Uploaded .... ago`
|
|
*/
|
|
export const uploadedFromNow = (date: string) => {
|
|
// NOTE: Malformed dates will result in errors. This is expected "fail loudly" behavior.
|
|
return `Uploaded ${formatDistanceToNow(new Date(date))} ago`;
|
|
};
|
|
|
|
/** Utility to create a string from a date in this format:
|
|
`.... ago`
|
|
*/
|
|
export const dateAgo = (date: string) => {
|
|
// NOTE: Malformed dates will result in errors. This is expected "fail loudly" behavior.
|
|
return `${formatDistanceToNow(new Date(date))} ago`;
|
|
};
|
|
|
|
/**
|
|
* returns a date in the format of 'MonthName Date, Year'
|
|
* @example "January 01, 2024"
|
|
*/
|
|
export const monthDayYearFormat = (date: string) => {
|
|
return format(date, "MMMM d, yyyy");
|
|
};
|