|
1 | 1 | import dates from '../utils/dates'; |
| 2 | +import oldGlobalize from './oldGlobalize'; |
2 | 3 | import { set } from '../formats'; |
3 | 4 | import { set as setLocalizer } from '../localizer'; |
4 | 5 |
|
5 | | -function inSame12Hr(start, end){ |
6 | | - let s = 12 - dates.hours(start) |
7 | | - let e = 12 - dates.hours(end) |
8 | | - return (s <= 0 && e <= 0) || (s >= 0 && e >= 0) |
9 | | -} |
10 | | - |
11 | 6 | let dateRangeFormat = ({ start, end }, culture, local)=> |
12 | | - local.format(start, 'd', culture) + ' — ' + local.format(end, 'd', culture) |
| 7 | + local.format(start, { date: 'short' }, culture) + ' — ' + local.format(end, { date: 'short' }, culture) |
13 | 8 |
|
14 | 9 | let timeRangeFormat = ({ start, end }, culture, local)=> |
15 | | - local.format(start, 'h:mmtt', culture) + |
16 | | - ' — ' + local.format(end, inSame12Hr(start, end) ? 'h:mm' : 'h:mmtt', culture) |
| 10 | + local.format(start, { time: 'short' }, culture) + |
| 11 | + ' — ' + local.format(end, { time: 'short' }, culture) |
17 | 12 |
|
18 | 13 | let weekRangeFormat = ({ start, end }, culture, local)=> |
19 | 14 | local.format(start, 'MMM dd', culture) + |
20 | | - ' - ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture) |
| 15 | + ' — ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture) |
21 | 16 |
|
22 | 17 | export let formats = { |
23 | 18 | dateFormat: 'dd', |
24 | | - dayFormat: 'ddd dd/MM', |
25 | | - weekdayFormat: 'ddd', |
| 19 | + dayFormat: 'eee dd/MM', |
| 20 | + weekdayFormat: 'eee', |
26 | 21 |
|
27 | 22 | selectRangeFormat: timeRangeFormat, |
28 | 23 | eventTimeRangeFormat: timeRangeFormat, |
29 | 24 |
|
30 | | - timeGutterFormat: 't', |
| 25 | + timeGutterFormat: { time: 'short' }, |
31 | 26 |
|
32 | | - monthHeaderFormat: 'Y', |
33 | | - dayHeaderFormat: 'dddd MMM dd', |
| 27 | + monthHeaderFormat: 'MMMM yyyy', |
| 28 | + dayHeaderFormat: 'eeee MMM dd', |
34 | 29 | dayRangeHeaderFormat: weekRangeFormat, |
35 | 30 | agendaHeaderFormat: dateRangeFormat, |
36 | 31 |
|
37 | | - agendaDateFormat: 'ddd MMM dd', |
38 | | - agendaTimeFormat: 't', |
| 32 | + agendaDateFormat: 'eee MMM dd', |
| 33 | + agendaTimeFormat: { time: 'short' }, |
39 | 34 | agendaTimeRangeFormat: timeRangeFormat |
40 | 35 | } |
41 | 36 |
|
42 | 37 | export default function(globalize) { |
43 | | - |
44 | | - function getCulture(culture){ |
45 | | - return culture |
46 | | - ? globalize.findClosestCulture(culture) |
47 | | - : globalize.culture() |
48 | | - } |
| 38 | + let locale = culture => culture ? globalize(culture) : globalize; |
49 | 39 |
|
50 | 40 | function firstOfWeek(culture) { |
51 | | - culture = getCulture(culture) |
52 | | - return (culture && culture.calendar.firstDay) || 0 |
| 41 | + let date = new Date(); |
| 42 | + //cldr-data doesn't seem to be zero based |
| 43 | + let localeDay = Math.max( |
| 44 | + parseInt(locale(culture).formatDate(date, { raw: 'e' }), 10) - 1, 0) |
| 45 | + |
| 46 | + return Math.abs(date.getDay() - localeDay) |
53 | 47 | } |
54 | 48 |
|
| 49 | + if (!globalize.load) |
| 50 | + return oldGlobalize(globalize); |
| 51 | + |
| 52 | + |
55 | 53 | set(formats) |
56 | 54 |
|
57 | 55 | return setLocalizer({ |
58 | 56 | firstOfWeek, |
59 | 57 |
|
60 | 58 | parse(value, format, culture){ |
61 | | - return globalize.parseDate(value, format, culture) |
| 59 | + format = typeof format === 'string' ? { raw: format } : format; |
| 60 | + return locale(culture).parseDate(value, format) |
62 | 61 | }, |
63 | 62 |
|
64 | 63 | format(value, format, culture){ |
65 | | - return globalize.format(value, format, culture) |
| 64 | + format = typeof format === 'string' ? { raw: format } : format; |
| 65 | + return locale(culture).formatDate(value, format) |
66 | 66 | } |
67 | 67 | }) |
68 | 68 | } |
0 commit comments