Socket
Socket
Sign inDemoInstall

@date-io/date-fns

Package Overview
Dependencies
4
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.16.0 to 2.17.0

8

build/date-fns-utils.d.ts
import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils";
import defaultLocale from "date-fns/locale/en-US";
declare type Locale = typeof defaultLocale;
type Locale = typeof defaultLocale;
export default class DateFnsUtils implements IUtils<Date> {

@@ -47,5 +47,5 @@ lib: string;

setYear: (value: Date, count: number) => Date;
date: (value?: any) => Date;
date: (value?: any) => Date | null;
toJsDate: (value: Date) => Date;
parse: (value: string, formatString: string) => Date;
parse: (value: string, formatString: string) => Date | null;
format: (date: Date, formatKey: keyof DateIOFormats) => string;

@@ -58,2 +58,4 @@ formatByString: (date: Date, formatString: string) => string;

isBeforeYear: (date: Date, value: Date) => boolean;
isBeforeMonth(value: Date, comparing: Date): boolean;
isAfterMonth(value: Date, comparing: Date): boolean;
isAfterYear: (date: Date, value: Date) => boolean;

@@ -60,0 +62,0 @@ isWithinRange: (date: Date, [start, end]: [Date, Date]) => boolean;

@@ -56,3 +56,3 @@ import addDays from 'date-fns/addDays';

var defaultFormats = {
const defaultFormats = {
dayOfMonth: "d",

@@ -86,12 +86,11 @@ fullDate: "PP",

};
var DateFnsUtils = /** @class */ (function () {
function DateFnsUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats;
class DateFnsUtils {
constructor({ locale, formats, } = {}) {
this.lib = "date-fns";
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
this.is12HourCycleInCurrentLocale = function () {
if (_this.locale) {
return /a/.test(_this.locale.formatLong.time());
this.is12HourCycleInCurrentLocale = () => {
var _a;
if (this.locale) {
return /a/.test((_a = this.locale.formatLong) === null || _a === void 0 ? void 0 : _a.time());
}

@@ -101,141 +100,144 @@ // By default date-fns is using en-US locale with am/pm enabled

};
this.getFormatHelperText = function (format) {
this.getFormatHelperText = (format) => {
var _a, _b;
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
var longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
var locale = _this.locale || defaultLocale;
return format
.match(longFormatRegexp)
.map(function (token) {
var firstCharacter = token[0];
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
const locale = this.locale || defaultLocale;
return ((_b = (_a = format
.match(longFormatRegexp)) === null || _a === void 0 ? void 0 : _a.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "p" || firstCharacter === "P") {
var longFormatter = longFormatters[firstCharacter];
const longFormatter = longFormatters[firstCharacter];
return longFormatter(token, locale.formatLong, {});
}
return token;
})
.join("")
.replace(/(aaa|aa|a)/g, "(a|p)m")
.toLocaleLowerCase();
}).join("").replace(/(aaa|aa|a)/g, "(a|p)m").toLocaleLowerCase()) !== null && _b !== void 0 ? _b : format);
};
this.parseISO = function (isoString) {
this.parseISO = (isoString) => {
return parseISO(isoString);
};
this.toISO = function (value) {
this.toISO = (value) => {
return formatISO(value, { format: "extended" });
};
this.getCurrentLocaleCode = function () {
this.getCurrentLocaleCode = () => {
var _a;
return ((_a = _this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US";
return ((_a = this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US";
};
this.addSeconds = function (value, count) {
this.addSeconds = (value, count) => {
return addSeconds(value, count);
};
this.addMinutes = function (value, count) {
this.addMinutes = (value, count) => {
return addMinutes(value, count);
};
this.addHours = function (value, count) {
this.addHours = (value, count) => {
return addHours(value, count);
};
this.addDays = function (value, count) {
this.addDays = (value, count) => {
return addDays(value, count);
};
this.addWeeks = function (value, count) {
this.addWeeks = (value, count) => {
return addWeeks(value, count);
};
this.addMonths = function (value, count) {
this.addMonths = (value, count) => {
return addMonths(value, count);
};
this.addYears = function (value, count) {
this.addYears = (value, count) => {
return addYears(value, count);
};
this.isValid = function (value) {
return isValid(_this.date(value));
this.isValid = (value) => {
return isValid(this.date(value));
};
this.getDiff = function (value, comparing, unit) {
this.getDiff = (value, comparing, unit) => {
var _a;
// we output 0 if the compare date is string and parsing is not valid
const dateToCompare = (_a = this.date(comparing)) !== null && _a !== void 0 ? _a : value;
if (!this.isValid(dateToCompare)) {
return 0;
}
switch (unit) {
case "years":
return differenceInYears(value, _this.date(comparing));
return differenceInYears(value, dateToCompare);
case "quarters":
return differenceInQuarters(value, _this.date(comparing));
return differenceInQuarters(value, dateToCompare);
case "months":
return differenceInMonths(value, _this.date(comparing));
return differenceInMonths(value, dateToCompare);
case "weeks":
return differenceInWeeks(value, _this.date(comparing));
return differenceInWeeks(value, dateToCompare);
case "days":
return differenceInDays(value, _this.date(comparing));
return differenceInDays(value, dateToCompare);
case "hours":
return differenceInHours(value, _this.date(comparing));
return differenceInHours(value, dateToCompare);
case "minutes":
return differenceInMinutes(value, _this.date(comparing));
return differenceInMinutes(value, dateToCompare);
case "seconds":
return differenceInSeconds(value, _this.date(comparing));
return differenceInSeconds(value, dateToCompare);
default: {
return differenceInMilliseconds(value, _this.date(comparing));
return differenceInMilliseconds(value, dateToCompare);
}
}
};
this.isAfter = function (value, comparing) {
this.isAfter = (value, comparing) => {
return isAfter(value, comparing);
};
this.isBefore = function (value, comparing) {
this.isBefore = (value, comparing) => {
return isBefore(value, comparing);
};
this.startOfDay = function (value) {
this.startOfDay = (value) => {
return startOfDay(value);
};
this.endOfDay = function (value) {
this.endOfDay = (value) => {
return endOfDay(value);
};
this.getHours = function (value) {
this.getHours = (value) => {
return getHours(value);
};
this.setHours = function (value, count) {
this.setHours = (value, count) => {
return setHours(value, count);
};
this.setMinutes = function (value, count) {
this.setMinutes = (value, count) => {
return setMinutes(value, count);
};
this.getSeconds = function (value) {
this.getSeconds = (value) => {
return getSeconds(value);
};
this.setSeconds = function (value, count) {
this.setSeconds = (value, count) => {
return setSeconds(value, count);
};
this.isSameDay = function (value, comparing) {
this.isSameDay = (value, comparing) => {
return isSameDay(value, comparing);
};
this.isSameMonth = function (value, comparing) {
this.isSameMonth = (value, comparing) => {
return isSameMonth(value, comparing);
};
this.isSameYear = function (value, comparing) {
this.isSameYear = (value, comparing) => {
return isSameYear(value, comparing);
};
this.isSameHour = function (value, comparing) {
this.isSameHour = (value, comparing) => {
return isSameHour(value, comparing);
};
this.startOfYear = function (value) {
this.startOfYear = (value) => {
return startOfYear(value);
};
this.endOfYear = function (value) {
this.endOfYear = (value) => {
return endOfYear(value);
};
this.startOfMonth = function (value) {
this.startOfMonth = (value) => {
return startOfMonth(value);
};
this.endOfMonth = function (value) {
this.endOfMonth = (value) => {
return endOfMonth(value);
};
this.startOfWeek = function (value) {
return startOfWeek(value, { locale: _this.locale });
this.startOfWeek = (value) => {
return startOfWeek(value, { locale: this.locale });
};
this.endOfWeek = function (value) {
return endOfWeek(value, { locale: _this.locale });
this.endOfWeek = (value) => {
return endOfWeek(value, { locale: this.locale });
};
this.getYear = function (value) {
this.getYear = (value) => {
return getYear(value);
};
this.setYear = function (value, count) {
this.setYear = (value, count) => {
return setYear(value, count);
};
this.date = function (value) {
this.date = (value) => {
if (typeof value === "undefined") {

@@ -249,18 +251,18 @@ return new Date();

};
this.toJsDate = function (value) {
this.toJsDate = (value) => {
return value;
};
this.parse = function (value, formatString) {
this.parse = (value, formatString) => {
if (value === "") {
return null;
}
return dateFnsParse(value, formatString, new Date(), { locale: _this.locale });
return dateFnsParse(value, formatString, new Date(), { locale: this.locale });
};
this.format = function (date, formatKey) {
return _this.formatByString(date, _this.formats[formatKey]);
this.format = (date, formatKey) => {
return this.formatByString(date, this.formats[formatKey]);
};
this.formatByString = function (date, formatString) {
return format(date, formatString, { locale: _this.locale });
this.formatByString = (date, formatString) => {
return format(date, formatString, { locale: this.locale });
};
this.isEqual = function (date, comparing) {
this.isEqual = (date, comparing) => {
if (date === null && comparing === null) {

@@ -271,81 +273,80 @@ return true;

};
this.isNull = function (date) {
this.isNull = (date) => {
return date === null;
};
this.isAfterDay = function (date, value) {
this.isAfterDay = (date, value) => {
return isAfter(date, endOfDay(value));
};
this.isBeforeDay = function (date, value) {
this.isBeforeDay = (date, value) => {
return isBefore(date, startOfDay(value));
};
this.isBeforeYear = function (date, value) {
this.isBeforeYear = (date, value) => {
return isBefore(date, startOfYear(value));
};
this.isAfterYear = function (date, value) {
this.isAfterYear = (date, value) => {
return isAfter(date, endOfYear(value));
};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return isWithinInterval(date, { start: start, end: end });
this.isWithinRange = (date, [start, end]) => {
return isWithinInterval(date, { start, end });
};
this.formatNumber = function (numberToFormat) {
this.formatNumber = (numberToFormat) => {
return numberToFormat;
};
this.getMinutes = function (date) {
this.getMinutes = (date) => {
return getMinutes(date);
};
this.getDate = function (date) {
this.getDate = (date) => {
return getDate(date);
};
this.setDate = function (date, count) {
this.setDate = (date, count) => {
return setDate(date, count);
};
this.getMonth = function (date) {
this.getMonth = (date) => {
return getMonth(date);
};
this.getDaysInMonth = function (date) {
this.getDaysInMonth = (date) => {
return getDaysInMonth(date);
};
this.setMonth = function (date, count) {
this.setMonth = (date, count) => {
return setMonth(date, count);
};
this.getMeridiemText = function (ampm) {
this.getMeridiemText = (ampm) => {
return ampm === "am" ? "AM" : "PM";
};
this.getNextMonth = function (date) {
this.getNextMonth = (date) => {
return addMonths(date, 1);
};
this.getPreviousMonth = function (date) {
this.getPreviousMonth = (date) => {
return addMonths(date, -1);
};
this.getMonthArray = function (date) {
var firstMonth = startOfYear(date);
var monthArray = [firstMonth];
this.getMonthArray = (date) => {
const firstMonth = startOfYear(date);
const monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(_this.getNextMonth(prevMonth));
const prevMonth = monthArray[monthArray.length - 1];
monthArray.push(this.getNextMonth(prevMonth));
}
return monthArray;
};
this.mergeDateAndTime = function (date, time) {
return _this.setSeconds(_this.setMinutes(_this.setHours(date, _this.getHours(time)), _this.getMinutes(time)), _this.getSeconds(time));
this.mergeDateAndTime = (date, time) => {
return this.setSeconds(this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), this.getSeconds(time));
};
this.getWeekdays = function () {
var now = new Date();
this.getWeekdays = () => {
const now = new Date();
return eachDayOfInterval({
start: startOfWeek(now, { locale: _this.locale }),
end: endOfWeek(now, { locale: _this.locale }),
}).map(function (day) { return _this.formatByString(day, "EEEEEE"); });
start: startOfWeek(now, { locale: this.locale }),
end: endOfWeek(now, { locale: this.locale }),
}).map((day) => this.formatByString(day, "EEEEEE"));
};
this.getWeekArray = function (date) {
var start = startOfWeek(startOfMonth(date), { locale: _this.locale });
var end = endOfWeek(endOfMonth(date), { locale: _this.locale });
var count = 0;
var current = start;
var nestedWeeks = [];
var lastDay = null;
this.getWeekArray = (date) => {
const start = startOfWeek(startOfMonth(date), { locale: this.locale });
const end = endOfWeek(endOfMonth(date), { locale: this.locale });
let count = 0;
let current = start;
const nestedWeeks = [];
let lastDay = null;
while (isBefore(current, end)) {
var weekNumber = Math.floor(count / 7);
const weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
var day = getDay(current);
const day = getDay(current);
if (lastDay !== day) {

@@ -360,7 +361,7 @@ lastDay = day;

};
this.getYearRange = function (start, end) {
var startDate = startOfYear(start);
var endDate = endOfYear(end);
var years = [];
var current = startDate;
this.getYearRange = (start, end) => {
const startDate = startOfYear(start);
const endDate = endOfYear(end);
const years = [];
let current = startDate;
while (isBefore(current, endDate)) {

@@ -375,5 +376,10 @@ years.push(current);

}
return DateFnsUtils;
}());
isBeforeMonth(value, comparing) {
return isBefore(value, startOfMonth(comparing));
}
isAfterMonth(value, comparing) {
return isAfter(value, startOfMonth(comparing));
}
}
export { DateFnsUtils as default };

@@ -115,3 +115,3 @@ 'use strict';

var defaultFormats = {
const defaultFormats = {
dayOfMonth: "d",

@@ -145,12 +145,11 @@ fullDate: "PP",

};
var DateFnsUtils = /** @class */ (function () {
function DateFnsUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats;
class DateFnsUtils {
constructor({ locale, formats, } = {}) {
this.lib = "date-fns";
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
this.is12HourCycleInCurrentLocale = function () {
if (_this.locale) {
return /a/.test(_this.locale.formatLong.time());
this.is12HourCycleInCurrentLocale = () => {
var _a;
if (this.locale) {
return /a/.test((_a = this.locale.formatLong) === null || _a === void 0 ? void 0 : _a.time());
}

@@ -160,141 +159,144 @@ // By default date-fns is using en-US locale with am/pm enabled

};
this.getFormatHelperText = function (format) {
this.getFormatHelperText = (format) => {
var _a, _b;
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
var longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
var locale = _this.locale || defaultLocale__default["default"];
return format
.match(longFormatRegexp)
.map(function (token) {
var firstCharacter = token[0];
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
const locale = this.locale || defaultLocale__default["default"];
return ((_b = (_a = format
.match(longFormatRegexp)) === null || _a === void 0 ? void 0 : _a.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "p" || firstCharacter === "P") {
var longFormatter = longFormatters__default["default"][firstCharacter];
const longFormatter = longFormatters__default["default"][firstCharacter];
return longFormatter(token, locale.formatLong, {});
}
return token;
})
.join("")
.replace(/(aaa|aa|a)/g, "(a|p)m")
.toLocaleLowerCase();
}).join("").replace(/(aaa|aa|a)/g, "(a|p)m").toLocaleLowerCase()) !== null && _b !== void 0 ? _b : format);
};
this.parseISO = function (isoString) {
this.parseISO = (isoString) => {
return parseISO__default["default"](isoString);
};
this.toISO = function (value) {
this.toISO = (value) => {
return formatISO__default["default"](value, { format: "extended" });
};
this.getCurrentLocaleCode = function () {
this.getCurrentLocaleCode = () => {
var _a;
return ((_a = _this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US";
return ((_a = this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US";
};
this.addSeconds = function (value, count) {
this.addSeconds = (value, count) => {
return addSeconds__default["default"](value, count);
};
this.addMinutes = function (value, count) {
this.addMinutes = (value, count) => {
return addMinutes__default["default"](value, count);
};
this.addHours = function (value, count) {
this.addHours = (value, count) => {
return addHours__default["default"](value, count);
};
this.addDays = function (value, count) {
this.addDays = (value, count) => {
return addDays__default["default"](value, count);
};
this.addWeeks = function (value, count) {
this.addWeeks = (value, count) => {
return addWeeks__default["default"](value, count);
};
this.addMonths = function (value, count) {
this.addMonths = (value, count) => {
return addMonths__default["default"](value, count);
};
this.addYears = function (value, count) {
this.addYears = (value, count) => {
return addYears__default["default"](value, count);
};
this.isValid = function (value) {
return isValid__default["default"](_this.date(value));
this.isValid = (value) => {
return isValid__default["default"](this.date(value));
};
this.getDiff = function (value, comparing, unit) {
this.getDiff = (value, comparing, unit) => {
var _a;
// we output 0 if the compare date is string and parsing is not valid
const dateToCompare = (_a = this.date(comparing)) !== null && _a !== void 0 ? _a : value;
if (!this.isValid(dateToCompare)) {
return 0;
}
switch (unit) {
case "years":
return differenceInYears__default["default"](value, _this.date(comparing));
return differenceInYears__default["default"](value, dateToCompare);
case "quarters":
return differenceInQuarters__default["default"](value, _this.date(comparing));
return differenceInQuarters__default["default"](value, dateToCompare);
case "months":
return differenceInMonths__default["default"](value, _this.date(comparing));
return differenceInMonths__default["default"](value, dateToCompare);
case "weeks":
return differenceInWeeks__default["default"](value, _this.date(comparing));
return differenceInWeeks__default["default"](value, dateToCompare);
case "days":
return differenceInDays__default["default"](value, _this.date(comparing));
return differenceInDays__default["default"](value, dateToCompare);
case "hours":
return differenceInHours__default["default"](value, _this.date(comparing));
return differenceInHours__default["default"](value, dateToCompare);
case "minutes":
return differenceInMinutes__default["default"](value, _this.date(comparing));
return differenceInMinutes__default["default"](value, dateToCompare);
case "seconds":
return differenceInSeconds__default["default"](value, _this.date(comparing));
return differenceInSeconds__default["default"](value, dateToCompare);
default: {
return differenceInMilliseconds__default["default"](value, _this.date(comparing));
return differenceInMilliseconds__default["default"](value, dateToCompare);
}
}
};
this.isAfter = function (value, comparing) {
this.isAfter = (value, comparing) => {
return isAfter__default["default"](value, comparing);
};
this.isBefore = function (value, comparing) {
this.isBefore = (value, comparing) => {
return isBefore__default["default"](value, comparing);
};
this.startOfDay = function (value) {
this.startOfDay = (value) => {
return startOfDay__default["default"](value);
};
this.endOfDay = function (value) {
this.endOfDay = (value) => {
return endOfDay__default["default"](value);
};
this.getHours = function (value) {
this.getHours = (value) => {
return getHours__default["default"](value);
};
this.setHours = function (value, count) {
this.setHours = (value, count) => {
return setHours__default["default"](value, count);
};
this.setMinutes = function (value, count) {
this.setMinutes = (value, count) => {
return setMinutes__default["default"](value, count);
};
this.getSeconds = function (value) {
this.getSeconds = (value) => {
return getSeconds__default["default"](value);
};
this.setSeconds = function (value, count) {
this.setSeconds = (value, count) => {
return setSeconds__default["default"](value, count);
};
this.isSameDay = function (value, comparing) {
this.isSameDay = (value, comparing) => {
return isSameDay__default["default"](value, comparing);
};
this.isSameMonth = function (value, comparing) {
this.isSameMonth = (value, comparing) => {
return isSameMonth__default["default"](value, comparing);
};
this.isSameYear = function (value, comparing) {
this.isSameYear = (value, comparing) => {
return isSameYear__default["default"](value, comparing);
};
this.isSameHour = function (value, comparing) {
this.isSameHour = (value, comparing) => {
return isSameHour__default["default"](value, comparing);
};
this.startOfYear = function (value) {
this.startOfYear = (value) => {
return startOfYear__default["default"](value);
};
this.endOfYear = function (value) {
this.endOfYear = (value) => {
return endOfYear__default["default"](value);
};
this.startOfMonth = function (value) {
this.startOfMonth = (value) => {
return startOfMonth__default["default"](value);
};
this.endOfMonth = function (value) {
this.endOfMonth = (value) => {
return endOfMonth__default["default"](value);
};
this.startOfWeek = function (value) {
return startOfWeek__default["default"](value, { locale: _this.locale });
this.startOfWeek = (value) => {
return startOfWeek__default["default"](value, { locale: this.locale });
};
this.endOfWeek = function (value) {
return endOfWeek__default["default"](value, { locale: _this.locale });
this.endOfWeek = (value) => {
return endOfWeek__default["default"](value, { locale: this.locale });
};
this.getYear = function (value) {
this.getYear = (value) => {
return getYear__default["default"](value);
};
this.setYear = function (value, count) {
this.setYear = (value, count) => {
return setYear__default["default"](value, count);
};
this.date = function (value) {
this.date = (value) => {
if (typeof value === "undefined") {

@@ -308,18 +310,18 @@ return new Date();

};
this.toJsDate = function (value) {
this.toJsDate = (value) => {
return value;
};
this.parse = function (value, formatString) {
this.parse = (value, formatString) => {
if (value === "") {
return null;
}
return dateFnsParse__default["default"](value, formatString, new Date(), { locale: _this.locale });
return dateFnsParse__default["default"](value, formatString, new Date(), { locale: this.locale });
};
this.format = function (date, formatKey) {
return _this.formatByString(date, _this.formats[formatKey]);
this.format = (date, formatKey) => {
return this.formatByString(date, this.formats[formatKey]);
};
this.formatByString = function (date, formatString) {
return format__default["default"](date, formatString, { locale: _this.locale });
this.formatByString = (date, formatString) => {
return format__default["default"](date, formatString, { locale: this.locale });
};
this.isEqual = function (date, comparing) {
this.isEqual = (date, comparing) => {
if (date === null && comparing === null) {

@@ -330,81 +332,80 @@ return true;

};
this.isNull = function (date) {
this.isNull = (date) => {
return date === null;
};
this.isAfterDay = function (date, value) {
this.isAfterDay = (date, value) => {
return isAfter__default["default"](date, endOfDay__default["default"](value));
};
this.isBeforeDay = function (date, value) {
this.isBeforeDay = (date, value) => {
return isBefore__default["default"](date, startOfDay__default["default"](value));
};
this.isBeforeYear = function (date, value) {
this.isBeforeYear = (date, value) => {
return isBefore__default["default"](date, startOfYear__default["default"](value));
};
this.isAfterYear = function (date, value) {
this.isAfterYear = (date, value) => {
return isAfter__default["default"](date, endOfYear__default["default"](value));
};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return isWithinInterval__default["default"](date, { start: start, end: end });
this.isWithinRange = (date, [start, end]) => {
return isWithinInterval__default["default"](date, { start, end });
};
this.formatNumber = function (numberToFormat) {
this.formatNumber = (numberToFormat) => {
return numberToFormat;
};
this.getMinutes = function (date) {
this.getMinutes = (date) => {
return getMinutes__default["default"](date);
};
this.getDate = function (date) {
this.getDate = (date) => {
return getDate__default["default"](date);
};
this.setDate = function (date, count) {
this.setDate = (date, count) => {
return setDate__default["default"](date, count);
};
this.getMonth = function (date) {
this.getMonth = (date) => {
return getMonth__default["default"](date);
};
this.getDaysInMonth = function (date) {
this.getDaysInMonth = (date) => {
return getDaysInMonth__default["default"](date);
};
this.setMonth = function (date, count) {
this.setMonth = (date, count) => {
return setMonth__default["default"](date, count);
};
this.getMeridiemText = function (ampm) {
this.getMeridiemText = (ampm) => {
return ampm === "am" ? "AM" : "PM";
};
this.getNextMonth = function (date) {
this.getNextMonth = (date) => {
return addMonths__default["default"](date, 1);
};
this.getPreviousMonth = function (date) {
this.getPreviousMonth = (date) => {
return addMonths__default["default"](date, -1);
};
this.getMonthArray = function (date) {
var firstMonth = startOfYear__default["default"](date);
var monthArray = [firstMonth];
this.getMonthArray = (date) => {
const firstMonth = startOfYear__default["default"](date);
const monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(_this.getNextMonth(prevMonth));
const prevMonth = monthArray[monthArray.length - 1];
monthArray.push(this.getNextMonth(prevMonth));
}
return monthArray;
};
this.mergeDateAndTime = function (date, time) {
return _this.setSeconds(_this.setMinutes(_this.setHours(date, _this.getHours(time)), _this.getMinutes(time)), _this.getSeconds(time));
this.mergeDateAndTime = (date, time) => {
return this.setSeconds(this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), this.getSeconds(time));
};
this.getWeekdays = function () {
var now = new Date();
this.getWeekdays = () => {
const now = new Date();
return eachDayOfInterval__default["default"]({
start: startOfWeek__default["default"](now, { locale: _this.locale }),
end: endOfWeek__default["default"](now, { locale: _this.locale }),
}).map(function (day) { return _this.formatByString(day, "EEEEEE"); });
start: startOfWeek__default["default"](now, { locale: this.locale }),
end: endOfWeek__default["default"](now, { locale: this.locale }),
}).map((day) => this.formatByString(day, "EEEEEE"));
};
this.getWeekArray = function (date) {
var start = startOfWeek__default["default"](startOfMonth__default["default"](date), { locale: _this.locale });
var end = endOfWeek__default["default"](endOfMonth__default["default"](date), { locale: _this.locale });
var count = 0;
var current = start;
var nestedWeeks = [];
var lastDay = null;
this.getWeekArray = (date) => {
const start = startOfWeek__default["default"](startOfMonth__default["default"](date), { locale: this.locale });
const end = endOfWeek__default["default"](endOfMonth__default["default"](date), { locale: this.locale });
let count = 0;
let current = start;
const nestedWeeks = [];
let lastDay = null;
while (isBefore__default["default"](current, end)) {
var weekNumber = Math.floor(count / 7);
const weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
var day = getDay__default["default"](current);
const day = getDay__default["default"](current);
if (lastDay !== day) {

@@ -419,7 +420,7 @@ lastDay = day;

};
this.getYearRange = function (start, end) {
var startDate = startOfYear__default["default"](start);
var endDate = endOfYear__default["default"](end);
var years = [];
var current = startDate;
this.getYearRange = (start, end) => {
const startDate = startOfYear__default["default"](start);
const endDate = endOfYear__default["default"](end);
const years = [];
let current = startDate;
while (isBefore__default["default"](current, endDate)) {

@@ -434,5 +435,10 @@ years.push(current);

}
return DateFnsUtils;
}());
isBeforeMonth(value, comparing) {
return isBefore__default["default"](value, startOfMonth__default["default"](comparing));
}
isAfterMonth(value, comparing) {
return isAfter__default["default"](value, startOfMonth__default["default"](comparing));
}
}
module.exports = DateFnsUtils;
{
"name": "@date-io/date-fns",
"version": "2.16.0",
"version": "2.17.0",
"description": "Abstraction over common javascript date management libraries",

@@ -41,3 +41,3 @@ "main": "build/index.js",

"dependencies": {
"@date-io/core": "^2.16.0"
"@date-io/core": "^2.17.0"
},

@@ -47,5 +47,5 @@ "devDependencies": {

"rollup": "^2.0.2",
"typescript": "^3.7.2"
"typescript": "^5.0.0"
},
"gitHead": "e9eddac85299013881e8bf005f5030fdf46d4756"
"gitHead": "e497a04c456f04211c8b0877d002c85e72ea98a2"
}

@@ -54,2 +54,3 @@ import addDays from "date-fns/addDays";

import isWithinInterval from "date-fns/isWithinInterval";
// @ts-ignore
import longFormatters from "date-fns/_lib/format/longFormatters";

@@ -107,3 +108,3 @@ import defaultLocale from "date-fns/locale/en-US";

if (this.locale) {
return /a/.test(this.locale.formatLong.time());
return /a/.test(this.locale.formatLong?.time());
}

@@ -119,15 +120,18 @@

const locale = this.locale || defaultLocale;
return format
.match(longFormatRegexp)
.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "p" || firstCharacter === "P") {
const longFormatter = longFormatters[firstCharacter];
return longFormatter(token, locale.formatLong, {});
}
return token;
})
.join("")
.replace(/(aaa|aa|a)/g, "(a|p)m")
.toLocaleLowerCase();
return (
format
.match(longFormatRegexp)
?.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "p" || firstCharacter === "P") {
const longFormatter = longFormatters[firstCharacter];
return longFormatter(token, locale.formatLong, {});
}
return token;
})
.join("")
.replace(/(aaa|aa|a)/g, "(a|p)m")
.toLocaleLowerCase() ?? format
);
};

@@ -180,21 +184,26 @@

public getDiff = (value: Date, comparing: Date | string, unit?: Unit) => {
// we output 0 if the compare date is string and parsing is not valid
const dateToCompare = this.date(comparing) ?? value;
if (!this.isValid(dateToCompare)) {
return 0;
}
switch (unit) {
case "years":
return differenceInYears(value, this.date(comparing));
return differenceInYears(value, dateToCompare);
case "quarters":
return differenceInQuarters(value, this.date(comparing));
return differenceInQuarters(value, dateToCompare);
case "months":
return differenceInMonths(value, this.date(comparing));
return differenceInMonths(value, dateToCompare);
case "weeks":
return differenceInWeeks(value, this.date(comparing));
return differenceInWeeks(value, dateToCompare);
case "days":
return differenceInDays(value, this.date(comparing));
return differenceInDays(value, dateToCompare);
case "hours":
return differenceInHours(value, this.date(comparing));
return differenceInHours(value, dateToCompare);
case "minutes":
return differenceInMinutes(value, this.date(comparing));
return differenceInMinutes(value, dateToCompare);
case "seconds":
return differenceInSeconds(value, this.date(comparing));
return differenceInSeconds(value, dateToCompare);
default: {
return differenceInMilliseconds(value, this.date(comparing));
return differenceInMilliseconds(value, dateToCompare);
}

@@ -344,2 +353,10 @@ }

public isBeforeMonth(value: Date, comparing: Date): boolean {
return isBefore(value, startOfMonth(comparing));
}
public isAfterMonth(value: Date, comparing: Date): boolean {
return isAfter(value, startOfMonth(comparing));
}
public isAfterYear = (date: Date, value: Date) => {

@@ -346,0 +363,0 @@ return isAfter(date, endOfYear(value));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc