mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
450cc30a9f
* fix(utils): preserve colon-containing values in tagsToRecord; align invalidFallback across date formatters; add formatRelativeTime
**key-value-tags: fix value truncation on tags with colons**
`tagsToRecord` used `tag.split(':')` with array destructuring, so any
value containing `:` (e.g. a webhook URL `https://example.com/hook`)
was silently truncated to just the scheme. Switch to `indexOf` so the
split happens only on the first colon, preserving the full value.
Example (before → after):
`tagsToRecord(['hook:https://api.example.com/cb'])`
before: `{ hook: 'https' }` ← bug
after: `{ hook: 'https://api.example.com/cb' }`
Add `key-value-tags.test.ts` covering: simple pairs, URL values,
multi-colon values, empty key/value, round-trip with `recordToTags`.
**date-time: honour `invalidFallback` consistently**
`FormatDateOptions` declares `invalidFallback` but only
`formatDateTimeSeconds` ever read it — `formatDateTime` and `formatDate`
both collapsed a present-but-invalid date string into `fallback ?? ''`,
making it impossible for callers to distinguish "nothing was passed" from
"a bad string was passed".
Extract a shared `resolveInvalid(value, options)` helper (prefers
`invalidFallback`, then `fallback`, then the raw value) and apply it
uniformly. Also refactor `formatDateTimeSeconds` to use the existing
`parseDate` helper, eliminating the duplicated `new Date` + `isNaN`
guard. No externally visible behaviour change for previously valid
combinations; callers that relied on invalid dates falling through to
`fallback` keep working since `resolveInvalid` falls through to
`fallback` when `invalidFallback` is absent.
**date-time: add `formatRelativeTime`**
Chat and notification UIs commonly need relative timestamps ("3 minutes
ago", "yesterday"). The utility file has no such function. Add
`formatRelativeTime(value, options?)` using `Intl.RelativeTimeFormat`
so the output respects the browser locale without hardcoded English
strings. Thresholds: seconds < 60 s, minutes < 1 h, hours < 24 h,
days < 7 d, beyond that falls back to `toLocaleDateString()`. Accepts
both ISO strings and `Date` objects.
Add `date-time.test.ts` covering all four exported functions including
`vi.useFakeTimers` assertions for `formatRelativeTime`.
* fix(utils): clean up formatRelativeTime after merge
Made-with: Cursor