Skip to content

Commit

Permalink
fix(client): show "present" string if end date is not entered, also a…
Browse files Browse the repository at this point in the history
…dd to i18n locales

fix #653
  • Loading branch information
AmruthPillai committed Mar 12, 2022
1 parent 799f208 commit b5cd6c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"markdown": {
"help-text": "This section supports <1>markdown</1> formatting."
},
"date": {
"present": "Present"
},
"subtitle": "A free and open source resume builder.",
"title": "Reactive Resume",
"toast": {
Expand Down
5 changes: 4 additions & 1 deletion client/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DateRange } from '@reactive-resume/schema';
import dayjs from 'dayjs';
import isEmpty from 'lodash/isEmpty';
import isString from 'lodash/isString';
import { i18n } from 'next-i18next';

export const dateFormatOptions: string[] = [
'MMMM DD, YYYY',
Expand All @@ -21,6 +22,8 @@ export const dateFormatOptions: string[] = [
export const getRelativeTime = (timestamp: dayjs.ConfigType): string => dayjs(timestamp).toNow(true);

export const formatDateString = (date: string | DateRange, formatStr: string): string | null => {
const presentString = i18n?.t('common.date.present') ?? '';

if (isEmpty(date)) return null;

// If `date` is a string
Expand All @@ -39,5 +42,5 @@ export const formatDateString = (date: string | DateRange, formatStr: string): s
return `${dayjs(date.start).format(formatStr)} - ${dayjs(date.end).format(formatStr)}`;
}

return dayjs(date.start).format(formatStr);
return `${dayjs(date.start).format(formatStr)} - ${presentString}`;
};

0 comments on commit b5cd6c4

Please sign in to comment.