2019-08-02 20:18:05 +02:00
( function ( ) { 'use strict' ; var global$1 = ( typeof global !== "undefined" ? global :
typeof self !== "undefined" ? self :
2020-01-16 19:29:13 +01:00
typeof window !== "undefined" ? window : { } ) ; var formatDistanceLocale = {
lessThanXSeconds : {
one : 'moins d’ une seconde' ,
other : 'moins de {{count}} secondes'
} ,
xSeconds : {
one : '1 seconde' ,
other : '{{count}} secondes'
} ,
halfAMinute : '30 secondes' ,
lessThanXMinutes : {
one : 'moins d’ une minute' ,
other : 'moins de {{count}} minutes'
} ,
xMinutes : {
one : '1 minute' ,
other : '{{count}} minutes'
} ,
aboutXHours : {
one : 'environ 1 heure' ,
other : 'environ {{count}} heures'
} ,
xHours : {
one : '1 heure' ,
other : '{{count}} heures'
} ,
xDays : {
one : '1 jour' ,
other : '{{count}} jours'
} ,
aboutXMonths : {
one : 'environ 1 mois' ,
other : 'environ {{count}} mois'
} ,
xMonths : {
one : '1 mois' ,
other : '{{count}} mois'
} ,
aboutXYears : {
one : 'environ 1 an' ,
other : 'environ {{count}} ans'
} ,
xYears : {
one : '1 an' ,
other : '{{count}} ans'
} ,
overXYears : {
one : 'plus d’ un an' ,
other : 'plus de {{count}} ans'
} ,
almostXYears : {
one : 'presqu’ un an' ,
other : 'presque {{count}} ans'
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
function formatDistance ( token , count , options ) {
options = options || { } ;
var result ;
if ( typeof formatDistanceLocale [ token ] === 'string' ) {
result = formatDistanceLocale [ token ] ;
} else if ( count === 1 ) {
result = formatDistanceLocale [ token ] . one ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
result = formatDistanceLocale [ token ] . other . replace ( '{{count}}' , count ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
if ( options . addSuffix ) {
if ( options . comparison > 0 ) {
return 'dans ' + result ;
} else {
return 'il y a ' + result ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return result ;
} function buildFormatLongFn ( args ) {
return function ( dirtyOptions ) {
var options = dirtyOptions || { } ;
var width = options . width ? String ( options . width ) : args . defaultWidth ;
var format = args . formats [ width ] || args . formats [ args . defaultWidth ] ;
return format ;
} ;
} var dateFormats = {
full : 'EEEE d MMMM y' ,
long : 'd MMMM y' ,
medium : 'd MMM y' ,
short : 'dd/MM/y'
} ;
var timeFormats = {
full : 'HH:mm:ss zzzz' ,
long : 'HH:mm:ss z' ,
medium : 'HH:mm:ss' ,
short : 'HH:mm'
} ;
var dateTimeFormats = {
full : "{{date}} 'à' {{time}}" ,
long : "{{date}} 'à' {{time}}" ,
medium : '{{date}}, {{time}}' ,
short : '{{date}}, {{time}}'
} ;
var formatLong = {
date : buildFormatLongFn ( {
formats : dateFormats ,
defaultWidth : 'full'
} ) ,
time : buildFormatLongFn ( {
formats : timeFormats ,
defaultWidth : 'full'
} ) ,
dateTime : buildFormatLongFn ( {
formats : dateTimeFormats ,
defaultWidth : 'full'
} )
} ; var formatRelativeLocale = {
lastWeek : "eeee 'dernier à' p" ,
yesterday : "'hier à' p" ,
today : "'aujourd’ hui à' p" ,
tomorrow : "'demain à' p'" ,
nextWeek : "eeee 'prochain à' p" ,
other : 'P'
} ;
function formatRelative ( token , _date , _baseDate , _options ) {
return formatRelativeLocale [ token ] ;
} function buildLocalizeFn ( args ) {
return function ( dirtyIndex , dirtyOptions ) {
var options = dirtyOptions || { } ;
var context = options . context ? String ( options . context ) : 'standalone' ;
var valuesArray ;
if ( context === 'formatting' && args . formattingValues ) {
var defaultWidth = args . defaultFormattingWidth || args . defaultWidth ;
var width = options . width ? String ( options . width ) : defaultWidth ;
valuesArray = args . formattingValues [ width ] || args . formattingValues [ defaultWidth ] ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
var _defaultWidth = args . defaultWidth ;
var _width = options . width ? String ( options . width ) : args . defaultWidth ;
valuesArray = args . values [ _width ] || args . values [ _defaultWidth ] ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var index = args . argumentCallback ? args . argumentCallback ( dirtyIndex ) : dirtyIndex ;
return valuesArray [ index ] ;
} ;
} var eraValues = {
narrow : [ 'av. J.-C' , 'ap. J.-C' ] ,
abbreviated : [ 'av. J.-C' , 'ap. J.-C' ] ,
wide : [ 'avant Jésus-Christ' , 'après Jésus-Christ' ]
} ;
var quarterValues = {
narrow : [ 'T1' , 'T2' , 'T3' , 'T4' ] ,
abbreviated : [ '1er trim.' , '2ème trim.' , '3ème trim.' , '4ème trim.' ] ,
wide : [ '1er trimestre' , '2ème trimestre' , '3ème trimestre' , '4ème trimestre' ]
} ;
var monthValues = {
narrow : [ 'J' , 'F' , 'M' , 'A' , 'M' , 'J' , 'J' , 'A' , 'S' , 'O' , 'N' , 'D' ] ,
abbreviated : [ 'janv.' , 'févr.' , 'mars' , 'avr.' , 'mai' , 'juin' , 'juil.' , 'août' , 'sept.' , 'oct.' , 'nov.' , 'déc.' ] ,
wide : [ 'janvier' , 'février' , 'mars' , 'avril' , 'mai' , 'juin' , 'juillet' , 'août' , 'septembre' , 'octobre' , 'novembre' , 'décembre' ]
} ;
var dayValues = {
narrow : [ 'D' , 'L' , 'M' , 'M' , 'J' , 'V' , 'S' ] ,
short : [ 'di' , 'lu' , 'ma' , 'me' , 'je' , 've' , 'sa' ] ,
abbreviated : [ 'dim.' , 'lun.' , 'mar.' , 'mer.' , 'jeu.' , 'ven.' , 'sam.' ] ,
wide : [ 'dimanche' , 'lundi' , 'mardi' , 'mercredi' , 'jeudi' , 'vendredi' , 'samedi' ]
} ;
var dayPeriodValues = {
narrow : {
am : 'AM' ,
pm : 'PM' ,
midnight : 'minuit' ,
noon : 'midi' ,
morning : 'mat.' ,
afternoon : 'ap.m.' ,
evening : 'soir' ,
night : 'mat.'
} ,
abbreviated : {
am : 'AM' ,
pm : 'PM' ,
midnight : 'minuit' ,
noon : 'midi' ,
morning : 'matin' ,
afternoon : 'après-midi' ,
evening : 'soir' ,
night : 'matin'
} ,
wide : {
am : 'AM' ,
pm : 'PM' ,
midnight : 'minuit' ,
noon : 'midi' ,
morning : 'du matin' ,
afternoon : 'de l’ après-midi' ,
evening : 'du soir' ,
night : 'du matin'
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function ordinalNumber ( dirtyNumber , dirtyOptions ) {
var number = Number ( dirtyNumber ) ;
var options = dirtyOptions || { } ;
var unit = String ( options . unit ) ;
var suffix ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( number === 0 ) {
return number ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
if ( unit === 'year' || unit === 'hour' || unit === 'week' ) {
if ( number === 1 ) {
suffix = 'ère' ;
} else {
suffix = 'ème' ;
}
} else {
if ( number === 1 ) {
suffix = 'er' ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
suffix = 'ème' ;
2019-08-02 20:18:05 +02:00
}
}
2020-01-16 19:29:13 +01:00
return number + suffix ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var localize = {
ordinalNumber : ordinalNumber ,
era : buildLocalizeFn ( {
values : eraValues ,
defaultWidth : 'wide'
} ) ,
quarter : buildLocalizeFn ( {
values : quarterValues ,
defaultWidth : 'wide' ,
argumentCallback : function ( quarter ) {
return Number ( quarter ) - 1 ;
}
} ) ,
month : buildLocalizeFn ( {
values : monthValues ,
defaultWidth : 'wide'
} ) ,
day : buildLocalizeFn ( {
values : dayValues ,
defaultWidth : 'wide'
} ) ,
dayPeriod : buildLocalizeFn ( {
values : dayPeriodValues ,
defaultWidth : 'wide'
} )
} ; function buildMatchPatternFn ( args ) {
return function ( dirtyString , dirtyOptions ) {
var string = String ( dirtyString ) ;
var options = dirtyOptions || { } ;
var matchResult = string . match ( args . matchPattern ) ;
if ( ! matchResult ) {
return null ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var matchedString = matchResult [ 0 ] ;
var parseResult = string . match ( args . parsePattern ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! parseResult ) {
return null ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var value = args . valueCallback ? args . valueCallback ( parseResult [ 0 ] ) : parseResult [ 0 ] ;
value = options . valueCallback ? options . valueCallback ( value ) : value ;
2019-08-02 20:18:05 +02:00
return {
2020-01-16 19:29:13 +01:00
value : value ,
rest : string . slice ( matchedString . length )
} ;
} ;
} function buildMatchFn ( args ) {
return function ( dirtyString , dirtyOptions ) {
var string = String ( dirtyString ) ;
var options = dirtyOptions || { } ;
var width = options . width ;
var matchPattern = width && args . matchPatterns [ width ] || args . matchPatterns [ args . defaultMatchWidth ] ;
var matchResult = string . match ( matchPattern ) ;
if ( ! matchResult ) {
return null ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var matchedString = matchResult [ 0 ] ;
var parsePatterns = width && args . parsePatterns [ width ] || args . parsePatterns [ args . defaultParseWidth ] ;
var value ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( Object . prototype . toString . call ( parsePatterns ) === '[object Array]' ) {
value = findIndex ( parsePatterns , function ( pattern ) {
return pattern . test ( string ) ;
} ) ;
} else {
value = findKey ( parsePatterns , function ( pattern ) {
return pattern . test ( string ) ;
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
value = args . valueCallback ? args . valueCallback ( value ) : value ;
value = options . valueCallback ? options . valueCallback ( value ) : value ;
return {
value : value ,
rest : string . slice ( matchedString . length )
} ;
} ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function findKey ( object , predicate ) {
for ( var key in object ) {
if ( object . hasOwnProperty ( key ) && predicate ( object [ key ] ) ) {
return key ;
}
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function findIndex ( array , predicate ) {
for ( var key = 0 ; key < array . length ; key ++ ) {
if ( predicate ( array [ key ] ) ) {
return key ;
}
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} var matchOrdinalNumberPattern = /^(\d+)(ième|ère|ème|er|e)?/i ;
var parseOrdinalNumberPattern = /\d+/i ;
var matchEraPatterns = {
narrow : /^(av\.J\.C|ap\.J\.C|ap\.J\.-C)/i ,
abbreviated : /^(av\.J\.-C|av\.J-C|apr\.J\.-C|apr\.J-C|ap\.J-C)/i ,
wide : /^(avant Jésus-Christ|après Jésus-Christ)/i
} ;
var parseEraPatterns = {
any : [ /^av/i , /^ap/i ]
} ;
var matchQuarterPatterns = {
narrow : /^[1234]/i ,
abbreviated : /^t[1234]/i ,
wide : /^[1234](er|ème|e)? trimestre/i
} ;
var parseQuarterPatterns = {
any : [ /1/i , /2/i , /3/i , /4/i ]
} ;
var matchMonthPatterns = {
narrow : /^[jfmasond]/i ,
abbreviated : /^(janv|févr|mars|avr|mai|juin|juill|juil|août|sept|oct|nov|déc)\.?/i ,
wide : /^(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)/i
} ;
var parseMonthPatterns = {
narrow : [ /^j/i , /^f/i , /^m/i , /^a/i , /^m/i , /^j/i , /^j/i , /^a/i , /^s/i , /^o/i , /^n/i , /^d/i ] ,
any : [ /^ja/i , /^f/i , /^mar/i , /^av/i , /^ma/i , /^juin/i , /^juil/i , /^ao/i , /^s/i , /^o/i , /^n/i , /^d/i ]
} ;
var matchDayPatterns = {
narrow : /^[lmjvsd]/i ,
short : /^(di|lu|ma|me|je|ve|sa)/i ,
abbreviated : /^(dim|lun|mar|mer|jeu|ven|sam)\.?/i ,
wide : /^(dimanche|lundi|mardi|mercredi|jeudi|vendredi|samedi)/i
} ;
var parseDayPatterns = {
narrow : [ /^d/i , /^l/i , /^m/i , /^m/i , /^j/i , /^v/i , /^s/i ] ,
any : [ /^di/i , /^lu/i , /^ma/i , /^me/i , /^je/i , /^ve/i , /^sa/i ]
} ;
var matchDayPeriodPatterns = {
narrow : /^(a|p|minuit|midi|mat\.?|ap\.?m\.?|soir|nuit)/i ,
any : /^([ap]\.?\s?m\.?|du matin|de l'après[-\s]midi|du soir|de la nuit)/i
} ;
var parseDayPeriodPatterns = {
any : {
am : /^a/i ,
pm : /^p/i ,
midnight : /^min/i ,
noon : /^mid/i ,
morning : /mat/i ,
afternoon : /ap/i ,
evening : /soir/i ,
night : /nuit/i
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
var match = {
ordinalNumber : buildMatchPatternFn ( {
matchPattern : matchOrdinalNumberPattern ,
parsePattern : parseOrdinalNumberPattern ,
valueCallback : function ( value ) {
return parseInt ( value , 10 ) ;
}
} ) ,
era : buildMatchFn ( {
matchPatterns : matchEraPatterns ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseEraPatterns ,
defaultParseWidth : 'any'
} ) ,
quarter : buildMatchFn ( {
matchPatterns : matchQuarterPatterns ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseQuarterPatterns ,
defaultParseWidth : 'any' ,
valueCallback : function ( index ) {
return index + 1 ;
}
} ) ,
month : buildMatchFn ( {
matchPatterns : matchMonthPatterns ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseMonthPatterns ,
defaultParseWidth : 'any'
} ) ,
day : buildMatchFn ( {
matchPatterns : matchDayPatterns ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseDayPatterns ,
defaultParseWidth : 'any'
} ) ,
dayPeriod : buildMatchFn ( {
matchPatterns : matchDayPeriodPatterns ,
defaultMatchWidth : 'any' ,
parsePatterns : parseDayPeriodPatterns ,
defaultParseWidth : 'any'
} )
} ; / * *
* @ type { Locale }
* @ category Locales
* @ summary French locale .
* @ language French
* @ iso - 639 - 2 fra
* @ author Jean Dupouy [ @ izeau ] { @ link https : //github.com/izeau}
* @ author François B [ @ fbonzon ] { @ link https : //github.com/fbonzon}
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var locale = {
code : 'fr' ,
formatDistance : formatDistance ,
formatLong : formatLong ,
formatRelative : formatRelative ,
localize : localize ,
match : match ,
options : {
weekStartsOn : 1
/* Monday */
,
firstWeekContainsDate : 1
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ; var formatDistanceLocale$1 = {
lessThanXSeconds : {
one : 'less than a second' ,
other : 'less than {{count}} seconds'
} ,
xSeconds : {
one : '1 second' ,
other : '{{count}} seconds'
} ,
halfAMinute : 'half a minute' ,
lessThanXMinutes : {
one : 'less than a minute' ,
other : 'less than {{count}} minutes'
} ,
xMinutes : {
one : '1 minute' ,
other : '{{count}} minutes'
} ,
aboutXHours : {
one : 'about 1 hour' ,
other : 'about {{count}} hours'
} ,
xHours : {
one : '1 hour' ,
other : '{{count}} hours'
} ,
xDays : {
one : '1 day' ,
other : '{{count}} days'
} ,
aboutXMonths : {
one : 'about 1 month' ,
other : 'about {{count}} months'
} ,
xMonths : {
one : '1 month' ,
other : '{{count}} months'
} ,
aboutXYears : {
one : 'about 1 year' ,
other : 'about {{count}} years'
} ,
xYears : {
one : '1 year' ,
other : '{{count}} years'
} ,
overXYears : {
one : 'over 1 year' ,
other : 'over {{count}} years'
} ,
almostXYears : {
one : 'almost 1 year' ,
other : 'almost {{count}} years'
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
function formatDistance$1 ( token , count , options ) {
options = options || { } ;
var result ;
if ( typeof formatDistanceLocale$1 [ token ] === 'string' ) {
result = formatDistanceLocale$1 [ token ] ;
} else if ( count === 1 ) {
result = formatDistanceLocale$1 [ token ] . one ;
} else {
result = formatDistanceLocale$1 [ token ] . other . replace ( '{{count}}' , count ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
if ( options . addSuffix ) {
if ( options . comparison > 0 ) {
return 'in ' + result ;
} else {
return result + ' ago' ;
}
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
return result ;
} var dateFormats$1 = {
full : 'EEEE, MMMM do, y' ,
long : 'MMMM do, y' ,
medium : 'MMM d, y' ,
short : 'MM/dd/yyyy'
} ;
var timeFormats$1 = {
full : 'h:mm:ss a zzzz' ,
long : 'h:mm:ss a z' ,
medium : 'h:mm:ss a' ,
short : 'h:mm a'
} ;
var dateTimeFormats$1 = {
full : "{{date}} 'at' {{time}}" ,
long : "{{date}} 'at' {{time}}" ,
medium : '{{date}}, {{time}}' ,
short : '{{date}}, {{time}}'
} ;
var formatLong$1 = {
date : buildFormatLongFn ( {
formats : dateFormats$1 ,
defaultWidth : 'full'
} ) ,
time : buildFormatLongFn ( {
formats : timeFormats$1 ,
defaultWidth : 'full'
} ) ,
dateTime : buildFormatLongFn ( {
formats : dateTimeFormats$1 ,
defaultWidth : 'full'
} )
} ; var formatRelativeLocale$1 = {
lastWeek : "'last' eeee 'at' p" ,
yesterday : "'yesterday at' p" ,
today : "'today at' p" ,
tomorrow : "'tomorrow at' p" ,
nextWeek : "eeee 'at' p" ,
other : 'P'
} ;
function formatRelative$1 ( token , _date , _baseDate , _options ) {
return formatRelativeLocale$1 [ token ] ;
} var eraValues$1 = {
narrow : [ 'B' , 'A' ] ,
abbreviated : [ 'BC' , 'AD' ] ,
wide : [ 'Before Christ' , 'Anno Domini' ]
} ;
var quarterValues$1 = {
narrow : [ '1' , '2' , '3' , '4' ] ,
abbreviated : [ 'Q1' , 'Q2' , 'Q3' , 'Q4' ] ,
wide : [ '1st quarter' , '2nd quarter' , '3rd quarter' , '4th quarter' ] // Note: in English, the names of days of the week and months are capitalized.
// If you are making a new locale based on this one, check if the same is true for the language you're working on.
// Generally, formatted dates should look like they are in the middle of a sentence,
// e.g. in Spanish language the weekdays and months should be in the lowercase.
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
} ;
var monthValues$1 = {
narrow : [ 'J' , 'F' , 'M' , 'A' , 'M' , 'J' , 'J' , 'A' , 'S' , 'O' , 'N' , 'D' ] ,
abbreviated : [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ] ,
wide : [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' ]
} ;
var dayValues$1 = {
narrow : [ 'S' , 'M' , 'T' , 'W' , 'T' , 'F' , 'S' ] ,
short : [ 'Su' , 'Mo' , 'Tu' , 'We' , 'Th' , 'Fr' , 'Sa' ] ,
abbreviated : [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ] ,
wide : [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ]
} ;
var dayPeriodValues$1 = {
narrow : {
am : 'a' ,
pm : 'p' ,
midnight : 'mi' ,
noon : 'n' ,
morning : 'morning' ,
afternoon : 'afternoon' ,
evening : 'evening' ,
night : 'night'
} ,
abbreviated : {
am : 'AM' ,
pm : 'PM' ,
midnight : 'midnight' ,
noon : 'noon' ,
morning : 'morning' ,
afternoon : 'afternoon' ,
evening : 'evening' ,
night : 'night'
} ,
wide : {
am : 'a.m.' ,
pm : 'p.m.' ,
midnight : 'midnight' ,
noon : 'noon' ,
morning : 'morning' ,
afternoon : 'afternoon' ,
evening : 'evening' ,
night : 'night'
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
var formattingDayPeriodValues = {
narrow : {
am : 'a' ,
pm : 'p' ,
midnight : 'mi' ,
noon : 'n' ,
morning : 'in the morning' ,
afternoon : 'in the afternoon' ,
evening : 'in the evening' ,
night : 'at night'
} ,
abbreviated : {
am : 'AM' ,
pm : 'PM' ,
midnight : 'midnight' ,
noon : 'noon' ,
morning : 'in the morning' ,
afternoon : 'in the afternoon' ,
evening : 'in the evening' ,
night : 'at night'
} ,
wide : {
am : 'a.m.' ,
pm : 'p.m.' ,
midnight : 'midnight' ,
noon : 'noon' ,
morning : 'in the morning' ,
afternoon : 'in the afternoon' ,
evening : 'in the evening' ,
night : 'at night'
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function ordinalNumber$1 ( dirtyNumber , _dirtyOptions ) {
var number = Number ( dirtyNumber ) ; // If ordinal numbers depend on context, for example,
// if they are different for different grammatical genders,
// use `options.unit`:
//
// var options = dirtyOptions || {}
// var unit = String(options.unit)
//
// where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
// 'day', 'hour', 'minute', 'second'
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var rem100 = number % 100 ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( rem100 > 20 || rem100 < 10 ) {
switch ( rem100 % 10 ) {
case 1 :
return number + 'st' ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
case 2 :
return number + 'nd' ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
case 3 :
return number + 'rd' ;
}
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return number + 'th' ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var localize$1 = {
ordinalNumber : ordinalNumber$1 ,
era : buildLocalizeFn ( {
values : eraValues$1 ,
defaultWidth : 'wide'
} ) ,
quarter : buildLocalizeFn ( {
values : quarterValues$1 ,
defaultWidth : 'wide' ,
argumentCallback : function ( quarter ) {
return Number ( quarter ) - 1 ;
}
} ) ,
month : buildLocalizeFn ( {
values : monthValues$1 ,
defaultWidth : 'wide'
} ) ,
day : buildLocalizeFn ( {
values : dayValues$1 ,
defaultWidth : 'wide'
} ) ,
dayPeriod : buildLocalizeFn ( {
values : dayPeriodValues$1 ,
defaultWidth : 'wide' ,
formattingValues : formattingDayPeriodValues ,
defaultFormattingWidth : 'wide'
} )
} ; var matchOrdinalNumberPattern$1 = /^(\d+)(th|st|nd|rd)?/i ;
var parseOrdinalNumberPattern$1 = /\d+/i ;
var matchEraPatterns$1 = {
narrow : /^(b|a)/i ,
abbreviated : /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i ,
wide : /^(before christ|before common era|anno domini|common era)/i
} ;
var parseEraPatterns$1 = {
any : [ /^b/i , /^(a|c)/i ]
} ;
var matchQuarterPatterns$1 = {
narrow : /^[1234]/i ,
abbreviated : /^q[1234]/i ,
wide : /^[1234](th|st|nd|rd)? quarter/i
} ;
var parseQuarterPatterns$1 = {
any : [ /1/i , /2/i , /3/i , /4/i ]
} ;
var matchMonthPatterns$1 = {
narrow : /^[jfmasond]/i ,
abbreviated : /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i ,
wide : /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
} ;
var parseMonthPatterns$1 = {
narrow : [ /^j/i , /^f/i , /^m/i , /^a/i , /^m/i , /^j/i , /^j/i , /^a/i , /^s/i , /^o/i , /^n/i , /^d/i ] ,
any : [ /^ja/i , /^f/i , /^mar/i , /^ap/i , /^may/i , /^jun/i , /^jul/i , /^au/i , /^s/i , /^o/i , /^n/i , /^d/i ]
} ;
var matchDayPatterns$1 = {
narrow : /^[smtwf]/i ,
short : /^(su|mo|tu|we|th|fr|sa)/i ,
abbreviated : /^(sun|mon|tue|wed|thu|fri|sat)/i ,
wide : /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
} ;
var parseDayPatterns$1 = {
narrow : [ /^s/i , /^m/i , /^t/i , /^w/i , /^t/i , /^f/i , /^s/i ] ,
any : [ /^su/i , /^m/i , /^tu/i , /^w/i , /^th/i , /^f/i , /^sa/i ]
} ;
var matchDayPeriodPatterns$1 = {
narrow : /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i ,
any : /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
} ;
var parseDayPeriodPatterns$1 = {
any : {
am : /^a/i ,
pm : /^p/i ,
midnight : /^mi/i ,
noon : /^no/i ,
morning : /morning/i ,
afternoon : /afternoon/i ,
evening : /evening/i ,
night : /night/i
}
} ;
var match$1 = {
ordinalNumber : buildMatchPatternFn ( {
matchPattern : matchOrdinalNumberPattern$1 ,
parsePattern : parseOrdinalNumberPattern$1 ,
valueCallback : function ( value ) {
return parseInt ( value , 10 ) ;
}
} ) ,
era : buildMatchFn ( {
matchPatterns : matchEraPatterns$1 ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseEraPatterns$1 ,
defaultParseWidth : 'any'
} ) ,
quarter : buildMatchFn ( {
matchPatterns : matchQuarterPatterns$1 ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseQuarterPatterns$1 ,
defaultParseWidth : 'any' ,
valueCallback : function ( index ) {
return index + 1 ;
}
} ) ,
month : buildMatchFn ( {
matchPatterns : matchMonthPatterns$1 ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseMonthPatterns$1 ,
defaultParseWidth : 'any'
} ) ,
day : buildMatchFn ( {
matchPatterns : matchDayPatterns$1 ,
defaultMatchWidth : 'wide' ,
parsePatterns : parseDayPatterns$1 ,
defaultParseWidth : 'any'
} ) ,
dayPeriod : buildMatchFn ( {
matchPatterns : matchDayPeriodPatterns$1 ,
defaultMatchWidth : 'any' ,
parsePatterns : parseDayPeriodPatterns$1 ,
defaultParseWidth : 'any'
} )
} ; / * *
* @ type { Locale }
* @ category Locales
* @ summary English locale ( United States ) .
* @ language English
* @ iso - 639 - 2 eng
* @ author Sasha Koss [ @ kossnocorp ] { @ link https : //github.com/kossnocorp}
* @ author Lesha Koss [ @ leshakoss ] { @ link https : //github.com/leshakoss}
2019-08-02 20:18:05 +02:00
* /
2020-01-16 19:29:13 +01:00
var locale$1 = {
code : 'en-US' ,
formatDistance : formatDistance$1 ,
formatLong : formatLong$1 ,
formatRelative : formatRelative$1 ,
localize : localize$1 ,
match : match$1 ,
options : {
weekStartsOn : 0
/* Sunday */
,
firstWeekContainsDate : 1
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ; function requiredArgs ( required , args ) {
if ( args . length < required ) {
throw new TypeError ( required + ' argument' + required > 1 ? 's' : '' + ' required, but only ' + args . length + ' present' ) ;
}
} / * *
* @ name toDate
* @ category Common Helpers
* @ summary Convert the given argument to an instance of Date .
2019-08-02 20:18:05 +02:00
*
* @ description
2020-01-16 19:29:13 +01:00
* Convert the given argument to an instance of Date .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* If the argument is an instance of Date , the function returns its clone .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* If the argument is a number , it is treated as a timestamp .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* If the argument is none of the above , the function returns Invalid Date .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* * * Note * * : * all * Date arguments passed to any * date - fns * function is processed by ` toDate ` .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* @ param { Date | Number } argument - the value to convert
* @ returns { Date } the parsed date in the local time zone
* @ throws { TypeError } 1 argument required
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* @ example
* // Clone the date:
* const result = toDate ( new Date ( 2014 , 1 , 11 , 11 , 30 , 30 ) )
* //=> Tue Feb 11 2014 11:30:30
2019-08-02 20:18:05 +02:00
*
* @ example
2020-01-16 19:29:13 +01:00
* // Convert the timestamp to date:
* const result = toDate ( 1392098430000 )
* //=> Tue Feb 11 2014 11:30:30
2019-08-02 20:18:05 +02:00
* /
2020-01-16 19:29:13 +01:00
function toDate ( argument ) {
requiredArgs ( 1 , arguments ) ;
var argStr = Object . prototype . toString . call ( argument ) ; // Clone the date
if ( argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]' ) {
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
return new Date ( argument . getTime ( ) ) ;
} else if ( typeof argument === 'number' || argStr === '[object Number]' ) {
return new Date ( argument ) ;
} else {
if ( ( typeof argument === 'string' || argStr === '[object String]' ) && typeof console !== 'undefined' ) {
// eslint-disable-next-line no-console
console . warn ( "Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule" ) ; // eslint-disable-next-line no-console
console . warn ( new Error ( ) . stack ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return new Date ( NaN ) ;
}
} / * *
* @ name isValid
2019-08-02 20:18:05 +02:00
* @ category Common Helpers
* @ summary Is the given date valid ?
*
* @ description
* Returns false if argument is Invalid Date and true otherwise .
2020-01-16 19:29:13 +01:00
* Argument is converted to Date using ` toDate ` . See [ toDate ] { @ link https : //date-fns.org/docs/toDate}
2019-08-02 20:18:05 +02:00
* Invalid Date is a Date , whose time value is NaN .
*
* Time value of Date : http : //es5.github.io/#x15.9.1.1
*
2020-01-16 19:29:13 +01:00
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* - Now ` isValid ` doesn ' t throw an exception
* if the first argument is not an instance of Date .
* Instead , argument is converted beforehand using ` toDate ` .
*
* Examples :
*
* | ` isValid ` argument | Before v2 . 0.0 | v2 . 0.0 onward |
* | -- -- -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- - |
* | ` new Date() ` | ` true ` | ` true ` |
* | ` new Date('2016-01-01') ` | ` true ` | ` true ` |
* | ` new Date('') ` | ` false ` | ` false ` |
* | ` new Date(1488370835081) ` | ` true ` | ` true ` |
* | ` new Date(NaN) ` | ` false ` | ` false ` |
* | ` '2016-01-01' ` | ` TypeError ` | ` false ` |
* | ` '' ` | ` TypeError ` | ` false ` |
* | ` 1488370835081 ` | ` TypeError ` | ` true ` |
* | ` NaN ` | ` TypeError ` | ` false ` |
*
* We introduce this change to make * date - fns * consistent with ECMAScript behavior
* that try to coerce arguments to the expected type
* ( which is also the case with other * date - fns * functions ) .
*
* @ param { * } date - the date to check
2019-08-02 20:18:05 +02:00
* @ returns { Boolean } the date is valid
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 1 argument required
2019-08-02 20:18:05 +02:00
*
* @ example
* // For the valid date:
* var result = isValid ( new Date ( 2014 , 1 , 31 ) )
* //=> true
*
* @ example
2020-01-16 19:29:13 +01:00
* // For the value, convertable into a date:
* var result = isValid ( 1393804800000 )
* //=> true
*
* @ example
2019-08-02 20:18:05 +02:00
* // For the invalid date:
* var result = isValid ( new Date ( '' ) )
* //=> false
* /
2020-01-16 19:29:13 +01:00
function isValid ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate ) ;
return ! isNaN ( date ) ;
} function toInteger ( dirtyNumber ) {
if ( dirtyNumber === null || dirtyNumber === true || dirtyNumber === false ) {
return NaN ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var number = Number ( dirtyNumber ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( isNaN ( number ) ) {
return number ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return number < 0 ? Math . ceil ( number ) : Math . floor ( number ) ;
} / * *
* @ name addMilliseconds
* @ category Millisecond Helpers
* @ summary Add the specified number of milliseconds to the given date .
*
* @ description
* Add the specified number of milliseconds to the given date .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } date - the date to be changed
2020-03-23 16:25:45 +01:00
* @ param { Number } amount - the amount of milliseconds to be added . Positive decimals will be rounded using ` Math.floor ` , decimals less than zero will be rounded using ` Math.ceil ` .
2020-01-16 19:29:13 +01:00
* @ returns { Date } the new date with the milliseconds added
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
* var result = addMilliseconds ( new Date ( 2014 , 6 , 10 , 12 , 45 , 30 , 0 ) , 750 )
* //=> Thu Jul 10 2014 12:45:30.750
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function addMilliseconds ( dirtyDate , dirtyAmount ) {
requiredArgs ( 2 , arguments ) ;
var timestamp = toDate ( dirtyDate ) . getTime ( ) ;
var amount = toInteger ( dirtyAmount ) ;
return new Date ( timestamp + amount ) ;
} / * *
* @ name subMilliseconds
* @ category Millisecond Helpers
* @ summary Subtract the specified number of milliseconds from the given date .
*
* @ description
* Subtract the specified number of milliseconds from the given date .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } date - the date to be changed
2020-03-23 16:25:45 +01:00
* @ param { Number } amount - the amount of milliseconds to be subtracted . Positive decimals will be rounded using ` Math.floor ` , decimals less than zero will be rounded using ` Math.ceil ` .
2020-01-16 19:29:13 +01:00
* @ returns { Date } the new date with the milliseconds subtracted
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
* var result = subMilliseconds ( new Date ( 2014 , 6 , 10 , 12 , 45 , 30 , 0 ) , 750 )
* //=> Thu Jul 10 2014 12:45:29.250
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function subMilliseconds ( dirtyDate , dirtyAmount ) {
requiredArgs ( 2 , arguments ) ;
var amount = toInteger ( dirtyAmount ) ;
return addMilliseconds ( dirtyDate , - amount ) ;
} function addLeadingZeros ( number , targetLength ) {
var sign = number < 0 ? '-' : '' ;
var output = Math . abs ( number ) . toString ( ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
while ( output . length < targetLength ) {
output = '0' + output ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return sign + output ;
} / *
* | | Unit | | Unit |
* | -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
* | a | AM , PM | A * | |
* | d | Day of month | D | |
* | h | Hour [ 1 - 12 ] | H | Hour [ 0 - 23 ] |
* | m | Minute | M | Month |
* | s | Second | S | Fraction of second |
* | y | Year ( abs ) | Y | |
*
* Letters marked by * are not implemented but reserved by Unicode standard .
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var formatters = {
// Year
y : function ( date , token ) {
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
// | Year | y | yy | yyy | yyyy | yyyyy |
// |----------|-------|----|-------|-------|-------|
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
var signedYear = date . getUTCFullYear ( ) ; // Returns 1 for 1 BC (which is year 0 in JavaScript)
var year = signedYear > 0 ? signedYear : 1 - signedYear ;
return addLeadingZeros ( token === 'yy' ? year % 100 : year , token . length ) ;
} ,
// Month
M : function ( date , token ) {
var month = date . getUTCMonth ( ) ;
return token === 'M' ? String ( month + 1 ) : addLeadingZeros ( month + 1 , 2 ) ;
} ,
// Day of the month
d : function ( date , token ) {
return addLeadingZeros ( date . getUTCDate ( ) , token . length ) ;
} ,
// AM or PM
a : function ( date , token ) {
var dayPeriodEnumValue = date . getUTCHours ( ) / 12 >= 1 ? 'pm' : 'am' ;
switch ( token ) {
case 'a' :
case 'aa' :
case 'aaa' :
return dayPeriodEnumValue . toUpperCase ( ) ;
case 'aaaaa' :
return dayPeriodEnumValue [ 0 ] ;
case 'aaaa' :
default :
return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.' ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ,
// Hour [1-12]
h : function ( date , token ) {
return addLeadingZeros ( date . getUTCHours ( ) % 12 || 12 , token . length ) ;
} ,
// Hour [0-23]
H : function ( date , token ) {
return addLeadingZeros ( date . getUTCHours ( ) , token . length ) ;
} ,
// Minute
m : function ( date , token ) {
return addLeadingZeros ( date . getUTCMinutes ( ) , token . length ) ;
} ,
// Second
s : function ( date , token ) {
return addLeadingZeros ( date . getUTCSeconds ( ) , token . length ) ;
} ,
// Fraction of second
S : function ( date , token ) {
var numberOfDigits = token . length ;
var milliseconds = date . getUTCMilliseconds ( ) ;
var fractionalSeconds = Math . floor ( milliseconds * Math . pow ( 10 , numberOfDigits - 3 ) ) ;
return addLeadingZeros ( fractionalSeconds , token . length ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ; var MILLISECONDS _IN _DAY = 86400000 ; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCDayOfYear ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate ) ;
var timestamp = date . getTime ( ) ;
date . setUTCMonth ( 0 , 1 ) ;
date . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var startOfYearTimestamp = date . getTime ( ) ;
var difference = timestamp - startOfYearTimestamp ;
return Math . floor ( difference / MILLISECONDS _IN _DAY ) + 1 ;
} // See issue: https://github.com/date-fns/date-fns/issues/376
function startOfUTCISOWeek ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var weekStartsOn = 1 ;
var date = toDate ( dirtyDate ) ;
var day = date . getUTCDay ( ) ;
var diff = ( day < weekStartsOn ? 7 : 0 ) + day - weekStartsOn ;
date . setUTCDate ( date . getUTCDate ( ) - diff ) ;
date . setUTCHours ( 0 , 0 , 0 , 0 ) ;
return date ;
} // See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCISOWeekYear ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate ) ;
var year = date . getUTCFullYear ( ) ;
var fourthOfJanuaryOfNextYear = new Date ( 0 ) ;
fourthOfJanuaryOfNextYear . setUTCFullYear ( year + 1 , 0 , 4 ) ;
fourthOfJanuaryOfNextYear . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var startOfNextYear = startOfUTCISOWeek ( fourthOfJanuaryOfNextYear ) ;
var fourthOfJanuaryOfThisYear = new Date ( 0 ) ;
fourthOfJanuaryOfThisYear . setUTCFullYear ( year , 0 , 4 ) ;
fourthOfJanuaryOfThisYear . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var startOfThisYear = startOfUTCISOWeek ( fourthOfJanuaryOfThisYear ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( date . getTime ( ) >= startOfNextYear . getTime ( ) ) {
return year + 1 ;
} else if ( date . getTime ( ) >= startOfThisYear . getTime ( ) ) {
return year ;
} else {
return year - 1 ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} // See issue: https://github.com/date-fns/date-fns/issues/376
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function startOfUTCISOWeekYear ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var year = getUTCISOWeekYear ( dirtyDate ) ;
var fourthOfJanuary = new Date ( 0 ) ;
fourthOfJanuary . setUTCFullYear ( year , 0 , 4 ) ;
fourthOfJanuary . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var date = startOfUTCISOWeek ( fourthOfJanuary ) ;
return date ;
} var MILLISECONDS _IN _WEEK = 604800000 ; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCISOWeek ( dirtyDate ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate ) ;
var diff = startOfUTCISOWeek ( date ) . getTime ( ) - startOfUTCISOWeekYear ( date ) . getTime ( ) ; // Round the number of days to the nearest integer
// because the number of milliseconds in a week is not constant
// (e.g. it's different in the week of the daylight saving time clock shift)
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return Math . round ( diff / MILLISECONDS _IN _WEEK ) + 1 ;
} // See issue: https://github.com/date-fns/date-fns/issues/376
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function startOfUTCWeek ( dirtyDate , dirtyOptions ) {
requiredArgs ( 1 , arguments ) ;
var options = dirtyOptions || { } ;
var locale = options . locale ;
var localeWeekStartsOn = locale && locale . options && locale . options . weekStartsOn ;
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger ( localeWeekStartsOn ) ;
var weekStartsOn = options . weekStartsOn == null ? defaultWeekStartsOn : toInteger ( options . weekStartsOn ) ; // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! ( weekStartsOn >= 0 && weekStartsOn <= 6 ) ) {
throw new RangeError ( 'weekStartsOn must be between 0 and 6 inclusively' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var date = toDate ( dirtyDate ) ;
var day = date . getUTCDay ( ) ;
var diff = ( day < weekStartsOn ? 7 : 0 ) + day - weekStartsOn ;
date . setUTCDate ( date . getUTCDate ( ) - diff ) ;
date . setUTCHours ( 0 , 0 , 0 , 0 ) ;
return date ;
} // See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCWeekYear ( dirtyDate , dirtyOptions ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate , dirtyOptions ) ;
var year = date . getUTCFullYear ( ) ;
var options = dirtyOptions || { } ;
var locale = options . locale ;
var localeFirstWeekContainsDate = locale && locale . options && locale . options . firstWeekContainsDate ;
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger ( localeFirstWeekContainsDate ) ;
var firstWeekContainsDate = options . firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger ( options . firstWeekContainsDate ) ; // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! ( firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7 ) ) {
throw new RangeError ( 'firstWeekContainsDate must be between 1 and 7 inclusively' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var firstWeekOfNextYear = new Date ( 0 ) ;
firstWeekOfNextYear . setUTCFullYear ( year + 1 , 0 , firstWeekContainsDate ) ;
firstWeekOfNextYear . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var startOfNextYear = startOfUTCWeek ( firstWeekOfNextYear , dirtyOptions ) ;
var firstWeekOfThisYear = new Date ( 0 ) ;
firstWeekOfThisYear . setUTCFullYear ( year , 0 , firstWeekContainsDate ) ;
firstWeekOfThisYear . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var startOfThisYear = startOfUTCWeek ( firstWeekOfThisYear , dirtyOptions ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( date . getTime ( ) >= startOfNextYear . getTime ( ) ) {
return year + 1 ;
} else if ( date . getTime ( ) >= startOfThisYear . getTime ( ) ) {
return year ;
} else {
return year - 1 ;
}
} // See issue: https://github.com/date-fns/date-fns/issues/376
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function startOfUTCWeekYear ( dirtyDate , dirtyOptions ) {
requiredArgs ( 1 , arguments ) ;
var options = dirtyOptions || { } ;
var locale = options . locale ;
var localeFirstWeekContainsDate = locale && locale . options && locale . options . firstWeekContainsDate ;
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger ( localeFirstWeekContainsDate ) ;
var firstWeekContainsDate = options . firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger ( options . firstWeekContainsDate ) ;
var year = getUTCWeekYear ( dirtyDate , dirtyOptions ) ;
var firstWeek = new Date ( 0 ) ;
firstWeek . setUTCFullYear ( year , 0 , firstWeekContainsDate ) ;
firstWeek . setUTCHours ( 0 , 0 , 0 , 0 ) ;
var date = startOfUTCWeek ( firstWeek , dirtyOptions ) ;
return date ;
} var MILLISECONDS _IN _WEEK$1 = 604800000 ; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCWeek ( dirtyDate , options ) {
requiredArgs ( 1 , arguments ) ;
var date = toDate ( dirtyDate ) ;
var diff = startOfUTCWeek ( date , options ) . getTime ( ) - startOfUTCWeekYear ( date , options ) . getTime ( ) ; // Round the number of days to the nearest integer
// because the number of milliseconds in a week is not constant
// (e.g. it's different in the week of the daylight saving time clock shift)
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return Math . round ( diff / MILLISECONDS _IN _WEEK$1 ) + 1 ;
} var dayPeriodEnum = {
am : 'am' ,
pm : 'pm' ,
midnight : 'midnight' ,
noon : 'noon' ,
morning : 'morning' ,
afternoon : 'afternoon' ,
evening : 'evening' ,
night : 'night'
/ *
* | | Unit | | Unit |
* | -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
* | a | AM , PM | A * | Milliseconds in day |
* | b | AM , PM , noon , midnight | B | Flexible day period |
* | c | Stand - alone local day of week | C * | Localized hour w / day period |
* | d | Day of month | D | Day of year |
* | e | Local day of week | E | Day of week |
* | f | | F * | Day of week in month |
* | g * | Modified Julian day | G | Era |
* | h | Hour [ 1 - 12 ] | H | Hour [ 0 - 23 ] |
* | i ! | ISO day of week | I ! | ISO week of year |
* | j * | Localized hour w / day period | J * | Localized hour w / o day period |
* | k | Hour [ 1 - 24 ] | K | Hour [ 0 - 11 ] |
* | l * | ( deprecated ) | L | Stand - alone month |
* | m | Minute | M | Month |
* | n | | N | |
* | o ! | Ordinal number modifier | O | Timezone ( GMT ) |
* | p ! | Long localized time | P ! | Long localized date |
* | q | Stand - alone quarter | Q | Quarter |
* | r * | Related Gregorian year | R ! | ISO week - numbering year |
* | s | Second | S | Fraction of second |
* | t ! | Seconds timestamp | T ! | Milliseconds timestamp |
* | u | Extended year | U * | Cyclic year |
* | v * | Timezone ( generic non - locat . ) | V * | Timezone ( location ) |
* | w | Local week of year | W * | Week of month |
* | x | Timezone ( ISO - 8601 w / o Z ) | X | Timezone ( ISO - 8601 ) |
* | y | Year ( abs ) | Y | Local week - numbering year |
* | z | Timezone ( specific non - locat . ) | Z * | Timezone ( aliases ) |
*
* Letters marked by * are not implemented but reserved by Unicode standard .
*
* Letters marked by ! are non - standard , but implemented by date - fns :
* - ` o ` modifies the previous token to turn it into an ordinal ( see ` format ` docs )
* - ` i ` is ISO day of week . For ` i ` and ` ii ` is returns numeric ISO week days ,
* i . e . 7 for Sunday , 1 for Monday , etc .
* - ` I ` is ISO week of year , as opposed to ` w ` which is local week of year .
* - ` R ` is ISO week - numbering year , as opposed to ` Y ` which is local week - numbering year .
* ` R ` is supposed to be used in conjunction with ` I ` and ` i `
* for universal ISO week - numbering date , whereas
* ` Y ` is supposed to be used in conjunction with ` w ` and ` e `
* for week - numbering date specific to the locale .
* - ` P ` is long localized date format
* - ` p ` is long localized time format
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
} ;
var formatters$1 = {
// Era
G : function ( date , token , localize ) {
var era = date . getUTCFullYear ( ) > 0 ? 1 : 0 ;
switch ( token ) {
// AD, BC
case 'G' :
case 'GG' :
case 'GGG' :
return localize . era ( era , {
width : 'abbreviated'
} ) ;
// A, B
case 'GGGGG' :
return localize . era ( era , {
width : 'narrow'
} ) ;
// Anno Domini, Before Christ
case 'GGGG' :
default :
return localize . era ( era , {
width : 'wide'
} ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} ,
// Year
y : function ( date , token , localize ) {
// Ordinal number
if ( token === 'yo' ) {
var signedYear = date . getUTCFullYear ( ) ; // Returns 1 for 1 BC (which is year 0 in JavaScript)
var year = signedYear > 0 ? signedYear : 1 - signedYear ;
return localize . ordinalNumber ( year , {
unit : 'year'
} ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
return formatters . y ( date , token ) ;
} ,
// Local week-numbering year
Y : function ( date , token , localize , options ) {
var signedWeekYear = getUTCWeekYear ( date , options ) ; // Returns 1 for 1 BC (which is year 0 in JavaScript)
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear ; // Two digit year
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( token === 'YY' ) {
var twoDigitYear = weekYear % 100 ;
return addLeadingZeros ( twoDigitYear , 2 ) ;
} // Ordinal number
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( token === 'Yo' ) {
return localize . ordinalNumber ( weekYear , {
unit : 'year'
} ) ;
} // Padding
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( weekYear , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// ISO week-numbering year
R : function ( date , token ) {
var isoWeekYear = getUTCISOWeekYear ( date ) ; // Padding
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( isoWeekYear , token . length ) ;
} ,
// Extended year. This is a single number designating the year of this calendar system.
// The main difference between `y` and `u` localizers are B.C. years:
// | Year | `y` | `u` |
// |------|-----|-----|
// | AC 1 | 1 | 1 |
// | BC 1 | 1 | 0 |
// | BC 2 | 2 | -1 |
// Also `yy` always returns the last two digits of a year,
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
u : function ( date , token ) {
var year = date . getUTCFullYear ( ) ;
return addLeadingZeros ( year , token . length ) ;
} ,
// Quarter
Q : function ( date , token , localize ) {
var quarter = Math . ceil ( ( date . getUTCMonth ( ) + 1 ) / 3 ) ;
switch ( token ) {
// 1, 2, 3, 4
case 'Q' :
return String ( quarter ) ;
// 01, 02, 03, 04
case 'QQ' :
return addLeadingZeros ( quarter , 2 ) ;
// 1st, 2nd, 3rd, 4th
case 'Qo' :
return localize . ordinalNumber ( quarter , {
unit : 'quarter'
} ) ;
// Q1, Q2, Q3, Q4
case 'QQQ' :
return localize . quarter ( quarter , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
case 'QQQQQ' :
return localize . quarter ( quarter , {
width : 'narrow' ,
context : 'formatting'
} ) ;
// 1st quarter, 2nd quarter, ...
case 'QQQQ' :
default :
return localize . quarter ( quarter , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
} ,
// Stand-alone quarter
q : function ( date , token , localize ) {
var quarter = Math . ceil ( ( date . getUTCMonth ( ) + 1 ) / 3 ) ;
switch ( token ) {
// 1, 2, 3, 4
case 'q' :
return String ( quarter ) ;
// 01, 02, 03, 04
case 'qq' :
return addLeadingZeros ( quarter , 2 ) ;
// 1st, 2nd, 3rd, 4th
case 'qo' :
return localize . ordinalNumber ( quarter , {
unit : 'quarter'
} ) ;
// Q1, Q2, Q3, Q4
case 'qqq' :
return localize . quarter ( quarter , {
width : 'abbreviated' ,
context : 'standalone'
} ) ;
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
case 'qqqqq' :
return localize . quarter ( quarter , {
width : 'narrow' ,
context : 'standalone'
} ) ;
// 1st quarter, 2nd quarter, ...
case 'qqqq' :
default :
return localize . quarter ( quarter , {
width : 'wide' ,
context : 'standalone'
} ) ;
}
} ,
// Month
M : function ( date , token , localize ) {
var month = date . getUTCMonth ( ) ;
switch ( token ) {
case 'M' :
case 'MM' :
return formatters . M ( date , token ) ;
// 1st, 2nd, ..., 12th
case 'Mo' :
return localize . ordinalNumber ( month + 1 , {
unit : 'month'
} ) ;
// Jan, Feb, ..., Dec
case 'MMM' :
return localize . month ( month , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
// J, F, ..., D
case 'MMMMM' :
return localize . month ( month , {
width : 'narrow' ,
context : 'formatting'
} ) ;
// January, February, ..., December
case 'MMMM' :
default :
return localize . month ( month , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
} ,
// Stand-alone month
L : function ( date , token , localize ) {
var month = date . getUTCMonth ( ) ;
switch ( token ) {
// 1, 2, ..., 12
case 'L' :
return String ( month + 1 ) ;
// 01, 02, ..., 12
case 'LL' :
return addLeadingZeros ( month + 1 , 2 ) ;
// 1st, 2nd, ..., 12th
case 'Lo' :
return localize . ordinalNumber ( month + 1 , {
unit : 'month'
} ) ;
// Jan, Feb, ..., Dec
case 'LLL' :
return localize . month ( month , {
width : 'abbreviated' ,
context : 'standalone'
} ) ;
// J, F, ..., D
case 'LLLLL' :
return localize . month ( month , {
width : 'narrow' ,
context : 'standalone'
} ) ;
// January, February, ..., December
case 'LLLL' :
default :
return localize . month ( month , {
width : 'wide' ,
context : 'standalone'
} ) ;
}
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Local week of year
w : function ( date , token , localize , options ) {
var week = getUTCWeek ( date , options ) ;
if ( token === 'wo' ) {
return localize . ordinalNumber ( week , {
unit : 'week'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( week , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// ISO week of year
I : function ( date , token , localize ) {
var isoWeek = getUTCISOWeek ( date ) ;
if ( token === 'Io' ) {
return localize . ordinalNumber ( isoWeek , {
unit : 'week'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( isoWeek , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Day of the month
d : function ( date , token , localize ) {
if ( token === 'do' ) {
return localize . ordinalNumber ( date . getUTCDate ( ) , {
unit : 'date'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return formatters . d ( date , token ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Day of year
D : function ( date , token , localize ) {
var dayOfYear = getUTCDayOfYear ( date ) ;
if ( token === 'Do' ) {
return localize . ordinalNumber ( dayOfYear , {
unit : 'dayOfYear'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( dayOfYear , token . length ) ;
} ,
// Day of week
E : function ( date , token , localize ) {
var dayOfWeek = date . getUTCDay ( ) ;
switch ( token ) {
// Tue
case 'E' :
case 'EE' :
case 'EEE' :
return localize . day ( dayOfWeek , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
// T
case 'EEEEE' :
return localize . day ( dayOfWeek , {
width : 'narrow' ,
context : 'formatting'
} ) ;
// Tu
case 'EEEEEE' :
return localize . day ( dayOfWeek , {
width : 'short' ,
context : 'formatting'
} ) ;
// Tuesday
case 'EEEE' :
default :
return localize . day ( dayOfWeek , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
} ,
// Local day of week
e : function ( date , token , localize , options ) {
var dayOfWeek = date . getUTCDay ( ) ;
var localDayOfWeek = ( dayOfWeek - options . weekStartsOn + 8 ) % 7 || 7 ;
switch ( token ) {
// Numerical value (Nth day of week with current locale or weekStartsOn)
case 'e' :
return String ( localDayOfWeek ) ;
// Padded numerical value
case 'ee' :
return addLeadingZeros ( localDayOfWeek , 2 ) ;
// 1st, 2nd, ..., 7th
case 'eo' :
return localize . ordinalNumber ( localDayOfWeek , {
unit : 'day'
} ) ;
case 'eee' :
return localize . day ( dayOfWeek , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
// T
case 'eeeee' :
return localize . day ( dayOfWeek , {
width : 'narrow' ,
context : 'formatting'
} ) ;
// Tu
case 'eeeeee' :
return localize . day ( dayOfWeek , {
width : 'short' ,
context : 'formatting'
} ) ;
// Tuesday
case 'eeee' :
default :
return localize . day ( dayOfWeek , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
} ,
// Stand-alone local day of week
c : function ( date , token , localize , options ) {
var dayOfWeek = date . getUTCDay ( ) ;
var localDayOfWeek = ( dayOfWeek - options . weekStartsOn + 8 ) % 7 || 7 ;
switch ( token ) {
// Numerical value (same as in `e`)
case 'c' :
return String ( localDayOfWeek ) ;
// Padded numerical value
case 'cc' :
return addLeadingZeros ( localDayOfWeek , token . length ) ;
// 1st, 2nd, ..., 7th
case 'co' :
return localize . ordinalNumber ( localDayOfWeek , {
unit : 'day'
} ) ;
case 'ccc' :
return localize . day ( dayOfWeek , {
width : 'abbreviated' ,
context : 'standalone'
} ) ;
// T
case 'ccccc' :
return localize . day ( dayOfWeek , {
width : 'narrow' ,
context : 'standalone'
} ) ;
// Tu
case 'cccccc' :
return localize . day ( dayOfWeek , {
width : 'short' ,
context : 'standalone'
} ) ;
// Tuesday
case 'cccc' :
default :
return localize . day ( dayOfWeek , {
width : 'wide' ,
context : 'standalone'
} ) ;
}
} ,
// ISO day of week
i : function ( date , token , localize ) {
var dayOfWeek = date . getUTCDay ( ) ;
var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek ;
switch ( token ) {
// 2
case 'i' :
return String ( isoDayOfWeek ) ;
// 02
case 'ii' :
return addLeadingZeros ( isoDayOfWeek , token . length ) ;
// 2nd
case 'io' :
return localize . ordinalNumber ( isoDayOfWeek , {
unit : 'day'
} ) ;
// Tue
case 'iii' :
return localize . day ( dayOfWeek , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
// T
case 'iiiii' :
return localize . day ( dayOfWeek , {
width : 'narrow' ,
context : 'formatting'
} ) ;
// Tu
case 'iiiiii' :
return localize . day ( dayOfWeek , {
width : 'short' ,
context : 'formatting'
} ) ;
// Tuesday
case 'iiii' :
default :
return localize . day ( dayOfWeek , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
} ,
// AM or PM
a : function ( date , token , localize ) {
var hours = date . getUTCHours ( ) ;
var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am' ;
switch ( token ) {
case 'a' :
case 'aa' :
case 'aaa' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
case 'aaaaa' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'narrow' ,
context : 'formatting'
} ) ;
case 'aaaa' :
default :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// AM, PM, midnight, noon
b : function ( date , token , localize ) {
var hours = date . getUTCHours ( ) ;
var dayPeriodEnumValue ;
if ( hours === 12 ) {
dayPeriodEnumValue = dayPeriodEnum . noon ;
} else if ( hours === 0 ) {
dayPeriodEnumValue = dayPeriodEnum . midnight ;
} else {
dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am' ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
switch ( token ) {
case 'b' :
case 'bb' :
case 'bbb' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
case 'bbbbb' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'narrow' ,
context : 'formatting'
} ) ;
case 'bbbb' :
default :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// in the morning, in the afternoon, in the evening, at night
B : function ( date , token , localize ) {
var hours = date . getUTCHours ( ) ;
var dayPeriodEnumValue ;
if ( hours >= 17 ) {
dayPeriodEnumValue = dayPeriodEnum . evening ;
} else if ( hours >= 12 ) {
dayPeriodEnumValue = dayPeriodEnum . afternoon ;
} else if ( hours >= 4 ) {
dayPeriodEnumValue = dayPeriodEnum . morning ;
} else {
dayPeriodEnumValue = dayPeriodEnum . night ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
switch ( token ) {
case 'B' :
case 'BB' :
case 'BBB' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'abbreviated' ,
context : 'formatting'
} ) ;
case 'BBBBB' :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'narrow' ,
context : 'formatting'
} ) ;
case 'BBBB' :
default :
return localize . dayPeriod ( dayPeriodEnumValue , {
width : 'wide' ,
context : 'formatting'
} ) ;
}
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Hour [1-12]
h : function ( date , token , localize ) {
if ( token === 'ho' ) {
var hours = date . getUTCHours ( ) % 12 ;
if ( hours === 0 ) hours = 12 ;
return localize . ordinalNumber ( hours , {
unit : 'hour'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return formatters . h ( date , token ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Hour [0-23]
H : function ( date , token , localize ) {
if ( token === 'Ho' ) {
return localize . ordinalNumber ( date . getUTCHours ( ) , {
unit : 'hour'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return formatters . H ( date , token ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Hour [0-11]
K : function ( date , token , localize ) {
var hours = date . getUTCHours ( ) % 12 ;
if ( token === 'Ko' ) {
return localize . ordinalNumber ( hours , {
unit : 'hour'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( hours , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Hour [1-24]
k : function ( date , token , localize ) {
var hours = date . getUTCHours ( ) ;
if ( hours === 0 ) hours = 24 ;
if ( token === 'ko' ) {
return localize . ordinalNumber ( hours , {
unit : 'hour'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return addLeadingZeros ( hours , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Minute
m : function ( date , token , localize ) {
if ( token === 'mo' ) {
return localize . ordinalNumber ( date . getUTCMinutes ( ) , {
unit : 'minute'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return formatters . m ( date , token ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Second
s : function ( date , token , localize ) {
if ( token === 'so' ) {
return localize . ordinalNumber ( date . getUTCSeconds ( ) , {
unit : 'second'
} ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return formatters . s ( date , token ) ;
} ,
// Fraction of second
S : function ( date , token ) {
return formatters . S ( date , token ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
X : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timezoneOffset = originalDate . getTimezoneOffset ( ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( timezoneOffset === 0 ) {
return 'Z' ;
}
switch ( token ) {
// Hours and optional minutes
case 'X' :
return formatTimezoneWithOptionalMinutes ( timezoneOffset ) ;
// Hours, minutes and optional seconds without `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `XX`
case 'XXXX' :
case 'XX' :
// Hours and minutes without `:` delimiter
return formatTimezone ( timezoneOffset ) ;
// Hours, minutes and optional seconds with `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `XXX`
case 'XXXXX' :
case 'XXX' : // Hours and minutes with `:` delimiter
default :
return formatTimezone ( timezoneOffset , ':' ) ;
}
} ,
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
x : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timezoneOffset = originalDate . getTimezoneOffset ( ) ;
switch ( token ) {
// Hours and optional minutes
case 'x' :
return formatTimezoneWithOptionalMinutes ( timezoneOffset ) ;
// Hours, minutes and optional seconds without `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `xx`
case 'xxxx' :
case 'xx' :
// Hours and minutes without `:` delimiter
return formatTimezone ( timezoneOffset ) ;
// Hours, minutes and optional seconds with `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `xxx`
case 'xxxxx' :
case 'xxx' : // Hours and minutes with `:` delimiter
default :
return formatTimezone ( timezoneOffset , ':' ) ;
}
} ,
// Timezone (GMT)
O : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timezoneOffset = originalDate . getTimezoneOffset ( ) ;
switch ( token ) {
// Short
case 'O' :
case 'OO' :
case 'OOO' :
return 'GMT' + formatTimezoneShort ( timezoneOffset , ':' ) ;
// Long
case 'OOOO' :
default :
return 'GMT' + formatTimezone ( timezoneOffset , ':' ) ;
}
} ,
// Timezone (specific non-location)
z : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timezoneOffset = originalDate . getTimezoneOffset ( ) ;
switch ( token ) {
// Short
case 'z' :
case 'zz' :
case 'zzz' :
return 'GMT' + formatTimezoneShort ( timezoneOffset , ':' ) ;
// Long
case 'zzzz' :
default :
return 'GMT' + formatTimezone ( timezoneOffset , ':' ) ;
}
} ,
// Seconds timestamp
t : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timestamp = Math . floor ( originalDate . getTime ( ) / 1000 ) ;
return addLeadingZeros ( timestamp , token . length ) ;
2019-08-02 20:18:05 +02:00
} ,
2020-01-16 19:29:13 +01:00
// Milliseconds timestamp
T : function ( date , token , _localize , options ) {
var originalDate = options . _originalDate || date ;
var timestamp = originalDate . getTime ( ) ;
return addLeadingZeros ( timestamp , token . length ) ;
}
} ;
function formatTimezoneShort ( offset , dirtyDelimiter ) {
var sign = offset > 0 ? '-' : '+' ;
var absOffset = Math . abs ( offset ) ;
var hours = Math . floor ( absOffset / 60 ) ;
var minutes = absOffset % 60 ;
if ( minutes === 0 ) {
return sign + String ( hours ) ;
}
var delimiter = dirtyDelimiter || '' ;
return sign + String ( hours ) + delimiter + addLeadingZeros ( minutes , 2 ) ;
}
function formatTimezoneWithOptionalMinutes ( offset , dirtyDelimiter ) {
if ( offset % 60 === 0 ) {
var sign = offset > 0 ? '-' : '+' ;
return sign + addLeadingZeros ( Math . abs ( offset ) / 60 , 2 ) ;
}
return formatTimezone ( offset , dirtyDelimiter ) ;
}
function formatTimezone ( offset , dirtyDelimiter ) {
var delimiter = dirtyDelimiter || '' ;
var sign = offset > 0 ? '-' : '+' ;
var absOffset = Math . abs ( offset ) ;
var hours = addLeadingZeros ( Math . floor ( absOffset / 60 ) , 2 ) ;
var minutes = addLeadingZeros ( absOffset % 60 , 2 ) ;
return sign + hours + delimiter + minutes ;
} function dateLongFormatter ( pattern , formatLong ) {
switch ( pattern ) {
case 'P' :
return formatLong . date ( {
width : 'short'
} ) ;
case 'PP' :
return formatLong . date ( {
width : 'medium'
} ) ;
case 'PPP' :
return formatLong . date ( {
width : 'long'
} ) ;
case 'PPPP' :
default :
return formatLong . date ( {
width : 'full'
} ) ;
}
}
function timeLongFormatter ( pattern , formatLong ) {
switch ( pattern ) {
case 'p' :
return formatLong . time ( {
width : 'short'
} ) ;
case 'pp' :
return formatLong . time ( {
width : 'medium'
} ) ;
case 'ppp' :
return formatLong . time ( {
width : 'long'
} ) ;
case 'pppp' :
default :
return formatLong . time ( {
width : 'full'
} ) ;
}
}
function dateTimeLongFormatter ( pattern , formatLong ) {
var matchResult = pattern . match ( /(P+)(p+)?/ ) ;
var datePattern = matchResult [ 1 ] ;
var timePattern = matchResult [ 2 ] ;
if ( ! timePattern ) {
return dateLongFormatter ( pattern , formatLong ) ;
}
var dateTimeFormat ;
switch ( datePattern ) {
case 'P' :
dateTimeFormat = formatLong . dateTime ( {
width : 'short'
} ) ;
break ;
case 'PP' :
dateTimeFormat = formatLong . dateTime ( {
width : 'medium'
} ) ;
break ;
case 'PPP' :
dateTimeFormat = formatLong . dateTime ( {
width : 'long'
} ) ;
break ;
case 'PPPP' :
default :
dateTimeFormat = formatLong . dateTime ( {
width : 'full'
} ) ;
break ;
}
return dateTimeFormat . replace ( '{{date}}' , dateLongFormatter ( datePattern , formatLong ) ) . replace ( '{{time}}' , timeLongFormatter ( timePattern , formatLong ) ) ;
}
var longFormatters = {
p : timeLongFormatter ,
P : dateTimeLongFormatter
} ; var MILLISECONDS _IN _MINUTE = 60000 ;
2020-03-23 16:25:45 +01:00
function getDateMillisecondsPart ( date ) {
return date . getTime ( ) % MILLISECONDS _IN _MINUTE ;
}
2020-01-16 19:29:13 +01:00
/ * *
* Google Chrome as of 67.0 . 3396.87 introduced timezones with offset that includes seconds .
* They usually appear for dates that denote time before the timezones were introduced
* ( e . g . for 'Europe/Prague' timezone the offset is GMT + 00 : 57 : 44 before 1 October 1891
* and GMT + 01 : 00 : 00 after that date )
*
* Date # getTimezoneOffset returns the offset in minutes and would return 57 for the example above ,
* which would lead to incorrect calculations .
*
* This function returns the timezone offset in milliseconds that takes seconds in account .
* /
2019-08-02 20:18:05 +02:00
2020-03-23 16:25:45 +01:00
2020-01-16 19:29:13 +01:00
function getTimezoneOffsetInMilliseconds ( dirtyDate ) {
var date = new Date ( dirtyDate . getTime ( ) ) ;
var baseTimezoneOffset = Math . ceil ( date . getTimezoneOffset ( ) ) ;
date . setSeconds ( 0 , 0 ) ;
2020-03-23 16:25:45 +01:00
var hasNegativeUTCOffset = baseTimezoneOffset > 0 ;
var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? ( MILLISECONDS _IN _MINUTE + getDateMillisecondsPart ( date ) ) % MILLISECONDS _IN _MINUTE : getDateMillisecondsPart ( date ) ;
2020-01-16 19:29:13 +01:00
return baseTimezoneOffset * MILLISECONDS _IN _MINUTE + millisecondsPartOfTimezoneOffset ;
} var protectedDayOfYearTokens = [ 'D' , 'DD' ] ;
var protectedWeekYearTokens = [ 'YY' , 'YYYY' ] ;
function isProtectedDayOfYearToken ( token ) {
return protectedDayOfYearTokens . indexOf ( token ) !== - 1 ;
}
function isProtectedWeekYearToken ( token ) {
return protectedWeekYearTokens . indexOf ( token ) !== - 1 ;
}
function throwProtectedError ( token ) {
if ( token === 'YYYY' ) {
throw new RangeError ( 'Use `yyyy` instead of `YYYY` for formatting years; see: https://git.io/fxCyr' ) ;
} else if ( token === 'YY' ) {
throw new RangeError ( 'Use `yy` instead of `YY` for formatting years; see: https://git.io/fxCyr' ) ;
} else if ( token === 'D' ) {
throw new RangeError ( 'Use `d` instead of `D` for formatting days of the month; see: https://git.io/fxCyr' ) ;
} else if ( token === 'DD' ) {
throw new RangeError ( 'Use `dd` instead of `DD` for formatting days of the month; see: https://git.io/fxCyr' ) ;
}
} // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
// (one of the certain letters followed by `o`)
// - (\w)\1* matches any sequences of the same letter
// - '' matches two quote characters in a row
// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
// except a single quote symbol, which ends the sequence.
// Two quote characters do not end the sequence.
// If there is no matching single quote
// then the sequence will continue until the end of the string.
// - . matches any single character unmatched by previous parts of the RegExps
var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g ; // This RegExp catches symbols escaped by quotes, and also
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g ;
var escapedStringRegExp = /^'([^]*?)'?$/ ;
var doubleQuoteRegExp = /''/g ;
var unescapedLatinCharacterRegExp = /[a-zA-Z]/ ;
/ * *
* @ name format
* @ category Common Helpers
* @ summary Format the date .
*
* @ description
* Return the formatted date string in the given format . The result may vary by locale .
*
* > ⚠ ️ Please note that the ` format ` tokens differ from Moment . js and other libraries .
* > See : https : //git.io/fxCyr
*
* The characters wrapped between two single quotes characters ( ' ) are escaped .
* Two single quotes in a row , whether inside or outside a quoted sequence , represent a 'real' single quote .
* ( see the last example )
*
* Format of the string is based on Unicode Technical Standard # 35 :
* https : //www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* with a few additions ( see note 7 below the table ) .
*
* Accepted patterns :
* | Unit | Pattern | Result examples | Notes |
* | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- - |
* | Era | G . . GGG | AD , BC | |
* | | GGGG | Anno Domini , Before Christ | 2 |
* | | GGGGG | A , B | |
* | Calendar year | y | 44 , 1 , 1900 , 2017 | 5 |
* | | yo | 44 th , 1 st , 0 th , 17 th | 5 , 7 |
* | | yy | 44 , 01 , 00 , 17 | 5 |
* | | yyy | 044 , 001 , 1900 , 2017 | 5 |
* | | yyyy | 0044 , 0001 , 1900 , 2017 | 5 |
* | | yyyyy | ... | 3 , 5 |
* | Local week - numbering year | Y | 44 , 1 , 1900 , 2017 | 5 |
* | | Yo | 44 th , 1 st , 1900 th , 2017 th | 5 , 7 |
* | | YY | 44 , 01 , 00 , 17 | 5 , 8 |
* | | YYY | 044 , 001 , 1900 , 2017 | 5 |
* | | YYYY | 0044 , 0001 , 1900 , 2017 | 5 , 8 |
* | | YYYYY | ... | 3 , 5 |
* | ISO week - numbering year | R | - 43 , 0 , 1 , 1900 , 2017 | 5 , 7 |
* | | RR | - 43 , 00 , 01 , 1900 , 2017 | 5 , 7 |
* | | RRR | - 043 , 000 , 001 , 1900 , 2017 | 5 , 7 |
* | | RRRR | - 0043 , 0000 , 0001 , 1900 , 2017 | 5 , 7 |
* | | RRRRR | ... | 3 , 5 , 7 |
* | Extended year | u | - 43 , 0 , 1 , 1900 , 2017 | 5 |
* | | uu | - 43 , 01 , 1900 , 2017 | 5 |
* | | uuu | - 043 , 001 , 1900 , 2017 | 5 |
* | | uuuu | - 0043 , 0001 , 1900 , 2017 | 5 |
* | | uuuuu | ... | 3 , 5 |
* | Quarter ( formatting ) | Q | 1 , 2 , 3 , 4 | |
* | | Qo | 1 st , 2 nd , 3 rd , 4 th | 7 |
* | | QQ | 01 , 02 , 03 , 04 | |
* | | QQQ | Q1 , Q2 , Q3 , Q4 | |
* | | QQQQ | 1 st quarter , 2 nd quarter , ... | 2 |
* | | QQQQQ | 1 , 2 , 3 , 4 | 4 |
* | Quarter ( stand - alone ) | q | 1 , 2 , 3 , 4 | |
* | | qo | 1 st , 2 nd , 3 rd , 4 th | 7 |
* | | qq | 01 , 02 , 03 , 04 | |
* | | qqq | Q1 , Q2 , Q3 , Q4 | |
* | | qqqq | 1 st quarter , 2 nd quarter , ... | 2 |
* | | qqqqq | 1 , 2 , 3 , 4 | 4 |
* | Month ( formatting ) | M | 1 , 2 , ... , 12 | |
* | | Mo | 1 st , 2 nd , ... , 12 th | 7 |
* | | MM | 01 , 02 , ... , 12 | |
* | | MMM | Jan , Feb , ... , Dec | |
* | | MMMM | January , February , ... , December | 2 |
* | | MMMMM | J , F , ... , D | |
* | Month ( stand - alone ) | L | 1 , 2 , ... , 12 | |
* | | Lo | 1 st , 2 nd , ... , 12 th | 7 |
* | | LL | 01 , 02 , ... , 12 | |
* | | LLL | Jan , Feb , ... , Dec | |
* | | LLLL | January , February , ... , December | 2 |
* | | LLLLL | J , F , ... , D | |
* | Local week of year | w | 1 , 2 , ... , 53 | |
* | | wo | 1 st , 2 nd , ... , 53 th | 7 |
* | | ww | 01 , 02 , ... , 53 | |
* | ISO week of year | I | 1 , 2 , ... , 53 | 7 |
* | | Io | 1 st , 2 nd , ... , 53 th | 7 |
* | | II | 01 , 02 , ... , 53 | 7 |
* | Day of month | d | 1 , 2 , ... , 31 | |
* | | do | 1 st , 2 nd , ... , 31 st | 7 |
* | | dd | 01 , 02 , ... , 31 | |
* | Day of year | D | 1 , 2 , ... , 365 , 366 | 9 |
* | | Do | 1 st , 2 nd , ... , 365 th , 366 th | 7 |
* | | DD | 01 , 02 , ... , 365 , 366 | 9 |
* | | DDD | 001 , 002 , ... , 365 , 366 | |
* | | DDDD | ... | 3 |
* | Day of week ( formatting ) | E . . EEE | Mon , Tue , Wed , ... , Su | |
* | | EEEE | Monday , Tuesday , ... , Sunday | 2 |
* | | EEEEE | M , T , W , T , F , S , S | |
* | | EEEEEE | Mo , Tu , We , Th , Fr , Su , Sa | |
* | ISO day of week ( formatting ) | i | 1 , 2 , 3 , ... , 7 | 7 |
* | | io | 1 st , 2 nd , ... , 7 th | 7 |
* | | ii | 01 , 02 , ... , 07 | 7 |
* | | iii | Mon , Tue , Wed , ... , Su | 7 |
* | | iiii | Monday , Tuesday , ... , Sunday | 2 , 7 |
* | | iiiii | M , T , W , T , F , S , S | 7 |
* | | iiiiii | Mo , Tu , We , Th , Fr , Su , Sa | 7 |
* | Local day of week ( formatting ) | e | 2 , 3 , 4 , ... , 1 | |
* | | eo | 2 nd , 3 rd , ... , 1 st | 7 |
* | | ee | 02 , 03 , ... , 01 | |
* | | eee | Mon , Tue , Wed , ... , Su | |
* | | eeee | Monday , Tuesday , ... , Sunday | 2 |
* | | eeeee | M , T , W , T , F , S , S | |
* | | eeeeee | Mo , Tu , We , Th , Fr , Su , Sa | |
* | Local day of week ( stand - alone ) | c | 2 , 3 , 4 , ... , 1 | |
* | | co | 2 nd , 3 rd , ... , 1 st | 7 |
* | | cc | 02 , 03 , ... , 01 | |
* | | ccc | Mon , Tue , Wed , ... , Su | |
* | | cccc | Monday , Tuesday , ... , Sunday | 2 |
* | | ccccc | M , T , W , T , F , S , S | |
* | | cccccc | Mo , Tu , We , Th , Fr , Su , Sa | |
* | AM , PM | a . . aaa | AM , PM | |
* | | aaaa | a . m . , p . m . | 2 |
* | | aaaaa | a , p | |
* | AM , PM , noon , midnight | b . . bbb | AM , PM , noon , midnight | |
* | | bbbb | a . m . , p . m . , noon , midnight | 2 |
* | | bbbbb | a , p , n , mi | |
* | Flexible day period | B . . BBB | at night , in the morning , ... | |
* | | BBBB | at night , in the morning , ... | 2 |
* | | BBBBB | at night , in the morning , ... | |
* | Hour [ 1 - 12 ] | h | 1 , 2 , ... , 11 , 12 | |
* | | ho | 1 st , 2 nd , ... , 11 th , 12 th | 7 |
* | | hh | 01 , 02 , ... , 11 , 12 | |
* | Hour [ 0 - 23 ] | H | 0 , 1 , 2 , ... , 23 | |
* | | Ho | 0 th , 1 st , 2 nd , ... , 23 rd | 7 |
* | | HH | 00 , 01 , 02 , ... , 23 | |
* | Hour [ 0 - 11 ] | K | 1 , 2 , ... , 11 , 0 | |
* | | Ko | 1 st , 2 nd , ... , 11 th , 0 th | 7 |
* | | KK | 1 , 2 , ... , 11 , 0 | |
* | Hour [ 1 - 24 ] | k | 24 , 1 , 2 , ... , 23 | |
* | | ko | 24 th , 1 st , 2 nd , ... , 23 rd | 7 |
* | | kk | 24 , 01 , 02 , ... , 23 | |
* | Minute | m | 0 , 1 , ... , 59 | |
* | | mo | 0 th , 1 st , ... , 59 th | 7 |
* | | mm | 00 , 01 , ... , 59 | |
* | Second | s | 0 , 1 , ... , 59 | |
* | | so | 0 th , 1 st , ... , 59 th | 7 |
* | | ss | 00 , 01 , ... , 59 | |
* | Fraction of second | S | 0 , 1 , ... , 9 | |
* | | SS | 00 , 01 , ... , 99 | |
* | | SSS | 000 , 0001 , ... , 999 | |
* | | SSSS | ... | 3 |
* | Timezone ( ISO - 8601 w / Z ) | X | - 08 , + 0530 , Z | |
* | | XX | - 0800 , + 0530 , Z | |
* | | XXX | - 08 : 00 , + 05 : 30 , Z | |
* | | XXXX | - 0800 , + 0530 , Z , + 123456 | 2 |
* | | XXXXX | - 08 : 00 , + 05 : 30 , Z , + 12 : 34 : 56 | |
* | Timezone ( ISO - 8601 w / o Z ) | x | - 08 , + 0530 , + 00 | |
* | | xx | - 0800 , + 0530 , + 0000 | |
* | | xxx | - 08 : 00 , + 05 : 30 , + 00 : 00 | 2 |
* | | xxxx | - 0800 , + 0530 , + 0000 , + 123456 | |
* | | xxxxx | - 08 : 00 , + 05 : 30 , + 00 : 00 , + 12 : 34 : 56 | |
* | Timezone ( GMT ) | O ... OOO | GMT - 8 , GMT + 5 : 30 , GMT + 0 | |
* | | OOOO | GMT - 08 : 00 , GMT + 05 : 30 , GMT + 00 : 00 | 2 |
* | Timezone ( specific non - locat . ) | z ... zzz | GMT - 8 , GMT + 5 : 30 , GMT + 0 | 6 |
* | | zzzz | GMT - 08 : 00 , GMT + 05 : 30 , GMT + 00 : 00 | 2 , 6 |
* | Seconds timestamp | t | 512969520 | 7 |
* | | tt | ... | 3 , 7 |
* | Milliseconds timestamp | T | 512969520900 | 7 |
* | | TT | ... | 3 , 7 |
* | Long localized date | P | 05 / 29 / 1453 | 7 |
* | | PP | May 29 , 1453 | 7 |
* | | PPP | May 29 th , 1453 | 7 |
* | | PPPP | Sunday , May 29 th , 1453 | 2 , 7 |
* | Long localized time | p | 12 : 00 AM | 7 |
* | | pp | 12 : 00 : 00 AM | 7 |
* | | ppp | 12 : 00 : 00 AM GMT + 2 | 7 |
* | | pppp | 12 : 00 : 00 AM GMT + 02 : 00 | 2 , 7 |
* | Combination of date and time | Pp | 05 / 29 / 1453 , 12 : 00 AM | 7 |
* | | PPpp | May 29 , 1453 , 12 : 00 : 00 AM | 7 |
* | | PPPppp | May 29 th , 1453 at ... | 7 |
* | | PPPPpppp | Sunday , May 29 th , 1453 at ... | 2 , 7 |
* Notes :
* 1. "Formatting" units ( e . g . formatting quarter ) in the default en - US locale
* are the same as "stand-alone" units , but are different in some languages .
* "Formatting" units are declined according to the rules of the language
* in the context of a date . "Stand-alone" units are always nominative singular :
*
* ` format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad' `
*
* ` format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu' `
*
* 2. Any sequence of the identical letters is a pattern , unless it is escaped by
* the single quote characters ( see below ) .
* If the sequence is longer than listed in table ( e . g . ` EEEEEEEEEEE ` )
* the output will be the same as default pattern for this unit , usually
* the longest one ( in case of ISO weekdays , ` EEEE ` ) . Default patterns for units
* are marked with "2" in the last column of the table .
*
* ` format(new Date(2017, 10, 6), 'MMM') //=> 'Nov' `
*
* ` format(new Date(2017, 10, 6), 'MMMM') //=> 'November' `
*
* ` format(new Date(2017, 10, 6), 'MMMMM') //=> 'N' `
*
* ` format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November' `
*
* ` format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November' `
*
* 3. Some patterns could be unlimited length ( such as ` yyyyyyyy ` ) .
* The output will be padded with zeros to match the length of the pattern .
*
* ` format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017' `
*
* 4. ` QQQQQ ` and ` qqqqq ` could be not strictly numerical in some locales .
* These tokens represent the shortest form of the quarter .
*
* 5. The main difference between ` y ` and ` u ` patterns are B . C . years :
*
* | Year | ` y ` | ` u ` |
* | -- -- -- | -- -- - | -- -- - |
* | AC 1 | 1 | 1 |
* | BC 1 | 1 | 0 |
* | BC 2 | 2 | - 1 |
*
* Also ` yy ` always returns the last two digits of a year ,
* while ` uu ` pads single digit years to 2 characters and returns other years unchanged :
*
* | Year | ` yy ` | ` uu ` |
* | -- -- -- | -- -- -- | -- -- -- |
* | 1 | 01 | 01 |
* | 14 | 14 | 14 |
* | 376 | 76 | 376 |
* | 1453 | 53 | 1453 |
*
* The same difference is true for local and ISO week - numbering years ( ` Y ` and ` R ` ) ,
* except local week - numbering years are dependent on ` options.weekStartsOn `
* and ` options.firstWeekContainsDate ` ( compare [ getISOWeekYear ] { @ link https : //date-fns.org/docs/getISOWeekYear}
* and [ getWeekYear ] { @ link https : //date-fns.org/docs/getWeekYear}).
*
* 6. Specific non - location timezones are currently unavailable in ` date-fns ` ,
* so right now these tokens fall back to GMT timezones .
*
* 7. These patterns are not in the Unicode Technical Standard # 35 :
* - ` i ` : ISO day of week
* - ` I ` : ISO week of year
* - ` R ` : ISO week - numbering year
* - ` t ` : seconds timestamp
* - ` T ` : milliseconds timestamp
* - ` o ` : ordinal number modifier
* - ` P ` : long localized date
* - ` p ` : long localized time
*
* 8. ` YY ` and ` YYYY ` tokens represent week - numbering years but they are often confused with years .
* You should enable ` options.useAdditionalWeekYearTokens ` to use them . See : https : //git.io/fxCyr
*
* 9. ` D ` and ` DD ` tokens represent days of the year but they are ofthen confused with days of the month .
* You should enable ` options.useAdditionalDayOfYearTokens ` to use them . See : https : //git.io/fxCyr
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* - The second argument is now required for the sake of explicitness .
*
* ` ` ` javascript
* // Before v2.0.0
* format ( new Date ( 2016 , 0 , 1 ) )
*
* // v2.0.0 onward
* format ( new Date ( 2016 , 0 , 1 ) , "yyyy-MM-dd'T'HH:mm:ss.SSSxxx" )
* ` ` `
*
* - New format string API for ` format ` function
* which is based on [ Unicode Technical Standard # 35 ] ( https : //www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table).
* See [ this post ] ( https : //blog.date-fns.org/post/unicode-tokens-in-date-fns-v2-sreatyki91jg) for more details.
*
* - Characters are now escaped using single quote symbols ( ` ' ` ) instead of square brackets .
*
* @ param { Date | Number } date - the original date
* @ param { String } format - the string of tokens
* @ param { Object } [ options ] - an object with options .
* @ param { Locale } [ options . locale = defaultLocale ] - the locale object . See [ Locale ] { @ link https : //date-fns.org/docs/Locale}
* @ param { 0 | 1 | 2 | 3 | 4 | 5 | 6 } [ options . weekStartsOn = 0 ] - the index of the first day of the week ( 0 - Sunday )
* @ param { Number } [ options . firstWeekContainsDate = 1 ] - the day of January , which is
* @ param { Boolean } [ options . useAdditionalWeekYearTokens = false ] - if true , allows usage of the week - numbering year tokens ` YY ` and ` YYYY ` ;
* see : https : //git.io/fxCyr
* @ param { Boolean } [ options . useAdditionalDayOfYearTokens = false ] - if true , allows usage of the day of year tokens ` D ` and ` DD ` ;
* see : https : //git.io/fxCyr
* @ returns { String } the formatted date string
* @ throws { TypeError } 2 arguments required
* @ throws { RangeError } ` date ` must not be Invalid Date
* @ throws { RangeError } ` options.locale ` must contain ` localize ` property
* @ throws { RangeError } ` options.locale ` must contain ` formatLong ` property
* @ throws { RangeError } ` options.weekStartsOn ` must be between 0 and 6
* @ throws { RangeError } ` options.firstWeekContainsDate ` must be between 1 and 7
* @ throws { RangeError } use ` yyyy ` instead of ` YYYY ` for formatting years ; see : https : //git.io/fxCyr
* @ throws { RangeError } use ` yy ` instead of ` YY ` for formatting years ; see : https : //git.io/fxCyr
* @ throws { RangeError } use ` d ` instead of ` D ` for formatting days of the month ; see : https : //git.io/fxCyr
* @ throws { RangeError } use ` dd ` instead of ` DD ` for formatting days of the month ; see : https : //git.io/fxCyr
* @ throws { RangeError } format string contains an unescaped latin alphabet character
*
* @ example
* // Represent 11 February 2014 in middle-endian format:
* var result = format ( new Date ( 2014 , 1 , 11 ) , 'MM/dd/yyyy' )
* //=> '02/11/2014'
*
* @ example
* // Represent 2 July 2014 in Esperanto:
* import { eoLocale } from 'date-fns/locale/eo'
* var result = format ( new Date ( 2014 , 6 , 2 ) , "do 'de' MMMM yyyy" , {
* locale : eoLocale
* } )
* //=> '2-a de julio 2014'
*
* @ example
* // Escape string by single quote characters:
* var result = format ( new Date ( 2014 , 6 , 2 , 15 ) , "h 'o''clock'" )
* //=> "3 o'clock"
* /
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
function format ( dirtyDate , dirtyFormatStr , dirtyOptions ) {
requiredArgs ( 2 , arguments ) ;
var formatStr = String ( dirtyFormatStr ) ;
var options = dirtyOptions || { } ;
var locale = options . locale || locale$1 ;
var localeFirstWeekContainsDate = locale . options && locale . options . firstWeekContainsDate ;
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger ( localeFirstWeekContainsDate ) ;
var firstWeekContainsDate = options . firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger ( options . firstWeekContainsDate ) ; // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! ( firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7 ) ) {
throw new RangeError ( 'firstWeekContainsDate must be between 1 and 7 inclusively' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var localeWeekStartsOn = locale . options && locale . options . weekStartsOn ;
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger ( localeWeekStartsOn ) ;
var weekStartsOn = options . weekStartsOn == null ? defaultWeekStartsOn : toInteger ( options . weekStartsOn ) ; // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! ( weekStartsOn >= 0 && weekStartsOn <= 6 ) ) {
throw new RangeError ( 'weekStartsOn must be between 0 and 6 inclusively' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! locale . localize ) {
throw new RangeError ( 'locale must contain localize property' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! locale . formatLong ) {
throw new RangeError ( 'locale must contain formatLong property' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var originalDate = toDate ( dirtyDate ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! isValid ( originalDate ) ) {
throw new RangeError ( 'Invalid time value' ) ;
} // Convert the date in system timezone to the same date in UTC+00:00 timezone.
// This ensures that when UTC functions will be implemented, locales will be compatible with them.
// See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var timezoneOffset = getTimezoneOffsetInMilliseconds ( originalDate ) ;
var utcDate = subMilliseconds ( originalDate , timezoneOffset ) ;
var formatterOptions = {
firstWeekContainsDate : firstWeekContainsDate ,
weekStartsOn : weekStartsOn ,
locale : locale ,
_originalDate : originalDate
} ;
var result = formatStr . match ( longFormattingTokensRegExp ) . map ( function ( substring ) {
var firstCharacter = substring [ 0 ] ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( firstCharacter === 'p' || firstCharacter === 'P' ) {
var longFormatter = longFormatters [ firstCharacter ] ;
return longFormatter ( substring , locale . formatLong , formatterOptions ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return substring ;
} ) . join ( '' ) . match ( formattingTokensRegExp ) . map ( function ( substring ) {
// Replace two single quote characters with one single quote character
if ( substring === "''" ) {
return "'" ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var firstCharacter = substring [ 0 ] ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( firstCharacter === "'" ) {
return cleanEscapedString ( substring ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var formatter = formatters$1 [ firstCharacter ] ;
2019-08-02 20:18:05 +02:00
if ( formatter ) {
2020-01-16 19:29:13 +01:00
if ( ! options . useAdditionalWeekYearTokens && isProtectedWeekYearToken ( substring ) ) {
throwProtectedError ( substring ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( ! options . useAdditionalDayOfYearTokens && isProtectedDayOfYearToken ( substring ) ) {
throwProtectedError ( substring ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
return formatter ( utcDate , substring , locale . localize , formatterOptions ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( firstCharacter . match ( unescapedLatinCharacterRegExp ) ) {
throw new RangeError ( 'Format string contains an unescaped latin alphabet character `' + firstCharacter + '`' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return substring ;
} ) . join ( '' ) ;
return result ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
function cleanEscapedString ( input ) {
return input . match ( escapedStringRegExp ) [ 1 ] . replace ( doubleQuoteRegExp , "'" ) ;
} / * *
* @ name compareAsc
2019-08-02 20:18:05 +02:00
* @ category Common Helpers
2020-01-16 19:29:13 +01:00
* @ summary Compare the two dates and return - 1 , 0 or 1.
2019-08-02 20:18:05 +02:00
*
* @ description
2020-01-16 19:29:13 +01:00
* Compare the two dates and return 1 if the first date is after the second ,
* - 1 if the first date is before the second or 0 if dates are equal .
2019-08-02 20:18:05 +02:00
*
2020-01-16 19:29:13 +01:00
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } dateLeft - the first date to compare
* @ param { Date | Number } dateRight - the second date to compare
2019-08-02 20:18:05 +02:00
* @ returns { Number } the result of the comparison
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 2 arguments required
2019-08-02 20:18:05 +02:00
*
* @ example
2020-01-16 19:29:13 +01:00
* // Compare 11 February 1987 and 10 July 1989:
* var result = compareAsc ( new Date ( 1987 , 1 , 11 ) , new Date ( 1989 , 6 , 10 ) )
* //=> -1
2019-08-02 20:18:05 +02:00
*
* @ example
2020-01-16 19:29:13 +01:00
* // Sort the array of dates:
2019-08-02 20:18:05 +02:00
* var result = [
* new Date ( 1995 , 6 , 2 ) ,
* new Date ( 1987 , 1 , 11 ) ,
* new Date ( 1989 , 6 , 10 )
2020-01-16 19:29:13 +01:00
* ] . sort ( compareAsc )
2019-08-02 20:18:05 +02:00
* //=> [
2020-01-16 19:29:13 +01:00
* // Wed Feb 11 1987 00:00:00,
2019-08-02 20:18:05 +02:00
* // Mon Jul 10 1989 00:00:00,
2020-01-16 19:29:13 +01:00
* // Sun Jul 02 1995 00:00:00
2019-08-02 20:18:05 +02:00
* // ]
* /
2020-01-16 19:29:13 +01:00
function compareAsc ( dirtyDateLeft , dirtyDateRight ) {
requiredArgs ( 2 , arguments ) ;
var dateLeft = toDate ( dirtyDateLeft ) ;
var dateRight = toDate ( dirtyDateRight ) ;
var diff = dateLeft . getTime ( ) - dateRight . getTime ( ) ;
if ( diff < 0 ) {
return - 1 ;
} else if ( diff > 0 ) {
return 1 ; // Return 0 if diff is 0; return NaN if diff is NaN
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
return diff ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} / * *
* @ name differenceInCalendarMonths
* @ category Month Helpers
* @ summary Get the number of calendar months between the given dates .
*
* @ description
* Get the number of calendar months between the given dates .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
* @ returns { Number } the number of calendar months
* @ throws { TypeError } 2 arguments required
*
* @ example
* // How many calendar months are between 31 January 2014 and 1 September 2014?
* var result = differenceInCalendarMonths (
* new Date ( 2014 , 8 , 1 ) ,
* new Date ( 2014 , 0 , 31 )
* )
* //=> 8
* /
function differenceInCalendarMonths ( dirtyDateLeft , dirtyDateRight ) {
requiredArgs ( 2 , arguments ) ;
var dateLeft = toDate ( dirtyDateLeft ) ;
var dateRight = toDate ( dirtyDateRight ) ;
var yearDiff = dateLeft . getFullYear ( ) - dateRight . getFullYear ( ) ;
var monthDiff = dateLeft . getMonth ( ) - dateRight . getMonth ( ) ;
return yearDiff * 12 + monthDiff ;
} / * *
* @ name differenceInMonths
* @ category Month Helpers
* @ summary Get the number of full months between the given dates .
*
* @ description
* Get the number of full months between the given dates .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
* @ returns { Number } the number of full months
* @ throws { TypeError } 2 arguments required
*
* @ example
* // How many full months are between 31 January 2014 and 1 September 2014?
* var result = differenceInMonths ( new Date ( 2014 , 8 , 1 ) , new Date ( 2014 , 0 , 31 ) )
* //=> 7
* /
function differenceInMonths ( dirtyDateLeft , dirtyDateRight ) {
requiredArgs ( 2 , arguments ) ;
var dateLeft = toDate ( dirtyDateLeft ) ;
var dateRight = toDate ( dirtyDateRight ) ;
var sign = compareAsc ( dateLeft , dateRight ) ;
var difference = Math . abs ( differenceInCalendarMonths ( dateLeft , dateRight ) ) ;
dateLeft . setMonth ( dateLeft . getMonth ( ) - sign * difference ) ; // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full
// If so, result must be decreased by 1 in absolute value
var isLastMonthNotFull = compareAsc ( dateLeft , dateRight ) === - sign ;
var result = sign * ( difference - isLastMonthNotFull ) ; // Prevent negative zero
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return result === 0 ? 0 : result ;
} / * *
* @ name differenceInMilliseconds
2019-08-02 20:18:05 +02:00
* @ category Millisecond Helpers
* @ summary Get the number of milliseconds between the given dates .
*
* @ description
* Get the number of milliseconds between the given dates .
*
2020-01-16 19:29:13 +01:00
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
2019-08-02 20:18:05 +02:00
* @ returns { Number } the number of milliseconds
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 2 arguments required
2019-08-02 20:18:05 +02:00
*
* @ example
* // How many milliseconds are between
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
* var result = differenceInMilliseconds (
* new Date ( 2014 , 6 , 2 , 12 , 30 , 21 , 700 ) ,
* new Date ( 2014 , 6 , 2 , 12 , 30 , 20 , 600 )
* )
* //=> 1100
* /
2020-01-16 19:29:13 +01:00
function differenceInMilliseconds ( dirtyDateLeft , dirtyDateRight ) {
requiredArgs ( 2 , arguments ) ;
var dateLeft = toDate ( dirtyDateLeft ) ;
var dateRight = toDate ( dirtyDateRight ) ;
return dateLeft . getTime ( ) - dateRight . getTime ( ) ;
} / * *
* @ name differenceInSeconds
2019-08-02 20:18:05 +02:00
* @ category Second Helpers
* @ summary Get the number of seconds between the given dates .
*
* @ description
* Get the number of seconds between the given dates .
*
2020-01-16 19:29:13 +01:00
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
2019-08-02 20:18:05 +02:00
* @ returns { Number } the number of seconds
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 2 arguments required
2019-08-02 20:18:05 +02:00
*
* @ example
* // How many seconds are between
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
* var result = differenceInSeconds (
* new Date ( 2014 , 6 , 2 , 12 , 30 , 20 , 0 ) ,
* new Date ( 2014 , 6 , 2 , 12 , 30 , 7 , 999 )
* )
* //=> 12
* /
2020-01-16 19:29:13 +01:00
function differenceInSeconds ( dirtyDateLeft , dirtyDateRight ) {
requiredArgs ( 2 , arguments ) ;
var diff = differenceInMilliseconds ( dirtyDateLeft , dirtyDateRight ) / 1000 ;
return diff > 0 ? Math . floor ( diff ) : Math . ceil ( diff ) ;
} function assign ( target , dirtyObject ) {
if ( target == null ) {
throw new TypeError ( 'assign requires that input parameter not be null or undefined' ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
dirtyObject = dirtyObject || { } ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
for ( var property in dirtyObject ) {
if ( dirtyObject . hasOwnProperty ( property ) ) {
target [ property ] = dirtyObject [ property ] ;
}
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
return target ;
} function cloneObject ( dirtyObject ) {
return assign ( { } , dirtyObject ) ;
} var MINUTES _IN _DAY = 1440 ;
2019-08-02 20:18:05 +02:00
var MINUTES _IN _ALMOST _TWO _DAYS = 2520 ;
var MINUTES _IN _MONTH = 43200 ;
var MINUTES _IN _TWO _MONTHS = 86400 ;
/ * *
2020-01-16 19:29:13 +01:00
* @ name formatDistance
2019-08-02 20:18:05 +02:00
* @ category Common Helpers
* @ summary Return the distance between the given dates in words .
*
* @ description
* Return the distance between the given dates in words .
*
* | Distance between dates | Result |
* | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- - |
* | 0 ... 30 secs | less than a minute |
* | 30 secs ... 1 min 30 secs | 1 minute |
* | 1 min 30 secs ... 44 mins 30 secs | [ 2. . 44 ] minutes |
* | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |
* | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [ 2. . 24 ] hours |
* | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |
* | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [ 2. . 30 ] days |
* | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |
* | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |
* | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [ 2. . 12 ] months |
* | 1 yr ... 1 yr 3 months | about 1 year |
* | 1 yr 3 months ... 1 yr 9 month s | over 1 year |
* | 1 yr 9 months ... 2 yrs | almost 2 years |
* | N yrs ... N yrs 3 months | about N years |
* | N yrs 3 months ... N yrs 9 months | over N years |
* | N yrs 9 months ... N + 1 yrs | almost N + 1 years |
*
* With ` options.includeSeconds == true ` :
* | Distance between dates | Result |
* | -- -- -- -- -- -- -- -- -- -- -- -- | -- -- -- -- -- -- -- -- -- -- -- |
* | 0 secs ... 5 secs | less than 5 seconds |
* | 5 secs ... 10 secs | less than 10 seconds |
* | 10 secs ... 20 secs | less than 20 seconds |
* | 20 secs ... 40 secs | half a minute |
* | 40 secs ... 60 secs | less than a minute |
* | 60 secs ... 90 secs | 1 minute |
*
2020-01-16 19:29:13 +01:00
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* - The function was renamed from ` distanceInWords ` to ` formatDistance `
* to make its name consistent with ` format ` and ` formatRelative ` .
*
* - The order of arguments is swapped to make the function
* consistent with ` differenceIn... ` functions .
*
* ` ` ` javascript
* // Before v2.0.0
*
* distanceInWords (
* new Date ( 1986 , 3 , 4 , 10 , 32 , 0 ) ,
* new Date ( 1986 , 3 , 4 , 11 , 32 , 0 ) ,
* { addSuffix : true }
* ) //=> 'in about 1 hour'
*
* // v2.0.0 onward
*
* formatDistance (
* new Date ( 1986 , 3 , 4 , 11 , 32 , 0 ) ,
* new Date ( 1986 , 3 , 4 , 10 , 32 , 0 ) ,
* { addSuffix : true }
* ) //=> 'in about 1 hour'
* ` ` `
*
* @ param { Date | Number } date - the date
* @ param { Date | Number } baseDate - the date to compare with
* @ param { Object } [ options ] - an object with options .
2019-08-02 20:18:05 +02:00
* @ param { Boolean } [ options . includeSeconds = false ] - distances less than a minute are more detailed
* @ param { Boolean } [ options . addSuffix = false ] - result indicates if the second date is earlier or later than the first
2020-01-16 19:29:13 +01:00
* @ param { Locale } [ options . locale = defaultLocale ] - the locale object . See [ Locale ] { @ link https : //date-fns.org/docs/Locale}
2019-08-02 20:18:05 +02:00
* @ returns { String } the distance in words
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 2 arguments required
* @ throws { RangeError } ` date ` must not be Invalid Date
* @ throws { RangeError } ` baseDate ` must not be Invalid Date
* @ throws { RangeError } ` options.locale ` must contain ` formatDistance ` property
2019-08-02 20:18:05 +02:00
*
* @ example
* // What is the distance between 2 July 2014 and 1 January 2015?
2020-01-16 19:29:13 +01:00
* var result = formatDistance ( new Date ( 2014 , 6 , 2 ) , new Date ( 2015 , 0 , 1 ) )
2019-08-02 20:18:05 +02:00
* //=> '6 months'
*
* @ example
* // What is the distance between 1 January 2015 00:00:15
* // and 1 January 2015 00:00:00, including seconds?
2020-01-16 19:29:13 +01:00
* var result = formatDistance (
2019-08-02 20:18:05 +02:00
* new Date ( 2015 , 0 , 1 , 0 , 0 , 15 ) ,
* new Date ( 2015 , 0 , 1 , 0 , 0 , 0 ) ,
2020-01-16 19:29:13 +01:00
* { includeSeconds : true }
2019-08-02 20:18:05 +02:00
* )
* //=> 'less than 20 seconds'
*
* @ example
* // What is the distance from 1 January 2016
* // to 1 January 2015, with a suffix?
2020-01-16 19:29:13 +01:00
* var result = formatDistance ( new Date ( 2015 , 0 , 1 ) , new Date ( 2016 , 0 , 1 ) , {
* addSuffix : true
* } )
2019-08-02 20:18:05 +02:00
* //=> 'about 1 year ago'
*
* @ example
* // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?
2020-01-16 19:29:13 +01:00
* import { eoLocale } from 'date-fns/locale/eo'
* var result = formatDistance ( new Date ( 2016 , 7 , 1 ) , new Date ( 2015 , 0 , 1 ) , {
* locale : eoLocale
* } )
2019-08-02 20:18:05 +02:00
* //=> 'pli ol 1 jaro'
* /
2020-01-16 19:29:13 +01:00
function formatDistance$2 ( dirtyDate , dirtyBaseDate , dirtyOptions ) {
requiredArgs ( 2 , arguments ) ;
2019-08-02 20:18:05 +02:00
var options = dirtyOptions || { } ;
2020-01-16 19:29:13 +01:00
var locale = options . locale || locale$1 ;
if ( ! locale . formatDistance ) {
throw new RangeError ( 'locale must contain formatDistance property' ) ;
}
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
var comparison = compareAsc ( dirtyDate , dirtyBaseDate ) ;
2019-08-02 20:18:05 +02:00
2020-01-16 19:29:13 +01:00
if ( isNaN ( comparison ) ) {
throw new RangeError ( 'Invalid time value' ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var localizeOptions = cloneObject ( options ) ;
localizeOptions . addSuffix = Boolean ( options . addSuffix ) ;
localizeOptions . comparison = comparison ;
var dateLeft ;
var dateRight ;
2019-08-02 20:18:05 +02:00
if ( comparison > 0 ) {
2020-01-16 19:29:13 +01:00
dateLeft = toDate ( dirtyBaseDate ) ;
dateRight = toDate ( dirtyDate ) ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
dateLeft = toDate ( dirtyDate ) ;
dateRight = toDate ( dirtyBaseDate ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
var seconds = differenceInSeconds ( dateRight , dateLeft ) ;
var offsetInSeconds = ( getTimezoneOffsetInMilliseconds ( dateRight ) - getTimezoneOffsetInMilliseconds ( dateLeft ) ) / 1000 ;
var minutes = Math . round ( ( seconds - offsetInSeconds ) / 60 ) ;
var months ; // 0 up to 2 mins
2019-08-02 20:18:05 +02:00
if ( minutes < 2 ) {
if ( options . includeSeconds ) {
if ( seconds < 5 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'lessThanXSeconds' , 5 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else if ( seconds < 10 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'lessThanXSeconds' , 10 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else if ( seconds < 20 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'lessThanXSeconds' , 20 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else if ( seconds < 40 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'halfAMinute' , null , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else if ( seconds < 60 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'lessThanXMinutes' , 1 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xMinutes' , 1 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
}
} else {
if ( minutes === 0 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'lessThanXMinutes' , 1 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xMinutes' , minutes , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
} // 2 mins up to 0.75 hrs
2019-08-02 20:18:05 +02:00
} else if ( minutes < 45 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xMinutes' , minutes , localizeOptions ) ; // 0.75 hrs up to 1.5 hrs
2019-08-02 20:18:05 +02:00
} else if ( minutes < 90 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'aboutXHours' , 1 , localizeOptions ) ; // 1.5 hrs up to 24 hrs
2019-08-02 20:18:05 +02:00
} else if ( minutes < MINUTES _IN _DAY ) {
var hours = Math . round ( minutes / 60 ) ;
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'aboutXHours' , hours , localizeOptions ) ; // 1 day up to 1.75 days
2019-08-02 20:18:05 +02:00
} else if ( minutes < MINUTES _IN _ALMOST _TWO _DAYS ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xDays' , 1 , localizeOptions ) ; // 1.75 days up to 30 days
2019-08-02 20:18:05 +02:00
} else if ( minutes < MINUTES _IN _MONTH ) {
var days = Math . round ( minutes / MINUTES _IN _DAY ) ;
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xDays' , days , localizeOptions ) ; // 1 month up to 2 months
2019-08-02 20:18:05 +02:00
} else if ( minutes < MINUTES _IN _TWO _MONTHS ) {
months = Math . round ( minutes / MINUTES _IN _MONTH ) ;
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'aboutXMonths' , months , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
}
2020-01-16 19:29:13 +01:00
months = differenceInMonths ( dateRight , dateLeft ) ; // 2 months up to 12 months
2019-08-02 20:18:05 +02:00
if ( months < 12 ) {
var nearestMonth = Math . round ( minutes / MINUTES _IN _MONTH ) ;
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'xMonths' , nearestMonth , localizeOptions ) ; // 1 year up to max Date
2019-08-02 20:18:05 +02:00
} else {
var monthsSinceStartOfYear = months % 12 ;
2020-01-16 19:29:13 +01:00
var years = Math . floor ( months / 12 ) ; // N years up to 1 years 3 months
2019-08-02 20:18:05 +02:00
if ( monthsSinceStartOfYear < 3 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'aboutXYears' , years , localizeOptions ) ; // N years 3 months up to N years 9 months
2019-08-02 20:18:05 +02:00
} else if ( monthsSinceStartOfYear < 9 ) {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'overXYears' , years , localizeOptions ) ; // N years 9 months up to N year 12 months
2019-08-02 20:18:05 +02:00
} else {
2020-01-16 19:29:13 +01:00
return locale . formatDistance ( 'almostXYears' , years + 1 , localizeOptions ) ;
2019-08-02 20:18:05 +02:00
}
}
2020-01-16 19:29:13 +01:00
} / * *
* @ name formatDistanceToNow
2019-08-02 20:18:05 +02:00
* @ category Common Helpers
* @ summary Return the distance between the given date and now in words .
2020-01-16 19:29:13 +01:00
* @ pure false
2019-08-02 20:18:05 +02:00
*
* @ description
* Return the distance between the given date and now in words .
*
* | Distance to now | Result |
* | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- - |
* | 0 ... 30 secs | less than a minute |
* | 30 secs ... 1 min 30 secs | 1 minute |
* | 1 min 30 secs ... 44 mins 30 secs | [ 2. . 44 ] minutes |
* | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |
* | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [ 2. . 24 ] hours |
* | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |
* | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [ 2. . 30 ] days |
* | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |
* | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |
* | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [ 2. . 12 ] months |
* | 1 yr ... 1 yr 3 months | about 1 year |
* | 1 yr 3 months ... 1 yr 9 month s | over 1 year |
* | 1 yr 9 months ... 2 yrs | almost 2 years |
* | N yrs ... N yrs 3 months | about N years |
* | N yrs 3 months ... N yrs 9 months | over N years |
* | N yrs 9 months ... N + 1 yrs | almost N + 1 years |
*
* With ` options.includeSeconds == true ` :
* | Distance to now | Result |
* | -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- -- |
* | 0 secs ... 5 secs | less than 5 seconds |
* | 5 secs ... 10 secs | less than 10 seconds |
* | 10 secs ... 20 secs | less than 20 seconds |
* | 20 secs ... 40 secs | half a minute |
* | 40 secs ... 60 secs | less than a minute |
* | 60 secs ... 90 secs | 1 minute |
*
2020-01-16 19:29:13 +01:00
* > ⚠ ️ Please note that this function is not present in the FP submodule as
* > it uses ` Date.now() ` internally hence impure and can ' t be safely curried .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* - The function was renamed from ` distanceInWordsToNow ` to ` formatDistanceToNow `
* to make its name consistent with ` format ` and ` formatRelative ` .
*
* ` ` ` javascript
* // Before v2.0.0
*
* distanceInWordsToNow ( new Date ( 2014 , 6 , 2 ) , { addSuffix : true } )
* //=> 'in 6 months'
*
* // v2.0.0 onward
*
* formatDistanceToNow ( new Date ( 2014 , 6 , 2 ) , { addSuffix : true } )
* //=> 'in 6 months'
* ` ` `
*
* @ param { Date | Number } date - the given date
2019-08-02 20:18:05 +02:00
* @ param { Object } [ options ] - the object with options
* @ param { Boolean } [ options . includeSeconds = false ] - distances less than a minute are more detailed
2020-01-16 19:29:13 +01:00
* @ param { Boolean } [ options . addSuffix = false ] - result specifies if now is earlier or later than the passed date
* @ param { Locale } [ options . locale = defaultLocale ] - the locale object . See [ Locale ] { @ link https : //date-fns.org/docs/Locale}
2019-08-02 20:18:05 +02:00
* @ returns { String } the distance in words
2020-01-16 19:29:13 +01:00
* @ throws { TypeError } 1 argument required
* @ throws { RangeError } ` date ` must not be Invalid Date
* @ throws { RangeError } ` options.locale ` must contain ` formatDistance ` property
2019-08-02 20:18:05 +02:00
*
* @ example
* // If today is 1 January 2015, what is the distance to 2 July 2014?
2020-01-16 19:29:13 +01:00
* var result = formatDistanceToNow (
2019-08-02 20:18:05 +02:00
* new Date ( 2014 , 6 , 2 )
* )
* //=> '6 months'
*
* @ example
* // If now is 1 January 2015 00:00:00,
* // what is the distance to 1 January 2015 00:00:15, including seconds?
2020-01-16 19:29:13 +01:00
* var result = formatDistanceToNow (
2019-08-02 20:18:05 +02:00
* new Date ( 2015 , 0 , 1 , 0 , 0 , 15 ) ,
* { includeSeconds : true }
* )
* //=> 'less than 20 seconds'
*
* @ example
* // If today is 1 January 2015,
* // what is the distance to 1 January 2016, with a suffix?
2020-01-16 19:29:13 +01:00
* var result = formatDistanceToNow (
2019-08-02 20:18:05 +02:00
* new Date ( 2016 , 0 , 1 ) ,
* { addSuffix : true }
* )
* //=> 'in about 1 year'
*
* @ example
* // If today is 1 January 2015,
* // what is the distance to 1 August 2016 in Esperanto?
* var eoLocale = require ( 'date-fns/locale/eo' )
2020-01-16 19:29:13 +01:00
* var result = formatDistanceToNow (
2019-08-02 20:18:05 +02:00
* new Date ( 2016 , 7 , 1 ) ,
* { locale : eoLocale }
* )
* //=> 'pli ol 1 jaro'
* /
2020-01-16 19:29:13 +01:00
function formatDistanceToNow ( dirtyDate , dirtyOptions ) {
requiredArgs ( 1 , arguments ) ;
return formatDistance$2 ( dirtyDate , Date . now ( ) , dirtyOptions ) ;
} if ( typeof self !== "undefined" ) {
2019-08-02 20:18:05 +02:00
init ( self ) ;
} else if ( typeof global$1 !== "undefined" ) {
init ( global$1 ) ;
} else if ( typeof window !== "undefined" ) {
init ( window ) ;
} else {
throw new Error ( "unsupported execution environment" ) ;
}
function init ( g ) {
g . dateFns = {
2020-01-16 19:29:13 +01:00
locales : {
"default" : locale$1 ,
"en" : locale$1 ,
"en_US" : locale$1 ,
"fr" : locale ,
"fr_FR" : locale
} ,
format ,
formatDistanceToNow
2019-08-02 20:18:05 +02:00
} ;
} } ( ) ) ;