date-fns
Advanced tools
Comparing version 2.18.0 to 2.19.0
@@ -7,7 +7,3 @@ "use strict"; | ||
exports.default = getTimezoneOffsetInMilliseconds; | ||
var MILLISECONDS_IN_MINUTE = 60000; | ||
function getDateMillisecondsPart(date) { | ||
return date.getTime() % MILLISECONDS_IN_MINUTE; | ||
} | ||
/** | ||
@@ -24,13 +20,8 @@ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. | ||
*/ | ||
function getTimezoneOffsetInMilliseconds(dirtyDate) { | ||
var date = new Date(dirtyDate.getTime()); | ||
var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset()); | ||
date.setSeconds(0, 0); | ||
var hasNegativeUTCOffset = baseTimezoneOffset > 0; | ||
var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date); | ||
return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset; | ||
function getTimezoneOffsetInMilliseconds(date) { | ||
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); | ||
utcDate.setUTCFullYear(date.getFullYear()); | ||
return date.getTime() - utcDate.getTime(); | ||
} | ||
module.exports = exports.default; |
@@ -47,20 +47,27 @@ "use strict"; | ||
var sign = (0, _index3.default)(dateLeft, dateRight); | ||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight)); // This will check if the date is end of Feb and assign a higher end of month date | ||
// to compare it with Jan | ||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight)); | ||
var result; // Check for the difference of less than month | ||
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { | ||
dateLeft.setDate(30); | ||
} | ||
if (difference < 1) { | ||
result = 0; | ||
} else { | ||
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { | ||
// This will check if the date is end of Feb and assign a higher end of month date | ||
// to compare it with Jan | ||
dateLeft.setDate(30); | ||
} | ||
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 | ||
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 = (0, _index3.default)(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month | ||
var isLastMonthNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month | ||
if ((0, _index5.default)((0, _index.default)(dirtyDateLeft)) && difference === 1 && (0, _index3.default)(dirtyDateLeft, dateRight) === 1) { | ||
isLastMonthNotFull = false; | ||
} | ||
if ((0, _index5.default)((0, _index.default)(dirtyDateLeft)) && difference === 1 && (0, _index3.default)(dirtyDateLeft, dateRight) === 1) { | ||
isLastMonthNotFull = false; | ||
} | ||
var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero | ||
result = sign * (difference - isLastMonthNotFull); | ||
} // Prevent negative zero | ||
return result === 0 ? 0 : result; | ||
@@ -67,0 +74,0 @@ } |
@@ -1,6 +0,1 @@ | ||
var MILLISECONDS_IN_MINUTE = 60000; | ||
function getDateMillisecondsPart(date) { | ||
return date.getTime() % MILLISECONDS_IN_MINUTE; | ||
} | ||
/** | ||
@@ -17,11 +12,6 @@ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. | ||
*/ | ||
export default function getTimezoneOffsetInMilliseconds(dirtyDate) { | ||
var date = new Date(dirtyDate.getTime()); | ||
var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset()); | ||
date.setSeconds(0, 0); | ||
var hasNegativeUTCOffset = baseTimezoneOffset > 0; | ||
var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date); | ||
return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset; | ||
export default function getTimezoneOffsetInMilliseconds(date) { | ||
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); | ||
utcDate.setUTCFullYear(date.getFullYear()); | ||
return date.getTime() - utcDate.getTime(); | ||
} |
@@ -34,21 +34,28 @@ import toDate from "../toDate/index.js"; | ||
var sign = compareAsc(dateLeft, dateRight); | ||
var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); // This will check if the date is end of Feb and assign a higher end of month date | ||
// to compare it with Jan | ||
var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); | ||
var result; // Check for the difference of less than month | ||
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { | ||
dateLeft.setDate(30); | ||
} | ||
if (difference < 1) { | ||
result = 0; | ||
} else { | ||
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { | ||
// This will check if the date is end of Feb and assign a higher end of month date | ||
// to compare it with Jan | ||
dateLeft.setDate(30); | ||
} | ||
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 | ||
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; // Check for cases of one full calendar month | ||
var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month | ||
if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) { | ||
isLastMonthNotFull = false; | ||
} | ||
if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) { | ||
isLastMonthNotFull = false; | ||
} | ||
var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero | ||
result = sign * (difference - isLastMonthNotFull); | ||
} // Prevent negative zero | ||
return result === 0 ? 0 : result; | ||
} |
import startOfWeek from "../startOfWeek/index.js"; | ||
import requiredArgs from "../_lib/requiredArgs/index.js"; | ||
/** | ||
@@ -37,3 +38,2 @@ * @name isSameWeek | ||
*/ | ||
export default function isSameWeek(dirtyDateLeft, dirtyDateRight, dirtyOptions) { | ||
@@ -40,0 +40,0 @@ requiredArgs(2, arguments); |
@@ -27,5 +27,5 @@ import formatDistance from "./_lib/formatDistance/index.js"; | ||
, | ||
firstWeekContainsDate: 1 | ||
firstWeekContainsDate: 4 | ||
} | ||
}; | ||
export default locale; |
@@ -20,3 +20,3 @@ import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js"; | ||
short: ['sö', 'må', 'ti', 'on', 'to', 'fr', 'lö'], | ||
abbreviated: ['sön', 'mån', 'tis', 'ons', 'tor', 'fre', 'lör'], | ||
abbreviated: ['sön', 'mån', 'tis', 'ons', 'tors', 'fre', 'lör'], | ||
wide: ['söndag', 'måndag', 'tisdag', 'onsdag', 'torsdag', 'fredag', 'lördag'] // https://www.unicode.org/cldr/charts/32/summary/sv.html#1888 | ||
@@ -23,0 +23,0 @@ |
@@ -33,3 +33,3 @@ import buildMatchPatternFn from "../../../_lib/buildMatchPatternFn/index.js"; | ||
short: /^(sö|må|ti|on|to|fr|lö)/i, | ||
abbreviated: /^(sön|mån|tis|ons|tor|fre|lör)/i, | ||
abbreviated: /^(sön|mån|tis|ons|tors|fre|lör)/i, | ||
wide: /^(söndag|måndag|tisdag|onsdag|torsdag|fredag|lördag)/i | ||
@@ -36,0 +36,0 @@ }; |
@@ -122,4 +122,5 @@ import toInteger from "../_lib/toInteger/index.js"; | ||
var result = new Date(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate(), dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); | ||
result.setFullYear(dirtyDate.getUTCFullYear()); | ||
var result = new Date(0); | ||
result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate()); | ||
result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); | ||
return result; | ||
@@ -126,0 +127,0 @@ } |
@@ -5,2 +5,3 @@ import toDate from "../toDate/index.js"; | ||
import requiredArgs from "../_lib/requiredArgs/index.js"; | ||
/** | ||
@@ -44,3 +45,2 @@ * @name set | ||
*/ | ||
export default function set(dirtyDate, values) { | ||
@@ -55,3 +55,3 @@ requiredArgs(2, arguments); | ||
if (isNaN(date)) { | ||
if (isNaN(date.getTime())) { | ||
return new Date(NaN); | ||
@@ -58,0 +58,0 @@ } |
@@ -40,3 +40,3 @@ "use strict"; | ||
, | ||
firstWeekContainsDate: 1 | ||
firstWeekContainsDate: 4 | ||
} | ||
@@ -43,0 +43,0 @@ }; |
@@ -30,3 +30,3 @@ "use strict"; | ||
short: ['sö', 'må', 'ti', 'on', 'to', 'fr', 'lö'], | ||
abbreviated: ['sön', 'mån', 'tis', 'ons', 'tor', 'fre', 'lör'], | ||
abbreviated: ['sön', 'mån', 'tis', 'ons', 'tors', 'fre', 'lör'], | ||
wide: ['söndag', 'måndag', 'tisdag', 'onsdag', 'torsdag', 'fredag', 'lördag'] // https://www.unicode.org/cldr/charts/32/summary/sv.html#1888 | ||
@@ -33,0 +33,0 @@ |
@@ -44,3 +44,3 @@ "use strict"; | ||
short: /^(sö|må|ti|on|to|fr|lö)/i, | ||
abbreviated: /^(sön|mån|tis|ons|tor|fre|lör)/i, | ||
abbreviated: /^(sön|mån|tis|ons|tors|fre|lör)/i, | ||
wide: /^(söndag|måndag|tisdag|onsdag|torsdag|fredag|lördag)/i | ||
@@ -47,0 +47,0 @@ }; |
{ | ||
"name": "date-fns", | ||
"version": "2.18.0", | ||
"version": "2.19.0", | ||
"sideEffects": false, | ||
@@ -49,6 +49,5 @@ "contributors": ["Sasha Koss <koss@nocorp.me>", "Lesha Koss <regiusprod@gmail.com>"], | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@date-fns/date-fns-scripts": "0.0.4", | ||
"@date-fns/date-fns-scripts": "^0.0.3", | ||
"@octokit/core": "^3.2.5", | ||
"@types/jest": "^26.0.13", | ||
"@types/mocha": "^8.2.1", | ||
"@types/node": "^14.6.3", | ||
@@ -76,3 +75,2 @@ "@types/power-assert": "^1.5.3", | ||
"jest": "^24.8.0", | ||
"jest-plugin-context": "^2.9.0", | ||
"js-beautify": "^1.5.10", | ||
@@ -79,0 +77,0 @@ "js-fns": "^2.5.1", |
@@ -133,4 +133,5 @@ "use strict"; | ||
var result = new Date(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate(), dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); | ||
result.setFullYear(dirtyDate.getUTCFullYear()); | ||
var result = new Date(0); | ||
result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate()); | ||
result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); | ||
return result; | ||
@@ -137,0 +138,0 @@ } |
@@ -65,3 +65,3 @@ "use strict"; | ||
if (isNaN(date)) { | ||
if (isNaN(date.getTime())) { | ||
return new Date(NaN); | ||
@@ -68,0 +68,0 @@ } |
Sorry, the diff of this file is too big to display
5560550
73
4704
115438