This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
forked from jquense/react-big-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
import dates from '../utils/dates'; | ||
import oldGlobalize from './oldGlobalize'; | ||
import { set } from '../formats'; | ||
import { set as setLocalizer } from '../localizer'; | ||
|
||
function inSame12Hr(start, end){ | ||
let s = 12 - dates.hours(start) | ||
let e = 12 - dates.hours(end) | ||
return (s <= 0 && e <= 0) || (s >= 0 && e >= 0) | ||
} | ||
|
||
let dateRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 'd', culture) + ' — ' + local.format(end, 'd', culture) | ||
local.format(start, { date: 'short' }, culture) + ' — ' + local.format(end, { date: 'short' }, culture) | ||
|
||
let timeRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 'h:mmtt', culture) + | ||
' — ' + local.format(end, inSame12Hr(start, end) ? 'h:mm' : 'h:mmtt', culture) | ||
local.format(start, { time: 'short' }, culture) + | ||
' — ' + local.format(end, { time: 'short' }, culture) | ||
|
||
let weekRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 'MMM dd', culture) + | ||
' - ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture) | ||
' — ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture) | ||
|
||
export let formats = { | ||
dateFormat: 'dd', | ||
dayFormat: 'ddd dd/MM', | ||
weekdayFormat: 'ddd', | ||
dayFormat: 'eee dd/MM', | ||
weekdayFormat: 'eee', | ||
|
||
selectRangeFormat: timeRangeFormat, | ||
eventTimeRangeFormat: timeRangeFormat, | ||
|
||
timeGutterFormat: 't', | ||
timeGutterFormat: { time: 'short' }, | ||
|
||
monthHeaderFormat: 'Y', | ||
dayHeaderFormat: 'dddd MMM dd', | ||
monthHeaderFormat: 'MMMM yyyy', | ||
dayHeaderFormat: 'eeee MMM dd', | ||
dayRangeHeaderFormat: weekRangeFormat, | ||
agendaHeaderFormat: dateRangeFormat, | ||
|
||
agendaDateFormat: 'ddd MMM dd', | ||
agendaTimeFormat: 't', | ||
agendaDateFormat: 'eee MMM dd', | ||
agendaTimeFormat: { time: 'short' }, | ||
agendaTimeRangeFormat: timeRangeFormat | ||
} | ||
|
||
export default function(globalize) { | ||
|
||
function getCulture(culture){ | ||
return culture | ||
? globalize.findClosestCulture(culture) | ||
: globalize.culture() | ||
} | ||
let locale = culture => culture ? globalize(culture) : globalize; | ||
|
||
function firstOfWeek(culture) { | ||
culture = getCulture(culture) | ||
return (culture && culture.calendar.firstDay) || 0 | ||
let date = new Date(); | ||
//cldr-data doesn't seem to be zero based | ||
let localeDay = Math.max( | ||
parseInt(locale(culture).formatDate(date, { raw: 'e' }), 10) - 1, 0) | ||
|
||
return Math.abs(date.getDay() - localeDay) | ||
} | ||
|
||
if (!globalize.load) | ||
return oldGlobalize(globalize); | ||
|
||
|
||
set(formats) | ||
|
||
return setLocalizer({ | ||
firstOfWeek, | ||
|
||
parse(value, format, culture){ | ||
return globalize.parseDate(value, format, culture) | ||
format = typeof format === 'string' ? { raw: format } : format; | ||
return locale(culture).parseDate(value, format) | ||
}, | ||
|
||
format(value, format, culture){ | ||
return globalize.format(value, format, culture) | ||
format = typeof format === 'string' ? { raw: format } : format; | ||
return locale(culture).formatDate(value, format) | ||
} | ||
}) | ||
} |
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,66 @@ | ||
import dates from '../utils/dates'; | ||
import { set } from '../formats'; | ||
import { set as setLocalizer } from '../localizer'; | ||
|
||
let dateRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 'd', culture) + ' — ' + local.format(end, 'd', culture) | ||
|
||
let timeRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 't', culture) + | ||
' — ' + local.format(end, 't', culture) | ||
|
||
let weekRangeFormat = ({ start, end }, culture, local)=> | ||
local.format(start, 'MMM dd', culture) + | ||
' - ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture) | ||
|
||
export default function(globalize) { | ||
|
||
} | ||
|
||
export let formats = { | ||
dateFormat: 'dd', | ||
dayFormat: 'ddd dd/MM', | ||
weekdayFormat: 'ddd', | ||
|
||
selectRangeFormat: timeRangeFormat, | ||
eventTimeRangeFormat: timeRangeFormat, | ||
|
||
timeGutterFormat: 't', | ||
|
||
monthHeaderFormat: 'Y', | ||
dayHeaderFormat: 'dddd MMM dd', | ||
dayRangeHeaderFormat: weekRangeFormat, | ||
agendaHeaderFormat: dateRangeFormat, | ||
|
||
agendaDateFormat: 'ddd MMM dd', | ||
agendaTimeFormat: 't', | ||
agendaTimeRangeFormat: timeRangeFormat | ||
} | ||
|
||
export default function(globalize) { | ||
|
||
function getCulture(culture){ | ||
return culture | ||
? globalize.findClosestCulture(culture) | ||
: globalize.culture() | ||
} | ||
|
||
function firstOfWeek(culture) { | ||
culture = getCulture(culture) | ||
return (culture && culture.calendar.firstDay) || 0 | ||
} | ||
|
||
set(formats) | ||
|
||
return setLocalizer({ | ||
firstOfWeek, | ||
|
||
parse(value, format, culture){ | ||
return globalize.parseDate(value, format, culture) | ||
}, | ||
|
||
format(value, format, culture){ | ||
return globalize.format(value, format, culture) | ||
} | ||
}) | ||
} |