-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add year to date description when not current year.
- Loading branch information
1 parent
9f00e0a
commit 6b892dc
Showing
3 changed files
with
21 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
packages/calendar/src/features/travel-calendar/util/DateDescriptionFormatter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import { format, Locale } from "date-fns"; | ||
import { format, isSameYear, Locale } from "date-fns"; | ||
|
||
export const formatDateDescription = (date: Date, locale: Locale) => { | ||
export const formatDateDescription = ( | ||
date: Date, | ||
today: Date, | ||
locale: Locale | ||
) => { | ||
const year = isSameYear(date, today) ? "" : " y"; | ||
if (locale.code.startsWith("en")) { | ||
return format(date, "eee MMM d", { locale }); | ||
return format(date, "eee MMM d" + year, { locale }).replace(".", ""); | ||
} else { | ||
return format(date, "eee d MMM", { locale }); | ||
return format(date, "eee d MMM" + year, { locale }).replace(".", ""); | ||
} | ||
}; | ||
|
||
export const formatDateDescriptionLong = (date: Date, locale: Locale) => { | ||
export const formatDateDescriptionLong = ( | ||
date: Date, | ||
today: Date, | ||
locale: Locale | ||
) => { | ||
const year = isSameYear(date, today) ? "" : " y"; | ||
if (locale.code.startsWith("en")) { | ||
return format(date, "eeee MMMM d", { locale }); | ||
return format(date, "eeee MMMM d" + year, { locale }); | ||
} else { | ||
return format(date, "eeee d MMMM", { locale }); | ||
return format(date, "eeee d MMMM" + year, { locale }); | ||
} | ||
}; |