Skip to content

Commit 3a7ca02

Browse files
docs: add knowledge base against unnecessary Day.js usage (calcom#23719)
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
1 parent 2cc8b1c commit 3a7ca02

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

.agents/knowledge-base.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,12 @@ dates.map((date) => dayjs.utc(date).add(1, "day").format());
318318
// ✅ Best - Use native Date when possible
319319
dates.map((date) => new Date(date.valueOf() + 24 * 60 * 60 * 1000));
320320
```
321+
322+
## Avoid using Dayjs if you don’t need to be strictly tz aware.
323+
324+
When doing logic like Dayjs.startOf(".."), you can instead use date-fns' `startOfMonth(dateObj)` / `endOfDay(dateObj)`;
325+
When doing logic that depends on Browser locale, use i18n.language (prefer to deconstruct) like: `const { i18n: { language } } = useLocale();`, in combination with built-in Intl.
326+
327+
Note that with Date, you’re dealing with System time, so it’s not suited to everywhere (such as in the Booker, where instead we’ll likely migrate to Temporal) - but in most cases the above are suitable.
328+
329+
The main reason for doing so is that Dayjs uses a useful, but highly risky plugin system, which has led us to create `@calcom/dayjs` - this is heavy however, because it pre-loads ALL plugins, including locale handling. It’s a non-ideal solution to a problem that unfortunately exists due to Dayjs.

0 commit comments

Comments
 (0)