Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Upgrade to date-fns V2 #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/examples/12_custom_locales.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ order: 12
---

import Calendar, { Sandbox } from "../demo";
import { it } from 'date-fns/locale';

# Custom Locales

Expand Down Expand Up @@ -46,9 +47,11 @@ For more information about the locales, see the [props#locale](/props#locale) se
This example uses the Italian locale.

<Sandbox>
<Calendar locale={require("date-fns/locale/it")} />
<Calendar locale={it} />
</Sandbox>

```js
<Calendar locale={require("date-fns/locale/it")} />
import { it } from 'date-fns/locale';

<Calendar locale={it} />
```
14 changes: 7 additions & 7 deletions docs/examples/30_advanced_example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ route: /examples/advanced-example
order: 30
---

import { format, areRangesOverlapping } from "date-fns";
import { format, areIntervalsOverlapping } from "date-fns";
import Calendar, { Sandbox, EventCapturer } from "../demo";
import Component from "@reach/component-component";

Expand Down Expand Up @@ -42,7 +42,7 @@ The things that you could do:
renderHeader={() => null}
renderDayHeader={date => (
<div className="SkedifyCalendar__WeekHeader__Days__Day">
{format(date, "dddd")}
{format(date, "iiii")}
</div>
)}
onEventClick={event => capture("onEventClick", event)}
Expand Down Expand Up @@ -114,7 +114,7 @@ The things that you could do:
return false;
}

return areRangesOverlapping(
return areIntervalsOverlapping(
storedEvent.start,
storedEvent.end,
start,
Expand All @@ -125,7 +125,7 @@ The things that you could do:
canCreateEvent={({ start, end }) => {
// We don't allow overlapping events
return !state.events.some(event =>
areRangesOverlapping(event.start, event.end, start, end)
areIntervalsOverlapping(event.start, event.end, start, end)
);
}}
events={state.events}
Expand All @@ -146,7 +146,7 @@ The things that you could do:
renderHeader={() => null}
renderDayHeader={date => (
<div className="SkedifyCalendar__WeekHeader__Days__Day">
{format(date, "dddd")}
{format(date, "iiii")}
</div>
)}
onEventClick={event => console.log("onEventClick", event)}
Expand Down Expand Up @@ -216,7 +216,7 @@ The things that you could do:
return false;
}

return areRangesOverlapping(
return areIntervalsOverlapping(
storedEvent.start,
storedEvent.end,
start,
Expand All @@ -227,7 +227,7 @@ The things that you could do:
canCreateEvent={({ start, end }) => {
// We don't allow overlapping events
return !this.state.events.some(event =>
areRangesOverlapping(event.start, event.end, start, end)
areIntervalsOverlapping(event.start, event.end, start, end)
);
}}
events={this.state.events}
Expand Down
2,602 changes: 2,015 additions & 587 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@
"lib"
],
"license": "MIT",
"dependencies": {
"date-fns": "^1.29.0",
"docz": "^0.12.13",
"uuid": "^3.3.2"
},
"peerDependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6"
"uuid": ">=8",
"date-fns": ">=2",
"react": ">=16"
},
"devDependencies": {
"@babel/preset-react": "^7.0.0",
Expand All @@ -71,6 +67,8 @@
"commitizen": "^3.0.5",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"date-fns": "^2.21.3",
"docz": "^0.12.13",
"docz-plugin-css": "^0.11.0",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
Expand All @@ -87,11 +85,15 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"semantic-release": "^15.12.3",
"travis-deploy-once": "^5.0.9"
"travis-deploy-once": "^5.0.9",
"uuid": "^8.3.2"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"volta": {
"node": "10.24.1"
}
}
7 changes: 5 additions & 2 deletions src/components/Calendar/Calendar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import uuid from 'uuid';
import { v4 as uuid } from 'uuid';

import {
startOfWeek,
Expand Down Expand Up @@ -514,7 +514,10 @@ class Calendar extends Component {
ref={gutterRef}
slotsToRender={slotsToRender}
sizeOfOneSlot={sizeOfOneSlot}
startTime={format(startTime)}
startTime={format(
startTime,
`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`
)}
step={step}
render={renderGutterItem}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Calendar/DragHandle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { memo } from 'react';
import uuid from 'uuid';
import { v4 as uuid } from 'uuid';
import { isFunction } from '../../utils/isFunction';

const PLACEMENT_TOP = uuid();
Expand Down
4 changes: 2 additions & 2 deletions src/components/Calendar/Gutter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo, forwardRef } from 'react';
import { Stack } from './Stack';
import { range } from '../../utils/range';
import { addMinutes } from 'date-fns';
import { addMinutes, parseISO } from 'date-fns';

function GutterComponent(
{ slotsToRender, sizeOfOneSlot, startTime, step, render },
Expand All @@ -15,7 +15,7 @@ function GutterComponent(
className="SkedifyCalendar__Gutter"
>
{range(slotsToRender).map(slotIndex => {
const time = addMinutes(startTime, slotIndex * step);
const time = addMinutes(parseISO(startTime), slotIndex * step);

return (
<div
Expand Down
10 changes: 4 additions & 6 deletions src/components/Calendar/LocaleContext.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { createContext } from 'react';

import german from 'date-fns/locale/de';
import french from 'date-fns/locale/fr';
import dutch from 'date-fns/locale/nl';
import { nl, fr, de } from 'date-fns/locale';

const AVAILABLE_LOCALES = {
de: german,
fr: french,
nl: dutch,
de,
fr,
nl,
};

const DEFAULT_LOCALE = undefined; // The default for date-fns will be english anyway
Expand Down
2 changes: 1 addition & 1 deletion src/components/Calendar/Stack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import uuid from 'uuid';
import { v4 as uuid } from 'uuid';

export const DIRECTION = {
HORIZONTAL_REVERSE: uuid(),
Expand Down
12 changes: 6 additions & 6 deletions src/components/Calendar/defaultRenderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ export const DEFAULT_RENDER_HEADER = ({ start, end }) => (
{locale => (
<div className="SkedifyCalendar__Header">
{isSameDay(start, end) ? (
format(start, 'DD MMMM YYYY')
format(start, 'dd LLLL yyyy')
) : (
<React.Fragment>
{format(
start,
isSameYear(start, end)
? isSameMonth(start, end)
? 'DD'
: 'DD MMMM'
: 'DD MMMM YYYY',
? 'dd'
: 'dd LLLL'
: 'dd LLLL yyyy',
{ locale }
)}
{' - '}
{format(end, 'DD MMMM YYYY', { locale })}
{format(end, 'dd LLLL yyyy', { locale })}
</React.Fragment>
)}
</div>
Expand All @@ -41,7 +41,7 @@ export const DEFAULT_RENDER_DAY_HEADER = date => (
<LocaleContext.Consumer>
{locale => (
<div className="SkedifyCalendar__WeekHeader__Days__Day">
{format(date, 'dddd DD/MM', { locale })}
{format(date, 'iiii dd/LL', { locale })}
</div>
)}
</LocaleContext.Consumer>
Expand Down