-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Date-fns localizer (#1542)
* testing date-fns localizer * format updates for fns 2.0 * format updates for fns 2.0 * README update * README update
- Loading branch information
Showing
3 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as dates from '../utils/dates' | ||
import { DateLocalizer } from '../localizer' | ||
|
||
let dateRangeFormat = ({ start, end }, culture, local) => | ||
`${local.format(start, 'P', culture)} – ${local.format(end, 'P', culture)}` | ||
|
||
let timeRangeFormat = ({ start, end }, culture, local) => | ||
`${local.format(start, 'p', culture)} – ${local.format(end, 'p', culture)}` | ||
|
||
let timeRangeStartFormat = ({ start }, culture, local) => | ||
`${local.format(start, 'h:mma', culture)} – ` | ||
|
||
let timeRangeEndFormat = ({ end }, culture, local) => | ||
` – ${local.format(end, 'h:mma', culture)}` | ||
|
||
let weekRangeFormat = ({ start, end }, culture, local) => | ||
`${local.format(start, 'MMMM dd', culture)} – ${local.format( | ||
end, | ||
dates.eq(start, end, 'month') ? 'dd' : 'MMMM dd', | ||
culture | ||
)}` | ||
|
||
export let formats = { | ||
dateFormat: 'dd', | ||
dayFormat: 'dd ddd', | ||
weekdayFormat: 'cccc', | ||
|
||
selectRangeFormat: timeRangeFormat, | ||
eventTimeRangeFormat: timeRangeFormat, | ||
eventTimeRangeStartFormat: timeRangeStartFormat, | ||
eventTimeRangeEndFormat: timeRangeEndFormat, | ||
|
||
timeGutterFormat: 'p', | ||
|
||
monthHeaderFormat: 'MMMM yyyy', | ||
dayHeaderFormat: 'dddd MMM dd', | ||
dayRangeHeaderFormat: weekRangeFormat, | ||
agendaHeaderFormat: dateRangeFormat, | ||
|
||
agendaDateFormat: 'ddd MMM dd', | ||
agendaTimeFormat: 'p', | ||
agendaTimeRangeFormat: timeRangeFormat, | ||
} | ||
|
||
const dateFnsLocalizer = function({ | ||
startOfWeek, | ||
getDay, | ||
format: _format, | ||
locales, | ||
}) { | ||
return new DateLocalizer({ | ||
formats, | ||
firstOfWeek(culture) { | ||
return getDay(startOfWeek(new Date(), { locale: locales[culture] })) | ||
}, | ||
|
||
format(value, formatString, culture) { | ||
return _format(new Date(value), formatString, { | ||
locale: locales[culture], | ||
}) | ||
}, | ||
}) | ||
} | ||
|
||
export default dateFnsLocalizer |