date-fns
Advanced tools
Comparing version 2.21.1 to 2.21.2
@@ -26,3 +26,3 @@ "use strict"; | ||
// Year | ||
y: function (date, token) { | ||
y(date, token) { | ||
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens | ||
@@ -41,13 +41,16 @@ // | Year | y | yy | yyy | yyyy | yyyyy | | ||
}, | ||
// Month | ||
M: function (date, token) { | ||
M(date, token) { | ||
var month = date.getUTCMonth(); | ||
return token === 'M' ? String(month + 1) : (0, _index.default)(month + 1, 2); | ||
}, | ||
// Day of the month | ||
d: function (date, token) { | ||
d(date, token) { | ||
return (0, _index.default)(date.getUTCDate(), token.length); | ||
}, | ||
// AM or PM | ||
a: function (date, token) { | ||
a(date, token) { | ||
var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am'; | ||
@@ -71,20 +74,25 @@ | ||
}, | ||
// Hour [1-12] | ||
h: function (date, token) { | ||
h(date, token) { | ||
return (0, _index.default)(date.getUTCHours() % 12 || 12, token.length); | ||
}, | ||
// Hour [0-23] | ||
H: function (date, token) { | ||
H(date, token) { | ||
return (0, _index.default)(date.getUTCHours(), token.length); | ||
}, | ||
// Minute | ||
m: function (date, token) { | ||
m(date, token) { | ||
return (0, _index.default)(date.getUTCMinutes(), token.length); | ||
}, | ||
// Second | ||
s: function (date, token) { | ||
s(date, token) { | ||
return (0, _index.default)(date.getUTCSeconds(), token.length); | ||
}, | ||
// Fraction of second | ||
S: function (date, token) { | ||
S(date, token) { | ||
var numberOfDigits = token.length; | ||
@@ -95,2 +103,3 @@ var milliseconds = date.getUTCMilliseconds(); | ||
} | ||
}; | ||
@@ -97,0 +106,0 @@ var _default = formatters; |
@@ -55,3 +55,3 @@ "use strict"; | ||
var dateRight = (0, _index3.default)(dirtyDateRight); | ||
if (!(0, _index.default)(dateLeft) || !(0, _index.default)(dateRight)) return new Date(NaN); | ||
if (!(0, _index.default)(dateLeft) || !(0, _index.default)(dateRight)) return NaN; | ||
var calendarDifference = (0, _index4.default)(dateLeft, dateRight); | ||
@@ -58,0 +58,0 @@ var sign = calendarDifference < 0 ? -1 : 1; |
@@ -38,3 +38,3 @@ "use strict"; | ||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? | ||
* var result = differenceInCalendarDays( | ||
* const result = differenceInCalendarDays( | ||
* new Date(2012, 6, 2, 0, 0), | ||
@@ -46,3 +46,3 @@ * new Date(2011, 6, 2, 23, 0) | ||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? | ||
* var result = differenceInCalendarDays( | ||
* const result = differenceInCalendarDays( | ||
* new Date(2011, 6, 3, 0, 1), | ||
@@ -49,0 +49,0 @@ * new Date(2011, 6, 2, 23, 59) |
@@ -38,3 +38,3 @@ "use strict"; | ||
* // How many calendar ISO weeks are between 6 July 2014 and 21 July 2014? | ||
* var result = differenceInCalendarISOWeeks( | ||
* const result = differenceInCalendarISOWeeks( | ||
* new Date(2014, 6, 21), | ||
@@ -41,0 +41,0 @@ * new Date(2014, 6, 6) |
@@ -40,3 +40,3 @@ "use strict"; | ||
* // How many calendar ISO week-numbering years are 1 January 2010 and 1 January 2012? | ||
* var result = differenceInCalendarISOWeekYears( | ||
* const result = differenceInCalendarISOWeekYears( | ||
* new Date(2012, 0, 1), | ||
@@ -43,0 +43,0 @@ * new Date(2010, 0, 1) |
@@ -40,3 +40,3 @@ "use strict"; | ||
* // How many calendar weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInCalendarWeeks( | ||
* const result = differenceInCalendarWeeks( | ||
* new Date(2014, 6, 20), | ||
@@ -50,3 +50,3 @@ * new Date(2014, 6, 5) | ||
* // how many calendar weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInCalendarWeeks( | ||
* const result = differenceInCalendarWeeks( | ||
* new Date(2014, 6, 20), | ||
@@ -53,0 +53,0 @@ * new Date(2014, 6, 5), |
@@ -33,3 +33,3 @@ "use strict"; | ||
* // How many calendar years are between 31 December 2013 and 11 February 2015? | ||
* var result = differenceInCalendarYears( | ||
* const result = differenceInCalendarYears( | ||
* new Date(2015, 1, 11), | ||
@@ -36,0 +36,0 @@ * new Date(2013, 11, 31) |
@@ -60,3 +60,3 @@ "use strict"; | ||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2012, 6, 2, 0, 0), | ||
@@ -68,3 +68,3 @@ * new Date(2011, 6, 2, 23, 0) | ||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2011, 6, 3, 0, 1), | ||
@@ -80,3 +80,3 @@ * new Date(2011, 6, 2, 23, 59) | ||
* // period has only 92*24-1 hours. | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2020, 5, 1), | ||
@@ -98,3 +98,3 @@ * new Date(2020, 2, 1) | ||
var isLastDayNotFull = compareLocalAsc(dateLeft, dateRight) === -sign; | ||
var isLastDayNotFull = Number(compareLocalAsc(dateLeft, dateRight) === -sign); | ||
var result = sign * (difference - isLastDayNotFull); // Prevent negative zero | ||
@@ -101,0 +101,0 @@ |
@@ -62,3 +62,3 @@ "use strict"; | ||
var isLastISOWeekYearNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign; | ||
var isLastISOWeekYearNotFull = Number((0, _index3.default)(dateLeft, dateRight) === -sign); | ||
var result = sign * (difference - isLastISOWeekYearNotFull); // Prevent negative zero | ||
@@ -65,0 +65,0 @@ |
@@ -34,3 +34,3 @@ "use strict"; | ||
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? | ||
* var result = differenceInMilliseconds( | ||
* const result = differenceInMilliseconds( | ||
* new Date(2014, 6, 2, 12, 30, 21, 700), | ||
@@ -37,0 +37,0 @@ * new Date(2014, 6, 2, 12, 30, 20, 600) |
@@ -68,3 +68,3 @@ "use strict"; | ||
result = sign * (difference - isLastMonthNotFull); | ||
result = sign * (difference - Number(isLastMonthNotFull)); | ||
} // Prevent negative zero | ||
@@ -71,0 +71,0 @@ |
@@ -34,3 +34,3 @@ "use strict"; | ||
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? | ||
* var result = differenceInSeconds( | ||
* const result = differenceInSeconds( | ||
* new Date(2014, 6, 2, 12, 30, 20, 0), | ||
@@ -37,0 +37,0 @@ * new Date(2014, 6, 2, 12, 30, 7, 999) |
@@ -42,3 +42,3 @@ "use strict"; | ||
* // How many full weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) | ||
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) | ||
* //=> 2 | ||
@@ -52,3 +52,3 @@ * | ||
* // only 54*24-1 hours. | ||
* var result = differenceInWeeks( | ||
* const result = differenceInWeeks( | ||
* new Date(2020, 5, 1), | ||
@@ -55,0 +55,0 @@ * new Date(2020, 2, 6) |
@@ -37,3 +37,3 @@ "use strict"; | ||
* // How many full years are between 31 December 2013 and 11 February 2015? | ||
* var result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) | ||
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) | ||
* //=> 1 | ||
@@ -49,8 +49,8 @@ */ | ||
dateLeft.setFullYear('1584'); | ||
dateRight.setFullYear('1584'); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full | ||
dateLeft.setFullYear(1584); | ||
dateRight.setFullYear(1584); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full | ||
// If so, result must be decreased by 1 in absolute value | ||
var isLastYearNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign; | ||
var result = sign * (difference - isLastYearNotFull); // Prevent negative zero | ||
var result = sign * (difference - Number(isLastYearNotFull)); // Prevent negative zero | ||
@@ -57,0 +57,0 @@ return result === 0 ? 0 : result; |
@@ -17,3 +17,3 @@ import addLeadingZeros from "../../addLeadingZeros/index.js"; | ||
// Year | ||
y: function (date, token) { | ||
y(date, token) { | ||
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens | ||
@@ -32,13 +32,16 @@ // | Year | y | yy | yyy | yyyy | yyyyy | | ||
}, | ||
// Month | ||
M: function (date, token) { | ||
M(date, token) { | ||
var month = date.getUTCMonth(); | ||
return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2); | ||
}, | ||
// Day of the month | ||
d: function (date, token) { | ||
d(date, token) { | ||
return addLeadingZeros(date.getUTCDate(), token.length); | ||
}, | ||
// AM or PM | ||
a: function (date, token) { | ||
a(date, token) { | ||
var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am'; | ||
@@ -62,20 +65,25 @@ | ||
}, | ||
// Hour [1-12] | ||
h: function (date, token) { | ||
h(date, token) { | ||
return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length); | ||
}, | ||
// Hour [0-23] | ||
H: function (date, token) { | ||
H(date, token) { | ||
return addLeadingZeros(date.getUTCHours(), token.length); | ||
}, | ||
// Minute | ||
m: function (date, token) { | ||
m(date, token) { | ||
return addLeadingZeros(date.getUTCMinutes(), token.length); | ||
}, | ||
// Second | ||
s: function (date, token) { | ||
s(date, token) { | ||
return addLeadingZeros(date.getUTCSeconds(), token.length); | ||
}, | ||
// Fraction of second | ||
S: function (date, token) { | ||
S(date, token) { | ||
var numberOfDigits = token.length; | ||
@@ -86,3 +94,4 @@ var milliseconds = date.getUTCMilliseconds(); | ||
} | ||
}; | ||
export default formatters; |
@@ -39,3 +39,3 @@ import isValid from "../isValid/index.js"; | ||
var dateRight = toDate(dirtyDateRight); | ||
if (!isValid(dateLeft) || !isValid(dateRight)) return new Date(NaN); | ||
if (!isValid(dateLeft) || !isValid(dateRight)) return NaN; | ||
var calendarDifference = differenceInCalendarDays(dateLeft, dateRight); | ||
@@ -42,0 +42,0 @@ var sign = calendarDifference < 0 ? -1 : 1; |
@@ -26,3 +26,3 @@ import getTimezoneOffsetInMilliseconds from "../_lib/getTimezoneOffsetInMilliseconds/index.js"; | ||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? | ||
* var result = differenceInCalendarDays( | ||
* const result = differenceInCalendarDays( | ||
* new Date(2012, 6, 2, 0, 0), | ||
@@ -34,3 +34,3 @@ * new Date(2011, 6, 2, 23, 0) | ||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? | ||
* var result = differenceInCalendarDays( | ||
* const result = differenceInCalendarDays( | ||
* new Date(2011, 6, 3, 0, 1), | ||
@@ -37,0 +37,0 @@ * new Date(2011, 6, 2, 23, 59) |
@@ -26,3 +26,3 @@ import getTimezoneOffsetInMilliseconds from "../_lib/getTimezoneOffsetInMilliseconds/index.js"; | ||
* // How many calendar ISO weeks are between 6 July 2014 and 21 July 2014? | ||
* var result = differenceInCalendarISOWeeks( | ||
* const result = differenceInCalendarISOWeeks( | ||
* new Date(2014, 6, 21), | ||
@@ -29,0 +29,0 @@ * new Date(2014, 6, 6) |
@@ -29,3 +29,3 @@ import getISOWeekYear from "../getISOWeekYear/index.js"; | ||
* // How many calendar ISO week-numbering years are 1 January 2010 and 1 January 2012? | ||
* var result = differenceInCalendarISOWeekYears( | ||
* const result = differenceInCalendarISOWeekYears( | ||
* new Date(2012, 0, 1), | ||
@@ -32,0 +32,0 @@ * new Date(2010, 0, 1) |
@@ -28,3 +28,3 @@ import startOfWeek from "../startOfWeek/index.js"; | ||
* // How many calendar weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInCalendarWeeks( | ||
* const result = differenceInCalendarWeeks( | ||
* new Date(2014, 6, 20), | ||
@@ -38,3 +38,3 @@ * new Date(2014, 6, 5) | ||
* // how many calendar weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInCalendarWeeks( | ||
* const result = differenceInCalendarWeeks( | ||
* new Date(2014, 6, 20), | ||
@@ -41,0 +41,0 @@ * new Date(2014, 6, 5), |
@@ -22,3 +22,3 @@ import toDate from "../toDate/index.js"; | ||
* // How many calendar years are between 31 December 2013 and 11 February 2015? | ||
* var result = differenceInCalendarYears( | ||
* const result = differenceInCalendarYears( | ||
* new Date(2015, 1, 11), | ||
@@ -25,0 +25,0 @@ * new Date(2013, 11, 31) |
@@ -48,3 +48,3 @@ import toDate from "../toDate/index.js"; | ||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2012, 6, 2, 0, 0), | ||
@@ -56,3 +56,3 @@ * new Date(2011, 6, 2, 23, 0) | ||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2011, 6, 3, 0, 1), | ||
@@ -68,3 +68,3 @@ * new Date(2011, 6, 2, 23, 59) | ||
* // period has only 92*24-1 hours. | ||
* var result = differenceInDays( | ||
* const result = differenceInDays( | ||
* new Date(2020, 5, 1), | ||
@@ -86,3 +86,3 @@ * new Date(2020, 2, 1) | ||
var isLastDayNotFull = compareLocalAsc(dateLeft, dateRight) === -sign; | ||
var isLastDayNotFull = Number(compareLocalAsc(dateLeft, dateRight) === -sign); | ||
var result = sign * (difference - isLastDayNotFull); // Prevent negative zero | ||
@@ -89,0 +89,0 @@ |
@@ -49,3 +49,3 @@ import toDate from "../toDate/index.js"; | ||
var isLastISOWeekYearNotFull = compareAsc(dateLeft, dateRight) === -sign; | ||
var isLastISOWeekYearNotFull = Number(compareAsc(dateLeft, dateRight) === -sign); | ||
var result = sign * (difference - isLastISOWeekYearNotFull); // Prevent negative zero | ||
@@ -52,0 +52,0 @@ |
@@ -23,3 +23,3 @@ import toDate from "../toDate/index.js"; | ||
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? | ||
* var result = differenceInMilliseconds( | ||
* const result = differenceInMilliseconds( | ||
* new Date(2014, 6, 2, 12, 30, 21, 700), | ||
@@ -26,0 +26,0 @@ * new Date(2014, 6, 2, 12, 30, 20, 600) |
@@ -55,3 +55,3 @@ import toDate from "../toDate/index.js"; | ||
result = sign * (difference - isLastMonthNotFull); | ||
result = sign * (difference - Number(isLastMonthNotFull)); | ||
} // Prevent negative zero | ||
@@ -58,0 +58,0 @@ |
@@ -23,3 +23,3 @@ import differenceInMilliseconds from "../differenceInMilliseconds/index.js"; | ||
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? | ||
* var result = differenceInSeconds( | ||
* const result = differenceInSeconds( | ||
* new Date(2014, 6, 2, 12, 30, 20, 0), | ||
@@ -26,0 +26,0 @@ * new Date(2014, 6, 2, 12, 30, 7, 999) |
@@ -31,3 +31,3 @@ import differenceInDays from "../differenceInDays/index.js"; | ||
* // How many full weeks are between 5 July 2014 and 20 July 2014? | ||
* var result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) | ||
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) | ||
* //=> 2 | ||
@@ -41,3 +41,3 @@ * | ||
* // only 54*24-1 hours. | ||
* var result = differenceInWeeks( | ||
* const result = differenceInWeeks( | ||
* new Date(2020, 5, 1), | ||
@@ -44,0 +44,0 @@ * new Date(2020, 2, 6) |
@@ -24,3 +24,3 @@ import toDate from "../toDate/index.js"; | ||
* // How many full years are between 31 December 2013 and 11 February 2015? | ||
* var result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) | ||
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) | ||
* //=> 1 | ||
@@ -37,10 +37,10 @@ */ | ||
dateLeft.setFullYear('1584'); | ||
dateRight.setFullYear('1584'); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full | ||
dateLeft.setFullYear(1584); | ||
dateRight.setFullYear(1584); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full | ||
// If so, result must be decreased by 1 in absolute value | ||
var isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign; | ||
var result = sign * (difference - isLastYearNotFull); // Prevent negative zero | ||
var result = sign * (difference - Number(isLastYearNotFull)); // Prevent negative zero | ||
return result === 0 ? 0 : result; | ||
} |
@@ -92,3 +92,3 @@ import compareAsc from "../compareAsc/index.js"; | ||
* // What is the distance between 2 July 2014 and 1 January 2015? | ||
* var result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) | ||
* const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) | ||
* //=> '6 months' | ||
@@ -99,3 +99,3 @@ * | ||
* // and 1 January 2015 00:00:00, including seconds? | ||
* var result = formatDistance( | ||
* const result = formatDistance( | ||
* new Date(2015, 0, 1, 0, 0, 15), | ||
@@ -110,3 +110,3 @@ * new Date(2015, 0, 1, 0, 0, 0), | ||
* // to 1 January 2015, with a suffix? | ||
* var result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* addSuffix: true | ||
@@ -119,3 +119,3 @@ * }) | ||
* import { eoLocale } from 'date-fns/locale/eo' | ||
* var result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* locale: eoLocale | ||
@@ -126,5 +126,5 @@ * }) | ||
export default function formatDistance(dirtyDate, dirtyBaseDate, dirtyOptions) { | ||
export default function formatDistance(dirtyDate, dirtyBaseDate) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
requiredArgs(2, arguments); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || defaultLocale; | ||
@@ -131,0 +131,0 @@ |
@@ -116,3 +116,3 @@ import getTimezoneOffsetInMilliseconds from "../_lib/getTimezoneOffsetInMilliseconds/index.js"; | ||
* // What is the distance between 2 July 2014 and 1 January 2015? | ||
* var result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2)) | ||
* const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2)) | ||
* //=> '6 months' | ||
@@ -123,3 +123,3 @@ * | ||
* // and 1 January 2015 00:00:00? | ||
* var result = formatDistanceStrict( | ||
* const result = formatDistanceStrict( | ||
* new Date(2015, 0, 1, 0, 0, 15), | ||
@@ -133,3 +133,3 @@ * new Date(2015, 0, 1, 0, 0, 0) | ||
* // to 1 January 2015, with a suffix? | ||
* var result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* addSuffix: true | ||
@@ -142,3 +142,3 @@ * }) | ||
* // to 1 January 2015, in minutes? | ||
* var result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), { | ||
* unit: 'minute' | ||
@@ -151,3 +151,3 @@ * }) | ||
* // to 28 January 2015, in months, rounded up? | ||
* var result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), { | ||
* unit: 'month', | ||
@@ -161,3 +161,3 @@ * roundingMethod: 'ceil' | ||
* import { eoLocale } from 'date-fns/locale/eo' | ||
* var result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* locale: eoLocale | ||
@@ -168,5 +168,5 @@ * }) | ||
export default function formatDistanceStrict(dirtyDate, dirtyBaseDate, dirtyOptions) { | ||
export default function formatDistanceStrict(dirtyDate, dirtyBaseDate) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
requiredArgs(2, arguments); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || defaultLocale; | ||
@@ -173,0 +173,0 @@ |
@@ -8,2 +8,3 @@ import differenceInCalendarDays from "../differenceInCalendarDays/index.js"; | ||
import requiredArgs from "../_lib/requiredArgs/index.js"; | ||
/** | ||
@@ -44,3 +45,2 @@ * @name formatRelative | ||
*/ | ||
export default function formatRelative(dirtyDate, dirtyBaseDate, dirtyOptions) { | ||
@@ -50,5 +50,9 @@ requiredArgs(2, arguments); | ||
var baseDate = toDate(dirtyBaseDate); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || defaultLocale; | ||
var _ref = dirtyOptions || {}, | ||
_ref$locale = _ref.locale, | ||
locale = _ref$locale === void 0 ? defaultLocale : _ref$locale, | ||
_ref$weekStartsOn = _ref.weekStartsOn, | ||
weekStartsOn = _ref$weekStartsOn === void 0 ? 0 : _ref$weekStartsOn; | ||
if (!locale.localize) { | ||
@@ -92,4 +96,10 @@ throw new RangeError('locale must contain localize property'); | ||
var utcBaseDate = subMilliseconds(baseDate, getTimezoneOffsetInMilliseconds(baseDate)); | ||
var formatStr = locale.formatRelative(token, utcDate, utcBaseDate, options); | ||
return format(date, formatStr, options); | ||
var formatStr = locale.formatRelative(token, utcDate, utcBaseDate, { | ||
locale, | ||
weekStartsOn | ||
}); | ||
return format(date, formatStr, { | ||
locale, | ||
weekStartsOn | ||
}); | ||
} |
@@ -36,3 +36,3 @@ import startOfWeek from "../startOfWeek/index.js"; | ||
* // Which week of the local week numbering year is 2 January 2005 with default options? | ||
* var result = getISOWeek(new Date(2005, 0, 2)) | ||
* const result = getISOWeek(new Date(2005, 0, 2)) | ||
* //=> 2 | ||
@@ -43,3 +43,3 @@ * | ||
* // and the first week of the year always contains 4 January? | ||
* var result = getISOWeek(new Date(2005, 0, 2), { | ||
* const result = getISOWeek(new Date(2005, 0, 2), { | ||
* weekStartsOn: 1, | ||
@@ -46,0 +46,0 @@ * firstWeekContainsDate: 4 |
@@ -72,9 +72,8 @@ import toDate from "../toDate/index.js"; | ||
* @example | ||
* var result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd') | ||
* const result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd') | ||
* //=> '2014-02-11' | ||
*/ | ||
export default function lightFormat(dirtyDate, dirtyFormatStr) { | ||
export default function lightFormat(dirtyDate, formatStr) { | ||
requiredArgs(2, arguments); | ||
var formatStr = String(dirtyFormatStr); | ||
var originalDate = toDate(dirtyDate); | ||
@@ -91,3 +90,6 @@ | ||
var utcDate = subMilliseconds(originalDate, timezoneOffset); | ||
var result = formatStr.match(formattingTokensRegExp).map(function (substring) { | ||
var tokens = formatStr.match(formattingTokensRegExp); // The only case when formattingTokensRegExp doesn't match the string is when it's empty | ||
if (!tokens) return ''; | ||
var result = tokens.map(function (substring) { | ||
// Replace two single quote characters with one single quote character | ||
@@ -107,3 +109,3 @@ if (substring === "''") { | ||
if (formatter) { | ||
return formatter(utcDate, substring, null, {}); | ||
return formatter(utcDate, substring); | ||
} | ||
@@ -121,3 +123,9 @@ | ||
function cleanEscapedString(input) { | ||
return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'"); | ||
var matches = input.match(escapedStringRegExp); | ||
if (!matches) { | ||
return input; | ||
} | ||
return matches[1].replace(doubleQuoteRegExp, "'"); | ||
} |
@@ -23,4 +23,4 @@ import formatDistance from "./_lib/formatDistance/index.js"; | ||
options: { | ||
weekStartsOn: 0 | ||
/* Sunday */ | ||
weekStartsOn: 6 | ||
/* Saturday */ | ||
, | ||
@@ -27,0 +27,0 @@ firstWeekContainsDate: 1 |
@@ -109,3 +109,3 @@ "use strict"; | ||
* // What is the distance between 2 July 2014 and 1 January 2015? | ||
* var result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) | ||
* const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) | ||
* //=> '6 months' | ||
@@ -116,3 +116,3 @@ * | ||
* // and 1 January 2015 00:00:00, including seconds? | ||
* var result = formatDistance( | ||
* const result = formatDistance( | ||
* new Date(2015, 0, 1, 0, 0, 15), | ||
@@ -127,3 +127,3 @@ * new Date(2015, 0, 1, 0, 0, 0), | ||
* // to 1 January 2015, with a suffix? | ||
* var result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* addSuffix: true | ||
@@ -136,3 +136,3 @@ * }) | ||
* import { eoLocale } from 'date-fns/locale/eo' | ||
* var result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* locale: eoLocale | ||
@@ -143,5 +143,5 @@ * }) | ||
function formatDistance(dirtyDate, dirtyBaseDate, dirtyOptions) { | ||
function formatDistance(dirtyDate, dirtyBaseDate) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _index8.default)(2, arguments); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || _index4.default; | ||
@@ -148,0 +148,0 @@ |
@@ -131,3 +131,3 @@ "use strict"; | ||
* // What is the distance between 2 July 2014 and 1 January 2015? | ||
* var result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2)) | ||
* const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2)) | ||
* //=> '6 months' | ||
@@ -138,3 +138,3 @@ * | ||
* // and 1 January 2015 00:00:00? | ||
* var result = formatDistanceStrict( | ||
* const result = formatDistanceStrict( | ||
* new Date(2015, 0, 1, 0, 0, 15), | ||
@@ -148,3 +148,3 @@ * new Date(2015, 0, 1, 0, 0, 0) | ||
* // to 1 January 2015, with a suffix? | ||
* var result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), { | ||
* addSuffix: true | ||
@@ -157,3 +157,3 @@ * }) | ||
* // to 1 January 2015, in minutes? | ||
* var result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), { | ||
* unit: 'minute' | ||
@@ -166,3 +166,3 @@ * }) | ||
* // to 28 January 2015, in months, rounded up? | ||
* var result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), { | ||
* unit: 'month', | ||
@@ -176,3 +176,3 @@ * roundingMethod: 'ceil' | ||
* import { eoLocale } from 'date-fns/locale/eo' | ||
* var result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), { | ||
* locale: eoLocale | ||
@@ -183,5 +183,5 @@ * }) | ||
function formatDistanceStrict(dirtyDate, dirtyBaseDate, dirtyOptions) { | ||
function formatDistanceStrict(dirtyDate, dirtyBaseDate) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _index6.default)(2, arguments); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || _index5.default; | ||
@@ -188,0 +188,0 @@ |
@@ -63,5 +63,9 @@ "use strict"; | ||
var baseDate = (0, _index5.default)(dirtyBaseDate); | ||
var options = dirtyOptions || {}; | ||
var locale = options.locale || _index3.default; | ||
var _ref = dirtyOptions || {}, | ||
_ref$locale = _ref.locale, | ||
locale = _ref$locale === void 0 ? _index3.default : _ref$locale, | ||
_ref$weekStartsOn = _ref.weekStartsOn, | ||
weekStartsOn = _ref$weekStartsOn === void 0 ? 0 : _ref$weekStartsOn; | ||
if (!locale.localize) { | ||
@@ -105,6 +109,12 @@ throw new RangeError('locale must contain localize property'); | ||
var utcBaseDate = (0, _index4.default)(baseDate, (0, _index6.default)(baseDate)); | ||
var formatStr = locale.formatRelative(token, utcDate, utcBaseDate, options); | ||
return (0, _index2.default)(date, formatStr, options); | ||
var formatStr = locale.formatRelative(token, utcDate, utcBaseDate, { | ||
locale, | ||
weekStartsOn | ||
}); | ||
return (0, _index2.default)(date, formatStr, { | ||
locale, | ||
weekStartsOn | ||
}); | ||
} | ||
module.exports = exports.default; |
@@ -49,3 +49,3 @@ "use strict"; | ||
* // Which week of the local week numbering year is 2 January 2005 with default options? | ||
* var result = getISOWeek(new Date(2005, 0, 2)) | ||
* const result = getISOWeek(new Date(2005, 0, 2)) | ||
* //=> 2 | ||
@@ -56,3 +56,3 @@ * | ||
* // and the first week of the year always contains 4 January? | ||
* var result = getISOWeek(new Date(2005, 0, 2), { | ||
* const result = getISOWeek(new Date(2005, 0, 2), { | ||
* weekStartsOn: 1, | ||
@@ -59,0 +59,0 @@ * firstWeekContainsDate: 4 |
@@ -87,9 +87,8 @@ "use strict"; | ||
* @example | ||
* var result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd') | ||
* const result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd') | ||
* //=> '2014-02-11' | ||
*/ | ||
function lightFormat(dirtyDate, dirtyFormatStr) { | ||
function lightFormat(dirtyDate, formatStr) { | ||
(0, _index6.default)(2, arguments); | ||
var formatStr = String(dirtyFormatStr); | ||
var originalDate = (0, _index.default)(dirtyDate); | ||
@@ -106,3 +105,6 @@ | ||
var utcDate = (0, _index5.default)(originalDate, timezoneOffset); | ||
var result = formatStr.match(formattingTokensRegExp).map(function (substring) { | ||
var tokens = formatStr.match(formattingTokensRegExp); // The only case when formattingTokensRegExp doesn't match the string is when it's empty | ||
if (!tokens) return ''; | ||
var result = tokens.map(function (substring) { | ||
// Replace two single quote characters with one single quote character | ||
@@ -122,3 +124,3 @@ if (substring === "''") { | ||
if (formatter) { | ||
return formatter(utcDate, substring, null, {}); | ||
return formatter(utcDate, substring); | ||
} | ||
@@ -136,5 +138,11 @@ | ||
function cleanEscapedString(input) { | ||
return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'"); | ||
var matches = input.match(escapedStringRegExp); | ||
if (!matches) { | ||
return input; | ||
} | ||
return matches[1].replace(doubleQuoteRegExp, "'"); | ||
} | ||
module.exports = exports.default; |
@@ -36,4 +36,4 @@ "use strict"; | ||
options: { | ||
weekStartsOn: 0 | ||
/* Sunday */ | ||
weekStartsOn: 6 | ||
/* Saturday */ | ||
, | ||
@@ -40,0 +40,0 @@ firstWeekContainsDate: 1 |
{ | ||
"name": "date-fns", | ||
"version": "2.21.1", | ||
"version": "2.21.2", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "contributors": ["Sasha Koss <koss@nocorp.me>", "Lesha Koss <regiusprod@gmail.com>"], |
Sorry, the diff of this file is too big to display
5837813
119795