master
Raw Download raw file
 1/*
 2 *
 3 * Date.addLocale(<code>) adds this locale to Sugar.
 4 * To set the locale globally, simply call:
 5 *
 6 * Date.setLocale('zh-CN');
 7 *
 8 * var locale = Date.getLocale(<code>) will return this object, which
 9 * can be tweaked to change the behavior of parsing/formatting in the locales.
10 *
11 * locale.addFormat adds a date format (see this file for examples).
12 * Special tokens in the date format will be parsed out into regex tokens:
13 *
14 * {0} is a reference to an entry in locale.tokens. Output: (?:the)?
15 * {unit} is a reference to all units. Output: (day|week|month|...)
16 * {unit3} is a reference to a specific unit. Output: (hour)
17 * {unit3-5} is a reference to a subset of the units array. Output: (hour|day|week)
18 * {unit?} "?" makes that token optional. Output: (day|week|month)?
19 *
20 * {day} Any reference to tokens in the modifiers array will include all with the same name. Output: (yesterday|today|tomorrow)
21 *
22 * All spaces are optional and will be converted to "\s*"
23 *
24 * Locale arrays months, weekdays, units, numbers, as well as the "src" field for
25 * all entries in the modifiers array follow a special format indicated by a colon:
26 *
27 * minute:|s  = minute|minutes
28 * thicke:n|r = thicken|thicker
29 *
30 * Additionally in the months, weekdays, units, and numbers array these will be added at indexes that are multiples
31 * of the relevant number for retrieval. For example having "sunday:|s" in the units array will result in:
32 *
33 * units: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sundays']
34 *
35 * When matched, the index will be found using:
36 *
37 * units.indexOf(match) % 7;
38 *
39 * Resulting in the correct index with any number of alternates for that entry.
40 *
41 */
42
43Date.addLocale('zh-CN', {
44  'variant': true,
45  'monthSuffix': '月',
46  'weekdays': '星期日|周日,星期一|周一,星期二|周二,星期三|周三,星期四|周四,星期五|周五,星期六|周六',
47  'units': '毫秒,秒钟,分钟,小时,天,个星期|周,个月,年',
48  'tokens': '日|号',
49  'short':'{yyyy}年{M}月{d}日',
50  'long': '{yyyy}年{M}月{d}日 {tt}{h}:{mm}',
51  'full': '{yyyy}年{M}月{d}日 {weekday} {tt}{h}:{mm}:{ss}',
52  'past': '{num}{unit}{sign}',
53  'future': '{num}{unit}{sign}',
54  'duration': '{num}{unit}',
55  'timeSuffixes': '点|时,分钟?,秒',
56  'ampm': '上午,下午',
57  'modifiers': [
58    { 'name': 'day', 'src': '前天', 'value': -2 },
59    { 'name': 'day', 'src': '昨天', 'value': -1 },
60    { 'name': 'day', 'src': '今天', 'value': 0 },
61    { 'name': 'day', 'src': '明天', 'value': 1 },
62    { 'name': 'day', 'src': '后天', 'value': 2 },
63    { 'name': 'sign', 'src': '前', 'value': -1 },
64    { 'name': 'sign', 'src': '后', 'value':  1 },
65    { 'name': 'shift', 'src': '上|去', 'value': -1 },
66    { 'name': 'shift', 'src': '这', 'value':  0 },
67    { 'name': 'shift', 'src': '下|明', 'value':  1 }
68  ],
69  'dateParse': [
70    '{num}{unit}{sign}',
71    '{shift}{unit=5-7}'
72  ],
73  'timeParse': [
74    '{shift}{weekday}',
75    '{year}年{month?}月?{date?}{0?}',
76    '{month}月{date?}{0?}',
77    '{date}[日号]'
78  ]
79});
80