Skip to content

Commit 537c6f3

Browse files
authored
feat: Dayjs localizer (#2264)
* docs: fixed instructions to run examples locally * fix: luxon story now uses luxon instead of moment * fix(moment localizer): removed comments about 'day' and 'date' in the call to isSame() * feat: created dayjs localizer * fix(dayjs localizer): min() & max() now both behave correctly when a default timezone is applied * docs(localizer guide): edited last two paragraphs to include the new localizer * fix(dayjs localizer): dayjs plugins are now loaded by the localizer * docs: updated README.md & exampleCode to reflect dayjs plugins being loaded by the localizer * docs(localizer props): added dayjs example & sorted examples alphabetically * docs(exampleCode dayjs): use dayjs to construct date based props * test: added commented out dayjs configuration * revert(README.md): remove note on node 16 storybook requirement * fix(dayjs localizer): dayjs plugins are now loaded by the dayjsLocalizer * docs(dayjs localizer): mention dayjs plugins being loaded by the dayjsLocalizer * docs(timezones): mention the dayjsLocalizer's ability to handle timezones too Big thanks to @marnixhoh for the effort and patience #2264
1 parent 5611d99 commit 537c6f3

File tree

15 files changed

+582
-29
lines changed

15 files changed

+582
-29
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ element has a height, or the calendar won't be visible. To provide your own cust
2929
$ git clone [email protected]:jquense/react-big-calendar.git
3030
$ cd react-big-calendar
3131
$ yarn
32-
$ yarn examples
32+
$ yarn storybook
3333
```
3434

3535
- Open [localhost:3000/examples/index.html](http://localhost:3000/examples/index.html).
3636

3737
### Localization and Date Formatting
3838

39-
`react-big-calendar` includes three options for handling the date formatting and culture localization, depending
40-
on your preference of DateTime libraries. You can use either the [Moment.js](https://momentjs.com/), [Globalize.js](https://github.com/jquery/globalize) or [date-fns](https://date-fns.org/) localizers.
39+
`react-big-calendar` includes four options for handling the date formatting and culture localization, depending
40+
on your preference of DateTime libraries. You can use either the [Moment.js](https://momentjs.com/), [Globalize.js](https://github.com/jquery/globalize), [date-fns](https://date-fns.org/), [Day.js](https://day.js.org) localizers.
4141

4242
Regardless of your choice, you **must** choose a localizer to use this library:
4343

@@ -118,6 +118,37 @@ const MyCalendar = (props) => (
118118
)
119119
```
120120

121+
#### Day.js
122+
123+
Note that the dayjsLocalizer extends Day.js with the following plugins:
124+
125+
- [IsBetween](https://day.js.org/docs/en/plugin/is-between)
126+
- [IsSameOrAfter](https://day.js.org/docs/en/plugin/is-same-or-after)
127+
- [IsSameOrBefore](https://day.js.org/docs/en/plugin/is-same-or-before)
128+
- [LocaleData](https://day.js.org/docs/en/plugin/locale-data)
129+
- [LocalizedFormat](https://day.js.org/docs/en/plugin/localized-format)
130+
- [MinMax](https://day.js.org/docs/en/plugin/min-max)
131+
- [UTC](https://day.js.org/docs/en/plugin/utc)
132+
133+
```js
134+
import { Calendar, dayjsLocalizer } from 'react-big-calendar'
135+
import dayjs from 'dayjs'
136+
137+
const localizer = dayjsLocalizer(dayjs)
138+
139+
const MyCalendar = (props) => (
140+
<div>
141+
<Calendar
142+
localizer={localizer}
143+
events={myEventsList}
144+
startAccessor="start"
145+
endAccessor="end"
146+
style={{ height: 500 }}
147+
/>
148+
</div>
149+
)
150+
```
151+
121152
## Custom Styling
122153

123154
Out of the box, you can include the compiled CSS files and be up and running. But, sometimes, you may want to style

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"@babel/runtime": "^7.18.6",
108108
"clsx": "^1.2.1",
109109
"date-arithmetic": "^4.1.0",
110+
"dayjs": "^1.11.5",
110111
"dom-helpers": "^5.2.1",
111112
"globalize": "^0.1.1",
112113
"invariant": "^2.2.4",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export { default as momentLocalizer } from './localizers/moment'
1313
export { default as luxonLocalizer } from './localizers/luxon'
1414
export { default as globalizeLocalizer } from './localizers/globalize'
1515
export { default as dateFnsLocalizer } from './localizers/date-fns'
16+
export { default as dayjsLocalizer } from './localizers/dayjs'
1617
export { default as move } from './utils/move'
1718
export { views as Views, navigate as Navigate } from './utils/constants'

0 commit comments

Comments
 (0)