feat: #ENABLING-645 complete the useDate hook with date format spec methods - #520
Open
pascalsaussier-edifice wants to merge 1 commit into
Open
feat: #ENABLING-645 complete the useDate hook with date format spec methods#520pascalsaussier-edifice wants to merge 1 commit into
pascalsaussier-edifice wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes the useDate hook in @edifice.io/react by adding one formatter per design-system date format (friendly/simple/raw/calendar/week), plus robust conversion helpers, while keeping the previous API available via @deprecated methods.
Changes:
- Added new date-format methods (
formatRelativeDate(Time),formatLongDate(Time),formatRawDate(Time),formatCalendarDate,formatWeek) and conversion helpers (toJsDate,toTimestamp,toIsoDate,toMongoDate). - Added Vitest coverage for the new API surface and ensured deprecated methods still behave as before.
- Added
date.*i18n keys for EN/FR in the docs app and updateduseDateStorybook documentation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| packages/react/src/hooks/useDate/useDate.ts | Implements the new formatters/converters and updates dayjs plugin imports to include .js. |
| packages/react/src/hooks/useDate/useDate.spec.tsx | Adds tests validating new formatters, conversions, and deprecated method compatibility. |
| packages/react/src/hooks/useDate/useDate.mdx | Updates Storybook docs to describe the new API and deprecations. |
| apps/docs/i18n.ts | Adds EN/FR date.* keys used by the new formatters in the docs environment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+47
| * Beyond this duration (in hours), friendly formats stop using a relative | ||
| * wording ("3 hours ago") and switch to a day-based wording ("yesterday", | ||
| * weekday, date). Matches the date format spec. | ||
| */ |
Comment on lines
+144
to
+166
| computedDate.isToday() || | ||
| Math.abs(now.diff(computedDate, 'hour')) <= FRIENDLY_RELATIVE_MAX_HOURS | ||
| ) { | ||
| return computedDate.fromNow(); | ||
| } | ||
|
|
||
| let patternKey: string; | ||
| if (computedDate.isSame(now.subtract(1, 'day'), 'day')) { | ||
| patternKey = 'yesterday'; | ||
| } else if (computedDate.isSame(now.add(1, 'day'), 'day')) { | ||
| patternKey = 'tomorrow'; | ||
| } else if (Math.abs(now.diff(computedDate, 'day')) < 7) { | ||
| patternKey = 'weekday'; | ||
| } else if (computedDate.isSame(now, 'year')) { | ||
| patternKey = 'currentYear'; | ||
| } else { | ||
| patternKey = 'otherYear'; | ||
| } | ||
|
|
||
| return computedDate.format(t(`date.friendly.${keyPrefix}.${patternKey}`)); | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+195
to
+203
| const formatLongDateTime = useCallback( | ||
| (date: CoreDate): string => { | ||
| const computedDate = toComputedDate(date); | ||
| return computedDate?.isValid() | ||
| ? computedDate.format(t('date.long.datetime')) | ||
| : ''; | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+211
to
+219
| const formatLongDate = useCallback( | ||
| (date: CoreDate): string => { | ||
| const computedDate = toComputedDate(date); | ||
| return computedDate?.isValid() | ||
| ? computedDate.format(t('date.long.date')) | ||
| : ''; | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+226
to
+234
| const formatRawDate = useCallback( | ||
| (date: CoreDate): string => { | ||
| const computedDate = toComputedDate(date); | ||
| return computedDate?.isValid() | ||
| ? computedDate.format(t('date.raw.date')) | ||
| : ''; | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+241
to
+249
| const formatRawDateTime = useCallback( | ||
| (date: CoreDate): string => { | ||
| const computedDate = toComputedDate(date); | ||
| return computedDate?.isValid() | ||
| ? computedDate.format(t('date.raw.datetime')) | ||
| : ''; | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+271
to
+278
| const period = computedDate.isSame(now, 'year') | ||
| ? 'currentYear' | ||
| : 'otherYear'; | ||
|
|
||
| return computedDate.format(t(`date.calendar.${variant}.${period}`)); | ||
| }, | ||
| [toComputedDate, t], | ||
| ); |
Comment on lines
+291
to
+294
| const now = dayjs().locale(currentLanguage as string); | ||
| const targetWeekStart = computedDate.startOf('week'); | ||
| const weekDiff = targetWeekStart.diff(now.startOf('week'), 'week'); | ||
|
|
pascalsaussier-edifice
force-pushed
the
develop-enabling
branch
from
June 25, 2026 12:27
888f7eb to
fedd736
Compare
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
from
June 25, 2026 12:28
9dad3e9 to
4448443
Compare
damienromito
previously approved these changes
Jun 30, 2026
damienromito
left a comment
Member
There was a problem hiding this comment.
propre ! c'est une bonne pratique de commencer à deprecier , ça nous facilitera le travail. Par contre il faudra ajouter une tâche de migration/clean sinon on va rester comme ça très longtemps.
pascalsaussier-edifice
force-pushed
the
develop-enabling
branch
2 times, most recently
from
July 1, 2026 09:29
ab73b57 to
434033a
Compare
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
from
July 1, 2026 13:27
4448443 to
1df492b
Compare
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
from
July 16, 2026 13:47
1df492b to
4913f4c
Compare
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
from
July 27, 2026 15:36
4913f4c to
b6be60e
Compare
pascalsaussier-edifice
force-pushed
the
develop-enabling
branch
from
August 3, 2026 08:57
9333533 to
4b64efa
Compare
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
2 times, most recently
from
August 6, 2026 13:19
b52d01d to
fbdc1bf
Compare
pascalsaussier-edifice
requested review from
Headan,
david-cc,
jcbe-ode and
theovgl
August 12, 2026 12:28
jcbe-ode
previously approved these changes
Aug 13, 2026
pascalsaussier-edifice
dismissed
jcbe-ode’s stale review
August 25, 2026 15:19
The merge-base changed after approval.
pascalsaussier-edifice
force-pushed
the
develop-enabling
branch
from
August 25, 2026 15:19
2b0b45c to
590c081
Compare
…ethods Expose one method per format of the Edifice date format spec, plus conversion helpers, so apps stop reimplementing date formatting. - Friendly: formatRelativeDateTime, formatRelativeDate - Simple/textual: formatLongDateTime, formatLongDate - Raw: formatRawDate, formatRawDateTime - Calendar: formatCalendarDate(variant 'full' | 'short' | 'abbr') - Week: formatWeek - Conversions: toJsDate, toTimestamp, toIsoDate, toMongoDate - Deprecate fromNow/formatTimeAgo/formatDate (kept, non-breaking) - Drive all wordings/patterns from i18n (en + fr reference keys), no hardcoded text - Fix isSameOrAfter/isToday dayjs imports to use the .js extension so they stay externalized as clean imports - Add useDate unit tests (frozen now, fr locale) and refresh the mdx doc Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pascalsaussier-edifice
force-pushed
the
feat-ENABLING-645-complete-usedate-hook
branch
from
August 26, 2026 15:46
fbdc1bf to
a1ebd74
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Complète le hook
useDate(@edifice.io/react) en exposant une méthode par format du design system de dates, plus des helpers de conversion. Objectif : harmoniser l'affichage des dates dans les nouvelles apps et arrêter les réimplémentations locales.Changement non-breaking : ajout de méthodes ; les anciennes (
fromNow,formatTimeAgo,formatDate) restent fonctionnelles et sont annotées@deprecated.Changements
Nouveaux formatters (tous acceptent un
CoreDate, localisés viacurrentLanguage) :formatRelativeDateTimehier à 16h22,le 21 septembre à 16h22formatRelativeDateil y a 38 minutes,hier,21 sept.formatLongDateTime23 juillet 2021 à 17:46formatLongDate23 juillet 2021formatRawDate28/02/2025formatRawDateTime18/11/2019 15:36formatCalendarDate(date, variant)'full' | 'short' | 'abbr')vendredi 16 avril,12 janv.,16/04formatWeekCette semaine,Semaine du 17 au 23 janvierConversions :
toJsDate,toTimestamp,toIsoDate,toMongoDate(robustes aux entrées invalides →undefined).Autres :
@deprecatedJSDoc) defromNow→formatRelativeDateTime,formatTimeAgo→formatRelativeDate,formatDate→formatLongDate/formatRawDate/formatCalendarDate.date.*ajoutées enenetfrdansapps/docs/i18n.ts. Aucun texte en dur.isSameOrAfter/isToday(ajout de l'extension.js) pour qu'ils restent externalisés en imports propresdayjs/plugin/xxx.jsau lieu d'un chemin pnpm absolu.Audit poids : aucun plugin dayjs ajouté (implémentation basée sur le built-in
startOf('week')+ comparaisons).dayjset ses plugins sont externalisés par le build → 0 octet ajouté au bundle publié.Choix d'implémentation (spec ambiguë)
mercredi à 16h22).formatWeek: bornes en mois abrégé pour semaine dernière/prochaine, mois complet pour « Semaine du … ».Which Package changed?
Has the documentation changed?
Type of change
Comment tester
pnpm --filter @edifice.io/react test→ 152 tests OK (dont 20 suruseDate).pnpm docspuis Hooks / useDate pour la doc.Checklist: