iamkun / iamkun/dayjs

Need for Independent dayjs Instances

Open
#2,702 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Description:**
I am trying to use dayjs along with the [dayjs-business-time](https://www.npmjs.com/package/dayjs-business-time) plugin to set the business times for a user. Since different users in the system can have different business times, I need to be able to configure a dayjs instance for each specific user and pass it around. However, dayjs being a global instance, any changes made to the business times for one dayjs instance affects all other instances. This global behaviour causes issues when the application is handling multiple users with different work schedules simultaneously.

I want to be able to do something like the following:
```
const dayjsForUser1 = dayjs.getNew();
dayjsForUser1.extend(dayjsBusinessTime);
dayjsForUser1.setBusinessTime({
sunday: null,
monday: [{ start: "09:00:00", end: "17:00:00" }],
tuesday: null,
wednesday: null,
thursday: null,
friday: null,
saturday: null,
});

const dayjsForUser2= dayjs.getNew();
dayjsForUser2.extend(dayjsBusinessTime);
/**
* setting the business time for dayjsForUser2 should not modify the business times setup for dayjsForUser1
* /
dayjsForUser2.setBusinessTime({
sunday: null,
monday: null,
tuesday: [{ start: "09:00:00", end: "17:00:00" }],
wednesday: null,
thursday: null,
friday: null,
saturday: null,
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.