Misc fixes from qa pass (#5650)

This commit is contained in:
Tom Moor
2023-08-04 23:40:36 -04:00
committed by GitHub
parent 80acc16791
commit 042ea7b61f
11 changed files with 96 additions and 54 deletions

View File

@@ -253,7 +253,7 @@
"Find": "Find",
"Match case": "Match case",
"Enable regex": "Enable regex",
"More options": "More options",
"Replace options": "Replace options",
"Replacement": "Replacement",
"Replace": "Replace",
"Replace all": "Replace all",
@@ -552,6 +552,7 @@
"All users see the same publicly shared view": "All users see the same publicly shared view",
"Custom link": "Custom link",
"The document will be accessible at <2>{{url}}</2>": "The document will be accessible at <2>{{url}}</2>",
"More options": "More options",
"Close": "Close",
"{{ teamName }} is using {{ appName }} to share documents, please login to continue.": "{{ teamName }} is using {{ appName }} to share documents, please login to continue.",
"Are you sure you want to delete the <em>{{ documentTitle }}</em> template?": "Are you sure you want to delete the <em>{{ documentTitle }}</em> template?",

View File

@@ -1,5 +1,12 @@
/* eslint-disable import/no-duplicates */
import { subDays, subMonths, subWeeks, subYears } from "date-fns";
import {
addSeconds,
formatDistanceToNow,
subDays,
subMonths,
subWeeks,
subYears,
} from "date-fns";
import {
cs,
de,
@@ -40,6 +47,44 @@ export function subtractDate(date: Date, period: DateFilter) {
}
}
/**
* Returns a humanized relative time string for the given date.
*
* @param date The date to convert
* @param options The options to pass to date-fns
* @returns The relative time string
*/
export function dateToRelative(
date: Date | number,
options?: {
includeSeconds?: boolean;
addSuffix?: boolean;
locale?: Locale | undefined;
shorten?: boolean;
}
) {
const now = new Date();
const parsedDateTime = new Date(date);
// Protect against "in less than a minute" when users computer clock is off.
const normalizedDateTime =
parsedDateTime > now && parsedDateTime < addSeconds(now, 60)
? now
: parsedDateTime;
const output = formatDistanceToNow(normalizedDateTime, options);
// Some tweaks to make english language shorter.
if (options?.shorten) {
return output
.replace("about", "")
.replace("less than a minute ago", "just now")
.replace("minute", "min");
}
return output;
}
/**
* Converts a locale string from Unicode CLDR format to BCP47 format.
*