UNPKG

sugar

Version:

A Javascript library for working with native objects.

83 lines (80 loc) 3.36 kB
/* * * Date.addLocale(<code>) adds this locale to Sugar. * To set the locale globally, simply call: * * Date.setLocale('da'); * * 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('da', { 'plural': true, 'months': 'januar,februar,marts,april,maj,juni,juli,august,september,oktober,november,december', 'weekdays': 'søndag|sondag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag|lordag', 'units': 'millisekund:|er,sekund:|er,minut:|ter,tim:e|er,dag:|e,ug:e|er|en,måned:|er|en+maaned:|er|en,år:||et+aar:||et', 'numbers': 'en|et,to,tre,fire,fem,seks,syv,otte,ni,ti', 'tokens': 'den,for', 'articles': 'den', 'short':'d. {d}. {month} {yyyy}', 'long': 'den {d}. {month} {yyyy} {H}:{mm}', 'full': '{Weekday} den {d}. {month} {yyyy} {H}:{mm}:{ss}', 'past': '{num} {unit} {sign}', 'future': '{sign} {num} {unit}', 'duration': '{num} {unit}', 'ampm': 'am,pm', 'modifiers': [ { 'name': 'day', 'src': 'forgårs|i forgårs|forgaars|i forgaars', 'value': -2 }, { 'name': 'day', 'src': 'i går|igår|i gaar|igaar', 'value': -1 }, { 'name': 'day', 'src': 'i dag|idag', 'value': 0 }, { 'name': 'day', 'src': 'i morgen|imorgen', 'value': 1 }, { 'name': 'day', 'src': 'over morgon|overmorgen|i over morgen|i overmorgen|iovermorgen', 'value': 2 }, { 'name': 'sign', 'src': 'siden', 'value': -1 }, { 'name': 'sign', 'src': 'om', 'value': 1 }, { 'name': 'shift', 'src': 'i sidste|sidste', 'value': -1 }, { 'name': 'shift', 'src': 'denne', 'value': 0 }, { 'name': 'shift', 'src': 'næste|naeste', 'value': 1 } ], 'dateParse': [ '{num} {unit} {sign}', '{sign} {num} {unit}', '{1?} {num} {unit} {sign}', '{shift} {unit=5-7}' ], 'timeParse': [ '{0?} {weekday?} {date?} {month} {year}', '{date} {month}', '{shift} {weekday}' ] });