mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-28 22:03:30 +03:00
Time units shorthand (#3862)
This commit is contained in:
parent
9a42f8b2eb
commit
198e72612c
@ -17,9 +17,9 @@ export function createTimeAgoStore(
|
||||
if (seconds < 10) {
|
||||
set('just now');
|
||||
} else if (seconds < 60) {
|
||||
set(`< 1 minute ${addSuffix ? ' ago' : ''}`);
|
||||
set(`< 1 min ${addSuffix ? ' ago' : ''}`);
|
||||
} else {
|
||||
set(formatDistanceToNowStrict(date, { addSuffix }));
|
||||
set(customFormatDistance(date, addSuffix));
|
||||
}
|
||||
timeoutId = window.setTimeout(() => {
|
||||
updateStore();
|
||||
@ -46,3 +46,27 @@ function getSecondsUntilUpdate(seconds: number) {
|
||||
return 3600;
|
||||
}
|
||||
}
|
||||
|
||||
// SHORTHAND WORDS
|
||||
const unitShorthandMap: Record<string, string> = {
|
||||
second: 'sec',
|
||||
seconds: 'sec',
|
||||
minute: 'min',
|
||||
minutes: 'min',
|
||||
hour: 'hr',
|
||||
hours: 'hr',
|
||||
day: 'day',
|
||||
days: 'days',
|
||||
month: 'mo',
|
||||
months: 'mo',
|
||||
year: 'yr',
|
||||
years: 'yr'
|
||||
};
|
||||
|
||||
function customFormatDistance(date: Date, addSuffix: boolean): string {
|
||||
const distance = formatDistanceToNowStrict(date, { addSuffix });
|
||||
return distance.replace(
|
||||
/\b(seconds?|minutes?|hours?|days?|months?|years?)\b/g,
|
||||
(match) => unitShorthandMap[match]
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user