UNPKG

sugar

Version:

A Javascript library for working with native objects.

81 lines (78 loc) 3.08 kB
/* * * Date.addLocale(<code>) adds this locale to Sugar. * To set the locale globally, simply call: * * Date.setLocale('ko'); * * 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. * */ Date.addLocale('ko', { 'digitDate': true, 'monthSuffix': '월', 'weekdays': '일요일,월요일,화요일,수요일,목요일,금요일,토요일', 'units': '밀리초,초,분,시간,일,주,개월|달,년', 'numbers': '일|한,이,삼,사,오,육,칠,팔,구,십', 'short': '{yyyy}년{M}월{d}일', 'long': '{yyyy}년{M}월{d}일 {H}시{mm}분', 'full': '{yyyy}년{M}월{d}일 {Weekday} {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} {unit=5?} {weekday}', '{year}년{month?}월?{date?}일?', '{month}월{date?}일?', '{date}일' ] });