UNPKG

sugar

Version:

A Javascript library for working with native objects.

82 lines (78 loc) 3.54 kB
/* * * Date.addLocale(<code>) adds this locale to Sugar. * To set the locale globally, simply call: * * Date.setLocale('zh-TW'); * * var locale = Date.getLocale(<code>) will return this object, which * can be tweaked to change the behavior of parsing/formatting in the locales. * * locale.addFormat adds a date format (see this file for examples). * Special tokens in the date format will be parsed out into regex tokens: * * {0} is a reference to an entry in locale.tokens. Output: (?:the)? * {unit} is a reference to all units. Output: (day|week|month|...) * {unit3} is a reference to a specific unit. Output: (hour) * {unit3-5} is a reference to a subset of the units array. Output: (hour|day|week) * {unit?} "?" makes that token optional. Output: (day|week|month)? * * {day} Any reference to tokens in the modifiers array will include all with the same name. Output: (yesterday|today|tomorrow) * * All spaces are optional and will be converted to "\s*" * * Locale arrays months, weekdays, units, numbers, as well as the "src" field for * all entries in the modifiers array follow a special format indicated by a colon: * * minute:|s = minute|minutes * thicke:n|r = thicken|thicker * * Additionally in the months, weekdays, units, and numbers array these will be added at indexes that are multiples * of the relevant number for retrieval. For example having "sunday:|s" in the units array will result in: * * units: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sundays'] * * When matched, the index will be found using: * * units.indexOf(match) % 7; * * Resulting in the correct index with any number of alternates for that entry. * */ //'zh-TW': '1;月;年;;星期日|週日,星期一|週一,星期二|週二,星期三|週三,星期四|週四,星期五|週五,星期六|週六;毫秒,秒鐘,分鐘,小時,天,個星期|週,個月,年;;;日|號;;上午,下午;點|時,分鐘?,秒;{num}{unit}{sign},{shift}{unit=5-7};{shift}{weekday},{year}年{month?}月?{date?}{0},{month}月{date?}{0},{date}{0};{yyyy}年{M}月{d}日 {Weekday};{tt}{h}:{mm}:{ss};前天,昨天,今天,明天,後天;,前,,後;,上|去,這,下|明', Date.addLocale('zh-TW', { 'monthSuffix': '月', 'weekdays': '星期日|週日,星期一|週一,星期二|週二,星期三|週三,星期四|週四,星期五|週五,星期六|週六', 'units': '毫秒,秒鐘,分鐘,小時,天,個星期|週,個月,年', 'tokens': '日|號', 'short':'{yyyy}年{M}月{d}日', 'long': '{yyyy}年{M}月{d}日 {tt}{h}:{mm}', 'full': '{yyyy}年{M}月{d}日 {Weekday} {tt}{h}:{mm}:{ss}', 'past': '{num}{unit}{sign}', 'future': '{num}{unit}{sign}', 'duration': '{num}{unit}', 'timeSuffixes': '點|時,分鐘?,秒', 'ampm': '上午,下午', 'modifiers': [ { 'name': 'day', 'src': '前天', 'value': -2 }, { 'name': 'day', 'src': '昨天', 'value': -1 }, { 'name': 'day', 'src': '今天', 'value': 0 }, { 'name': 'day', 'src': '明天', 'value': 1 }, { 'name': 'day', 'src': '後天', 'value': 2 }, { 'name': 'sign', 'src': '前', 'value': -1 }, { 'name': 'sign', 'src': '後', 'value': 1 }, { 'name': 'shift', 'src': '上|去', 'value': -1 }, { 'name': 'shift', 'src': '這', 'value': 0 }, { 'name': 'shift', 'src': '下|明', 'value': 1 } ], 'dateParse': [ '{num}{unit}{sign}', '{shift}{unit=5-7}' ], 'timeParse': [ '{shift}{weekday}', '{year}年{month?}月?{date?}{0?}', '{month}月{date?}{0?}', '{date}[日號]' ] });