New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@date-io/dayjs

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@date-io/dayjs - npm Package Compare versions

Comparing version 2.10.6 to 2.10.7

110

build/dayjs-utils.d.ts

@@ -18,58 +18,58 @@ import defaultDayjs from "dayjs";

constructor({ locale, formats, instance }?: Opts);
is12HourCycleInCurrentLocale(): boolean;
getCurrentLocaleCode(): string;
getFormatHelperText(format: string): string;
parse(value: any, format: any): defaultDayjs.Dayjs;
date(value?: any): defaultDayjs.Dayjs;
toJsDate(value: Dayjs): Date;
isValid(value: any): boolean;
isNull(date: Dayjs): boolean;
getDiff(date: Dayjs, comparing: Dayjs, units?: Unit): number;
isAfter(date: Dayjs, value: Dayjs): boolean;
isBefore(date: Dayjs, value: Dayjs): boolean;
isAfterDay(date: Dayjs, value: Dayjs): boolean;
isBeforeDay(date: Dayjs, value: Dayjs): boolean;
isBeforeYear(date: Dayjs, value: Dayjs): boolean;
isAfterYear(date: Dayjs, value: Dayjs): boolean;
startOfDay(date: Dayjs): defaultDayjs.Dayjs;
endOfDay(date: Dayjs): defaultDayjs.Dayjs;
format(date: Dayjs, formatKey: keyof DateIOFormats): string;
formatByString(date: Dayjs, formatString: string): string;
formatNumber(numberToFormat: string): string;
getHours(date: Dayjs): number;
addSeconds(date: Dayjs, count: number): defaultDayjs.Dayjs;
addMinutes(date: Dayjs, count: number): defaultDayjs.Dayjs;
addHours(date: Dayjs, count: number): defaultDayjs.Dayjs;
addDays(date: Dayjs, count: number): defaultDayjs.Dayjs;
addWeeks(date: Dayjs, count: number): defaultDayjs.Dayjs;
addMonths(date: Dayjs, count: number): defaultDayjs.Dayjs;
setMonth(date: Dayjs, count: number): defaultDayjs.Dayjs;
setHours(date: Dayjs, count: number): defaultDayjs.Dayjs;
getMinutes(date: Dayjs): number;
setMinutes(date: Dayjs, count: number): defaultDayjs.Dayjs;
getSeconds(date: Dayjs): number;
setSeconds(date: Dayjs, count: number): defaultDayjs.Dayjs;
getMonth(date: Dayjs): number;
getDaysInMonth(date: Dayjs): number;
isSameDay(date: Dayjs, comparing: Dayjs): boolean;
isSameMonth(date: Dayjs, comparing: Dayjs): boolean;
isSameYear(date: Dayjs, comparing: Dayjs): boolean;
isSameHour(date: Dayjs, comparing: Dayjs): boolean;
getMeridiemText(ampm: "am" | "pm"): "AM" | "PM";
startOfMonth(date: Dayjs): defaultDayjs.Dayjs;
endOfMonth(date: Dayjs): defaultDayjs.Dayjs;
startOfWeek(date: Dayjs): defaultDayjs.Dayjs;
endOfWeek(date: Dayjs): defaultDayjs.Dayjs;
getNextMonth(date: Dayjs): defaultDayjs.Dayjs;
getPreviousMonth(date: Dayjs): defaultDayjs.Dayjs;
getMonthArray(date: Dayjs): defaultDayjs.Dayjs[];
getYear(date: Dayjs): number;
setYear(date: Dayjs, year: number): defaultDayjs.Dayjs;
mergeDateAndTime(date: Dayjs, time: Dayjs): defaultDayjs.Dayjs;
getWeekdays(): string[];
isEqual(value: any, comparing: any): boolean;
getWeekArray(date: Dayjs): defaultDayjs.Dayjs[][];
getYearRange(start: Dayjs, end: Dayjs): defaultDayjs.Dayjs[];
isWithinRange(date: Dayjs, [start, end]: [Dayjs, Dayjs]): boolean;
is12HourCycleInCurrentLocale: () => boolean;
getCurrentLocaleCode: () => string;
getFormatHelperText: (format: string) => string;
parse: (value: any, format: any) => defaultDayjs.Dayjs;
date: (value?: any) => defaultDayjs.Dayjs;
toJsDate: (value: Dayjs) => Date;
isValid: (value: any) => boolean;
isNull: (date: Dayjs) => boolean;
getDiff: (date: Dayjs, comparing: Dayjs, units?: Unit) => number;
isAfter: (date: Dayjs, value: Dayjs) => boolean;
isBefore: (date: Dayjs, value: Dayjs) => boolean;
isAfterDay: (date: Dayjs, value: Dayjs) => boolean;
isBeforeDay: (date: Dayjs, value: Dayjs) => boolean;
isBeforeYear: (date: Dayjs, value: Dayjs) => boolean;
isAfterYear: (date: Dayjs, value: Dayjs) => boolean;
startOfDay: (date: Dayjs) => defaultDayjs.Dayjs;
endOfDay: (date: Dayjs) => defaultDayjs.Dayjs;
format: (date: Dayjs, formatKey: keyof DateIOFormats) => string;
formatByString: (date: Dayjs, formatString: string) => string;
formatNumber: (numberToFormat: string) => string;
getHours: (date: Dayjs) => number;
addSeconds: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
addMinutes: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
addHours: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
addDays: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
addWeeks: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
addMonths: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
setMonth: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
setHours: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
getMinutes: (date: Dayjs) => number;
setMinutes: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
getSeconds: (date: Dayjs) => number;
setSeconds: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
getMonth: (date: Dayjs) => number;
getDaysInMonth: (date: Dayjs) => number;
isSameDay: (date: Dayjs, comparing: Dayjs) => boolean;
isSameMonth: (date: Dayjs, comparing: Dayjs) => boolean;
isSameYear: (date: Dayjs, comparing: Dayjs) => boolean;
isSameHour: (date: Dayjs, comparing: Dayjs) => boolean;
getMeridiemText: (ampm: "am" | "pm") => "AM" | "PM";
startOfMonth: (date: Dayjs) => defaultDayjs.Dayjs;
endOfMonth: (date: Dayjs) => defaultDayjs.Dayjs;
startOfWeek: (date: Dayjs) => defaultDayjs.Dayjs;
endOfWeek: (date: Dayjs) => defaultDayjs.Dayjs;
getNextMonth: (date: Dayjs) => defaultDayjs.Dayjs;
getPreviousMonth: (date: Dayjs) => defaultDayjs.Dayjs;
getMonthArray: (date: Dayjs) => defaultDayjs.Dayjs[];
getYear: (date: Dayjs) => number;
setYear: (date: Dayjs, year: number) => defaultDayjs.Dayjs;
mergeDateAndTime: (date: Dayjs, time: Dayjs) => defaultDayjs.Dayjs;
getWeekdays: () => string[];
isEqual: (value: any, comparing: any) => boolean;
getWeekArray: (date: Dayjs) => defaultDayjs.Dayjs[][];
getYearRange: (start: Dayjs, end: Dayjs) => defaultDayjs.Dayjs[];
isWithinRange: (date: Dayjs, [start, end]: [Dayjs, Dayjs]) => boolean;
}
export {};

@@ -49,4 +49,230 @@ import defaultDayjs from 'dayjs';

function DayjsUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance;
this.lib = "dayjs";
this.is12HourCycleInCurrentLocale = function () {
var _a, _b;
/* istanbul ignore next */
return /A|a/.test((_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT);
};
this.getCurrentLocaleCode = function () {
return _this.locale || "en";
};
this.getFormatHelperText = function (format) {
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var _a, _b;
var firstCharacter = token[0];
if (firstCharacter === "L") {
/* istanbul ignore next */
return (_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token]) !== null && _b !== void 0 ? _b : token;
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
};
this.parse = function (value, format) {
if (value === "") {
return null;
}
return _this.dayjs(value, format, _this.locale);
};
this.date = function (value) {
if (value === null) {
return null;
}
return _this.dayjs(value);
};
this.toJsDate = function (value) {
return value.toDate();
};
this.isValid = function (value) {
return _this.dayjs(value).isValid();
};
this.isNull = function (date) {
return date === null;
};
this.getDiff = function (date, comparing, units) {
return date.diff(comparing, units);
};
this.isAfter = function (date, value) {
return date.isAfter(value);
};
this.isBefore = function (date, value) {
return date.isBefore(value);
};
this.isAfterDay = function (date, value) {
return date.isAfter(value, "day");
};
this.isBeforeDay = function (date, value) {
return date.isBefore(value, "day");
};
this.isBeforeYear = function (date, value) {
return date.isBefore(value, "year");
};
this.isAfterYear = function (date, value) {
return date.isAfter(value, "year");
};
this.startOfDay = function (date) {
return date.clone().startOf("day");
};
this.endOfDay = function (date) {
return date.clone().endOf("day");
};
this.format = function (date, formatKey) {
return _this.formatByString(date, _this.formats[formatKey]);
};
this.formatByString = function (date, formatString) {
return _this.dayjs(date).format(formatString);
};
this.formatNumber = function (numberToFormat) {
return numberToFormat;
};
this.getHours = function (date) {
return date.hour();
};
this.addSeconds = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "second")
: date.add(count, "second");
};
this.addMinutes = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "minute")
: date.add(count, "minute");
};
this.addHours = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "hour") : date.add(count, "hour");
};
this.addDays = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "day") : date.add(count, "day");
};
this.addWeeks = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "week") : date.add(count, "week");
};
this.addMonths = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "month") : date.add(count, "month");
};
this.setMonth = function (date, count) {
return date.set("month", count);
};
this.setHours = function (date, count) {
return date.set("hour", count);
};
this.getMinutes = function (date) {
return date.minute();
};
this.setMinutes = function (date, count) {
return date.clone().set("minute", count);
};
this.getSeconds = function (date) {
return date.second();
};
this.setSeconds = function (date, count) {
return date.clone().set("second", count);
};
this.getMonth = function (date) {
return date.month();
};
this.getDaysInMonth = function (date) {
return date.daysInMonth();
};
this.isSameDay = function (date, comparing) {
return date.isSame(comparing, "day");
};
this.isSameMonth = function (date, comparing) {
return date.isSame(comparing, "month");
};
this.isSameYear = function (date, comparing) {
return date.isSame(comparing, "year");
};
this.isSameHour = function (date, comparing) {
return date.isSame(comparing, "hour");
};
this.getMeridiemText = function (ampm) {
return ampm === "am" ? "AM" : "PM";
};
this.startOfMonth = function (date) {
return date.clone().startOf("month");
};
this.endOfMonth = function (date) {
return date.clone().endOf("month");
};
this.startOfWeek = function (date) {
return date.clone().startOf("week");
};
this.endOfWeek = function (date) {
return date.clone().endOf("week");
};
this.getNextMonth = function (date) {
return date.clone().add(1, "month");
};
this.getPreviousMonth = function (date) {
return date.clone().subtract(1, "month");
};
this.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(_this.getNextMonth(prevMonth));
}
return monthArray;
};
this.getYear = function (date) {
return date.year();
};
this.setYear = function (date, year) {
return date.clone().set("year", year);
};
this.mergeDateAndTime = function (date, time) {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
this.getWeekdays = function () {
var start = _this.dayjs().startOf("week");
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) {
return _this.formatByString(start.add(diff, "day"), "dd");
});
};
this.isEqual = function (value, comparing) {
if (value === null && comparing === null) {
return true;
}
return _this.dayjs(value).isSame(comparing);
};
this.getWeekArray = function (date) {
var start = _this.dayjs(date).clone().startOf("month").startOf("week");
var end = _this.dayjs(date).clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
nestedWeeks[weekNumber].push(current);
current = current.clone().add(1, "day");
count += 1;
}
return nestedWeeks;
};
this.getYearRange = function (start, end) {
var startDate = _this.dayjs(start).startOf("year");
var endDate = _this.dayjs(end).endOf("year");
var years = [];
var current = startDate;
while (current.isBefore(endDate)) {
years.push(current);
current = current.clone().add(1, "year");
}
return years;
};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return date.isBetween(start, end, null, "[]");
};
this.rawDayJsInstance = instance || defaultDayjs;

@@ -57,229 +283,2 @@ this.dayjs = withLocale(this.rawDayJsInstance, locale);

}
DayjsUtils.prototype.is12HourCycleInCurrentLocale = function () {
var _a, _b;
/* istanbul ignore next */
return /A|a/.test((_b = (_a = this.rawDayJsInstance.Ls[this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT);
};
DayjsUtils.prototype.getCurrentLocaleCode = function () {
return this.locale || "en";
};
DayjsUtils.prototype.getFormatHelperText = function (format) {
var _this = this;
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var _a, _b;
var firstCharacter = token[0];
if (firstCharacter === "L") {
/* istanbul ignore next */
return (_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token]) !== null && _b !== void 0 ? _b : token;
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
};
DayjsUtils.prototype.parse = function (value, format) {
if (value === "") {
return null;
}
return this.dayjs(value, format, this.locale);
};
DayjsUtils.prototype.date = function (value) {
if (value === null) {
return null;
}
return this.dayjs(value);
};
DayjsUtils.prototype.toJsDate = function (value) {
return value.toDate();
};
DayjsUtils.prototype.isValid = function (value) {
return this.dayjs(value).isValid();
};
DayjsUtils.prototype.isNull = function (date) {
return date === null;
};
DayjsUtils.prototype.getDiff = function (date, comparing, units) {
return date.diff(comparing, units);
};
DayjsUtils.prototype.isAfter = function (date, value) {
return date.isAfter(value);
};
DayjsUtils.prototype.isBefore = function (date, value) {
return date.isBefore(value);
};
DayjsUtils.prototype.isAfterDay = function (date, value) {
return date.isAfter(value, "day");
};
DayjsUtils.prototype.isBeforeDay = function (date, value) {
return date.isBefore(value, "day");
};
DayjsUtils.prototype.isBeforeYear = function (date, value) {
return date.isBefore(value, "year");
};
DayjsUtils.prototype.isAfterYear = function (date, value) {
return date.isAfter(value, "year");
};
DayjsUtils.prototype.startOfDay = function (date) {
return date.clone().startOf("day");
};
DayjsUtils.prototype.endOfDay = function (date) {
return date.clone().endOf("day");
};
DayjsUtils.prototype.format = function (date, formatKey) {
return this.formatByString(date, this.formats[formatKey]);
};
DayjsUtils.prototype.formatByString = function (date, formatString) {
return this.dayjs(date).format(formatString);
};
DayjsUtils.prototype.formatNumber = function (numberToFormat) {
return numberToFormat;
};
DayjsUtils.prototype.getHours = function (date) {
return date.hour();
};
DayjsUtils.prototype.addSeconds = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "second")
: date.add(count, "second");
};
DayjsUtils.prototype.addMinutes = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "minute")
: date.add(count, "minute");
};
DayjsUtils.prototype.addHours = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "hour") : date.add(count, "hour");
};
DayjsUtils.prototype.addDays = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "day") : date.add(count, "day");
};
DayjsUtils.prototype.addWeeks = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "week") : date.add(count, "week");
};
DayjsUtils.prototype.addMonths = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "month") : date.add(count, "month");
};
DayjsUtils.prototype.setMonth = function (date, count) {
return date.set("month", count);
};
DayjsUtils.prototype.setHours = function (date, count) {
return date.set("hour", count);
};
DayjsUtils.prototype.getMinutes = function (date) {
return date.minute();
};
DayjsUtils.prototype.setMinutes = function (date, count) {
return date.clone().set("minute", count);
};
DayjsUtils.prototype.getSeconds = function (date) {
return date.second();
};
DayjsUtils.prototype.setSeconds = function (date, count) {
return date.clone().set("second", count);
};
DayjsUtils.prototype.getMonth = function (date) {
return date.month();
};
DayjsUtils.prototype.getDaysInMonth = function (date) {
return date.daysInMonth();
};
DayjsUtils.prototype.isSameDay = function (date, comparing) {
return date.isSame(comparing, "day");
};
DayjsUtils.prototype.isSameMonth = function (date, comparing) {
return date.isSame(comparing, "month");
};
DayjsUtils.prototype.isSameYear = function (date, comparing) {
return date.isSame(comparing, "year");
};
DayjsUtils.prototype.isSameHour = function (date, comparing) {
return date.isSame(comparing, "hour");
};
DayjsUtils.prototype.getMeridiemText = function (ampm) {
return ampm === "am" ? "AM" : "PM";
};
DayjsUtils.prototype.startOfMonth = function (date) {
return date.clone().startOf("month");
};
DayjsUtils.prototype.endOfMonth = function (date) {
return date.clone().endOf("month");
};
DayjsUtils.prototype.startOfWeek = function (date) {
return date.clone().startOf("week");
};
DayjsUtils.prototype.endOfWeek = function (date) {
return date.clone().endOf("week");
};
DayjsUtils.prototype.getNextMonth = function (date) {
return date.clone().add(1, "month");
};
DayjsUtils.prototype.getPreviousMonth = function (date) {
return date.clone().subtract(1, "month");
};
DayjsUtils.prototype.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(this.getNextMonth(prevMonth));
}
return monthArray;
};
DayjsUtils.prototype.getYear = function (date) {
return date.year();
};
DayjsUtils.prototype.setYear = function (date, year) {
return date.clone().set("year", year);
};
DayjsUtils.prototype.mergeDateAndTime = function (date, time) {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
DayjsUtils.prototype.getWeekdays = function () {
var _this = this;
var start = this.dayjs().startOf("week");
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) {
return _this.formatByString(start.add(diff, "day"), "dd");
});
};
DayjsUtils.prototype.isEqual = function (value, comparing) {
if (value === null && comparing === null) {
return true;
}
return this.dayjs(value).isSame(comparing);
};
DayjsUtils.prototype.getWeekArray = function (date) {
var start = this.dayjs(date).clone().startOf("month").startOf("week");
var end = this.dayjs(date).clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
nestedWeeks[weekNumber].push(current);
current = current.clone().add(1, "day");
count += 1;
}
return nestedWeeks;
};
DayjsUtils.prototype.getYearRange = function (start, end) {
var startDate = this.dayjs(start).startOf("year");
var endDate = this.dayjs(end).endOf("year");
var years = [];
var current = startDate;
while (current.isBefore(endDate)) {
years.push(current);
current = current.clone().add(1, "year");
}
return years;
};
DayjsUtils.prototype.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return date.isBetween(start, end, null, "[]");
};
return DayjsUtils;

@@ -286,0 +285,0 @@ }());

@@ -58,4 +58,230 @@ 'use strict';

function DayjsUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance;
this.lib = "dayjs";
this.is12HourCycleInCurrentLocale = function () {
var _a, _b;
/* istanbul ignore next */
return /A|a/.test((_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT);
};
this.getCurrentLocaleCode = function () {
return _this.locale || "en";
};
this.getFormatHelperText = function (format) {
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var _a, _b;
var firstCharacter = token[0];
if (firstCharacter === "L") {
/* istanbul ignore next */
return (_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token]) !== null && _b !== void 0 ? _b : token;
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
};
this.parse = function (value, format) {
if (value === "") {
return null;
}
return _this.dayjs(value, format, _this.locale);
};
this.date = function (value) {
if (value === null) {
return null;
}
return _this.dayjs(value);
};
this.toJsDate = function (value) {
return value.toDate();
};
this.isValid = function (value) {
return _this.dayjs(value).isValid();
};
this.isNull = function (date) {
return date === null;
};
this.getDiff = function (date, comparing, units) {
return date.diff(comparing, units);
};
this.isAfter = function (date, value) {
return date.isAfter(value);
};
this.isBefore = function (date, value) {
return date.isBefore(value);
};
this.isAfterDay = function (date, value) {
return date.isAfter(value, "day");
};
this.isBeforeDay = function (date, value) {
return date.isBefore(value, "day");
};
this.isBeforeYear = function (date, value) {
return date.isBefore(value, "year");
};
this.isAfterYear = function (date, value) {
return date.isAfter(value, "year");
};
this.startOfDay = function (date) {
return date.clone().startOf("day");
};
this.endOfDay = function (date) {
return date.clone().endOf("day");
};
this.format = function (date, formatKey) {
return _this.formatByString(date, _this.formats[formatKey]);
};
this.formatByString = function (date, formatString) {
return _this.dayjs(date).format(formatString);
};
this.formatNumber = function (numberToFormat) {
return numberToFormat;
};
this.getHours = function (date) {
return date.hour();
};
this.addSeconds = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "second")
: date.add(count, "second");
};
this.addMinutes = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "minute")
: date.add(count, "minute");
};
this.addHours = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "hour") : date.add(count, "hour");
};
this.addDays = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "day") : date.add(count, "day");
};
this.addWeeks = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "week") : date.add(count, "week");
};
this.addMonths = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "month") : date.add(count, "month");
};
this.setMonth = function (date, count) {
return date.set("month", count);
};
this.setHours = function (date, count) {
return date.set("hour", count);
};
this.getMinutes = function (date) {
return date.minute();
};
this.setMinutes = function (date, count) {
return date.clone().set("minute", count);
};
this.getSeconds = function (date) {
return date.second();
};
this.setSeconds = function (date, count) {
return date.clone().set("second", count);
};
this.getMonth = function (date) {
return date.month();
};
this.getDaysInMonth = function (date) {
return date.daysInMonth();
};
this.isSameDay = function (date, comparing) {
return date.isSame(comparing, "day");
};
this.isSameMonth = function (date, comparing) {
return date.isSame(comparing, "month");
};
this.isSameYear = function (date, comparing) {
return date.isSame(comparing, "year");
};
this.isSameHour = function (date, comparing) {
return date.isSame(comparing, "hour");
};
this.getMeridiemText = function (ampm) {
return ampm === "am" ? "AM" : "PM";
};
this.startOfMonth = function (date) {
return date.clone().startOf("month");
};
this.endOfMonth = function (date) {
return date.clone().endOf("month");
};
this.startOfWeek = function (date) {
return date.clone().startOf("week");
};
this.endOfWeek = function (date) {
return date.clone().endOf("week");
};
this.getNextMonth = function (date) {
return date.clone().add(1, "month");
};
this.getPreviousMonth = function (date) {
return date.clone().subtract(1, "month");
};
this.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(_this.getNextMonth(prevMonth));
}
return monthArray;
};
this.getYear = function (date) {
return date.year();
};
this.setYear = function (date, year) {
return date.clone().set("year", year);
};
this.mergeDateAndTime = function (date, time) {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
this.getWeekdays = function () {
var start = _this.dayjs().startOf("week");
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) {
return _this.formatByString(start.add(diff, "day"), "dd");
});
};
this.isEqual = function (value, comparing) {
if (value === null && comparing === null) {
return true;
}
return _this.dayjs(value).isSame(comparing);
};
this.getWeekArray = function (date) {
var start = _this.dayjs(date).clone().startOf("month").startOf("week");
var end = _this.dayjs(date).clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
nestedWeeks[weekNumber].push(current);
current = current.clone().add(1, "day");
count += 1;
}
return nestedWeeks;
};
this.getYearRange = function (start, end) {
var startDate = _this.dayjs(start).startOf("year");
var endDate = _this.dayjs(end).endOf("year");
var years = [];
var current = startDate;
while (current.isBefore(endDate)) {
years.push(current);
current = current.clone().add(1, "year");
}
return years;
};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return date.isBetween(start, end, null, "[]");
};
this.rawDayJsInstance = instance || defaultDayjs__default['default'];

@@ -66,229 +292,2 @@ this.dayjs = withLocale(this.rawDayJsInstance, locale);

}
DayjsUtils.prototype.is12HourCycleInCurrentLocale = function () {
var _a, _b;
/* istanbul ignore next */
return /A|a/.test((_b = (_a = this.rawDayJsInstance.Ls[this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT);
};
DayjsUtils.prototype.getCurrentLocaleCode = function () {
return this.locale || "en";
};
DayjsUtils.prototype.getFormatHelperText = function (format) {
var _this = this;
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var _a, _b;
var firstCharacter = token[0];
if (firstCharacter === "L") {
/* istanbul ignore next */
return (_b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token]) !== null && _b !== void 0 ? _b : token;
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
};
DayjsUtils.prototype.parse = function (value, format) {
if (value === "") {
return null;
}
return this.dayjs(value, format, this.locale);
};
DayjsUtils.prototype.date = function (value) {
if (value === null) {
return null;
}
return this.dayjs(value);
};
DayjsUtils.prototype.toJsDate = function (value) {
return value.toDate();
};
DayjsUtils.prototype.isValid = function (value) {
return this.dayjs(value).isValid();
};
DayjsUtils.prototype.isNull = function (date) {
return date === null;
};
DayjsUtils.prototype.getDiff = function (date, comparing, units) {
return date.diff(comparing, units);
};
DayjsUtils.prototype.isAfter = function (date, value) {
return date.isAfter(value);
};
DayjsUtils.prototype.isBefore = function (date, value) {
return date.isBefore(value);
};
DayjsUtils.prototype.isAfterDay = function (date, value) {
return date.isAfter(value, "day");
};
DayjsUtils.prototype.isBeforeDay = function (date, value) {
return date.isBefore(value, "day");
};
DayjsUtils.prototype.isBeforeYear = function (date, value) {
return date.isBefore(value, "year");
};
DayjsUtils.prototype.isAfterYear = function (date, value) {
return date.isAfter(value, "year");
};
DayjsUtils.prototype.startOfDay = function (date) {
return date.clone().startOf("day");
};
DayjsUtils.prototype.endOfDay = function (date) {
return date.clone().endOf("day");
};
DayjsUtils.prototype.format = function (date, formatKey) {
return this.formatByString(date, this.formats[formatKey]);
};
DayjsUtils.prototype.formatByString = function (date, formatString) {
return this.dayjs(date).format(formatString);
};
DayjsUtils.prototype.formatNumber = function (numberToFormat) {
return numberToFormat;
};
DayjsUtils.prototype.getHours = function (date) {
return date.hour();
};
DayjsUtils.prototype.addSeconds = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "second")
: date.add(count, "second");
};
DayjsUtils.prototype.addMinutes = function (date, count) {
return count < 0
? date.subtract(Math.abs(count), "minute")
: date.add(count, "minute");
};
DayjsUtils.prototype.addHours = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "hour") : date.add(count, "hour");
};
DayjsUtils.prototype.addDays = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "day") : date.add(count, "day");
};
DayjsUtils.prototype.addWeeks = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "week") : date.add(count, "week");
};
DayjsUtils.prototype.addMonths = function (date, count) {
return count < 0 ? date.subtract(Math.abs(count), "month") : date.add(count, "month");
};
DayjsUtils.prototype.setMonth = function (date, count) {
return date.set("month", count);
};
DayjsUtils.prototype.setHours = function (date, count) {
return date.set("hour", count);
};
DayjsUtils.prototype.getMinutes = function (date) {
return date.minute();
};
DayjsUtils.prototype.setMinutes = function (date, count) {
return date.clone().set("minute", count);
};
DayjsUtils.prototype.getSeconds = function (date) {
return date.second();
};
DayjsUtils.prototype.setSeconds = function (date, count) {
return date.clone().set("second", count);
};
DayjsUtils.prototype.getMonth = function (date) {
return date.month();
};
DayjsUtils.prototype.getDaysInMonth = function (date) {
return date.daysInMonth();
};
DayjsUtils.prototype.isSameDay = function (date, comparing) {
return date.isSame(comparing, "day");
};
DayjsUtils.prototype.isSameMonth = function (date, comparing) {
return date.isSame(comparing, "month");
};
DayjsUtils.prototype.isSameYear = function (date, comparing) {
return date.isSame(comparing, "year");
};
DayjsUtils.prototype.isSameHour = function (date, comparing) {
return date.isSame(comparing, "hour");
};
DayjsUtils.prototype.getMeridiemText = function (ampm) {
return ampm === "am" ? "AM" : "PM";
};
DayjsUtils.prototype.startOfMonth = function (date) {
return date.clone().startOf("month");
};
DayjsUtils.prototype.endOfMonth = function (date) {
return date.clone().endOf("month");
};
DayjsUtils.prototype.startOfWeek = function (date) {
return date.clone().startOf("week");
};
DayjsUtils.prototype.endOfWeek = function (date) {
return date.clone().endOf("week");
};
DayjsUtils.prototype.getNextMonth = function (date) {
return date.clone().add(1, "month");
};
DayjsUtils.prototype.getPreviousMonth = function (date) {
return date.clone().subtract(1, "month");
};
DayjsUtils.prototype.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
while (monthArray.length < 12) {
var prevMonth = monthArray[monthArray.length - 1];
monthArray.push(this.getNextMonth(prevMonth));
}
return monthArray;
};
DayjsUtils.prototype.getYear = function (date) {
return date.year();
};
DayjsUtils.prototype.setYear = function (date, year) {
return date.clone().set("year", year);
};
DayjsUtils.prototype.mergeDateAndTime = function (date, time) {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
DayjsUtils.prototype.getWeekdays = function () {
var _this = this;
var start = this.dayjs().startOf("week");
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) {
return _this.formatByString(start.add(diff, "day"), "dd");
});
};
DayjsUtils.prototype.isEqual = function (value, comparing) {
if (value === null && comparing === null) {
return true;
}
return this.dayjs(value).isSame(comparing);
};
DayjsUtils.prototype.getWeekArray = function (date) {
var start = this.dayjs(date).clone().startOf("month").startOf("week");
var end = this.dayjs(date).clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
nestedWeeks[weekNumber].push(current);
current = current.clone().add(1, "day");
count += 1;
}
return nestedWeeks;
};
DayjsUtils.prototype.getYearRange = function (start, end) {
var startDate = this.dayjs(start).startOf("year");
var endDate = this.dayjs(end).endOf("year");
var years = [];
var current = startDate;
while (current.isBefore(endDate)) {
years.push(current);
current = current.clone().add(1, "year");
}
return years;
};
DayjsUtils.prototype.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
return date.isBetween(start, end, null, "[]");
};
return DayjsUtils;

@@ -295,0 +294,0 @@ }());

{
"name": "@date-io/dayjs",
"version": "2.10.6",
"version": "2.10.7",
"description": "Abstraction over common javascript date management libraries",

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

"dependencies": {
"@date-io/core": "^2.10.6"
"@date-io/core": "^2.10.7"
},

@@ -45,3 +45,3 @@ "devDependencies": {

"license": "MIT",
"gitHead": "3082a238a35ec86f0ba6a2fd410a2d69a88e48d3"
"gitHead": "9c5e30787db67c9a9729c3cf26f584499366270e"
}

@@ -77,12 +77,12 @@ import defaultDayjs, { QUnitType } from "dayjs";

public is12HourCycleInCurrentLocale() {
public is12HourCycleInCurrentLocale = () => {
/* istanbul ignore next */
return /A|a/.test(this.rawDayJsInstance.Ls[this.locale || "en"]?.formats?.LT);
}
};
public getCurrentLocaleCode() {
public getCurrentLocaleCode = () => {
return this.locale || "en";
}
};
public getFormatHelperText(format: string) {
public getFormatHelperText = (format: string) => {
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js

@@ -103,5 +103,5 @@ var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;

.toLocaleLowerCase();
}
};
public parse(value: any, format: any) {
public parse = (value: any, format: any) => {
if (value === "") {

@@ -112,5 +112,5 @@ return null;

return this.dayjs(value, format, this.locale);
}
};
public date(value?: any) {
public date = (value?: any) => {
if (value === null) {

@@ -121,173 +121,173 @@ return null;

return this.dayjs(value);
}
};
public toJsDate(value: Dayjs) {
public toJsDate = (value: Dayjs) => {
return value.toDate();
}
};
public isValid(value: any) {
public isValid = (value: any) => {
return this.dayjs(value).isValid();
}
};
public isNull(date: Dayjs) {
public isNull = (date: Dayjs) => {
return date === null;
}
};
public getDiff(date: Dayjs, comparing: Dayjs, units?: Unit) {
public getDiff = (date: Dayjs, comparing: Dayjs, units?: Unit) => {
return date.diff(comparing, units as QUnitType);
}
};
public isAfter(date: Dayjs, value: Dayjs) {
public isAfter = (date: Dayjs, value: Dayjs) => {
return date.isAfter(value);
}
};
public isBefore(date: Dayjs, value: Dayjs) {
public isBefore = (date: Dayjs, value: Dayjs) => {
return date.isBefore(value);
}
};
public isAfterDay(date: Dayjs, value: Dayjs) {
public isAfterDay = (date: Dayjs, value: Dayjs) => {
return date.isAfter(value, "day");
}
};
public isBeforeDay(date: Dayjs, value: Dayjs) {
public isBeforeDay = (date: Dayjs, value: Dayjs) => {
return date.isBefore(value, "day");
}
};
public isBeforeYear(date: Dayjs, value: Dayjs) {
public isBeforeYear = (date: Dayjs, value: Dayjs) => {
return date.isBefore(value, "year");
}
};
public isAfterYear(date: Dayjs, value: Dayjs) {
public isAfterYear = (date: Dayjs, value: Dayjs) => {
return date.isAfter(value, "year");
}
};
public startOfDay(date: Dayjs) {
public startOfDay = (date: Dayjs) => {
return date.clone().startOf("day");
}
};
public endOfDay(date: Dayjs) {
public endOfDay = (date: Dayjs) => {
return date.clone().endOf("day");
}
};
public format(date: Dayjs, formatKey: keyof DateIOFormats) {
public format = (date: Dayjs, formatKey: keyof DateIOFormats) => {
return this.formatByString(date, this.formats[formatKey]);
}
};
public formatByString(date: Dayjs, formatString: string) {
public formatByString = (date: Dayjs, formatString: string) => {
return this.dayjs(date).format(formatString);
}
};
public formatNumber(numberToFormat: string) {
public formatNumber = (numberToFormat: string) => {
return numberToFormat;
}
};
public getHours(date: Dayjs) {
public getHours = (date: Dayjs) => {
return date.hour();
}
};
public addSeconds(date: Dayjs, count: number) {
public addSeconds = (date: Dayjs, count: number) => {
return count < 0
? date.subtract(Math.abs(count), "second")
: date.add(count, "second");
}
};
public addMinutes(date: Dayjs, count: number) {
public addMinutes = (date: Dayjs, count: number) => {
return count < 0
? date.subtract(Math.abs(count), "minute")
: date.add(count, "minute");
}
};
public addHours(date: Dayjs, count: number) {
public addHours = (date: Dayjs, count: number) => {
return count < 0 ? date.subtract(Math.abs(count), "hour") : date.add(count, "hour");
}
};
public addDays(date: Dayjs, count: number) {
public addDays = (date: Dayjs, count: number) => {
return count < 0 ? date.subtract(Math.abs(count), "day") : date.add(count, "day");
}
};
public addWeeks(date: Dayjs, count: number) {
public addWeeks = (date: Dayjs, count: number) => {
return count < 0 ? date.subtract(Math.abs(count), "week") : date.add(count, "week");
}
};
public addMonths(date: Dayjs, count: number) {
public addMonths = (date: Dayjs, count: number) => {
return count < 0 ? date.subtract(Math.abs(count), "month") : date.add(count, "month");
}
};
public setMonth(date: Dayjs, count: number) {
public setMonth = (date: Dayjs, count: number) => {
return date.set("month", count);
}
};
public setHours(date: Dayjs, count: number) {
public setHours = (date: Dayjs, count: number) => {
return date.set("hour", count);
}
};
public getMinutes(date: Dayjs) {
public getMinutes = (date: Dayjs) => {
return date.minute();
}
};
public setMinutes(date: Dayjs, count: number) {
public setMinutes = (date: Dayjs, count: number) => {
return date.clone().set("minute", count);
}
};
public getSeconds(date: Dayjs) {
public getSeconds = (date: Dayjs) => {
return date.second();
}
};
public setSeconds(date: Dayjs, count: number) {
public setSeconds = (date: Dayjs, count: number) => {
return date.clone().set("second", count);
}
};
public getMonth(date: Dayjs) {
public getMonth = (date: Dayjs) => {
return date.month();
}
};
public getDaysInMonth(date: Dayjs) {
public getDaysInMonth = (date: Dayjs) => {
return date.daysInMonth();
}
};
public isSameDay(date: Dayjs, comparing: Dayjs) {
public isSameDay = (date: Dayjs, comparing: Dayjs) => {
return date.isSame(comparing, "day");
}
};
public isSameMonth(date: Dayjs, comparing: Dayjs) {
public isSameMonth = (date: Dayjs, comparing: Dayjs) => {
return date.isSame(comparing, "month");
}
};
public isSameYear(date: Dayjs, comparing: Dayjs) {
public isSameYear = (date: Dayjs, comparing: Dayjs) => {
return date.isSame(comparing, "year");
}
};
public isSameHour(date: Dayjs, comparing: Dayjs) {
public isSameHour = (date: Dayjs, comparing: Dayjs) => {
return date.isSame(comparing, "hour");
}
};
public getMeridiemText(ampm: "am" | "pm") {
public getMeridiemText = (ampm: "am" | "pm") => {
return ampm === "am" ? "AM" : "PM";
}
};
public startOfMonth(date: Dayjs) {
public startOfMonth = (date: Dayjs) => {
return date.clone().startOf("month");
}
};
public endOfMonth(date: Dayjs) {
public endOfMonth = (date: Dayjs) => {
return date.clone().endOf("month");
}
};
public startOfWeek(date: Dayjs) {
public startOfWeek = (date: Dayjs) => {
return date.clone().startOf("week");
}
};
public endOfWeek(date: Dayjs) {
public endOfWeek = (date: Dayjs) => {
return date.clone().endOf("week");
}
};
public getNextMonth(date: Dayjs) {
public getNextMonth = (date: Dayjs) => {
return date.clone().add(1, "month");
}
};
public getPreviousMonth(date: Dayjs) {
public getPreviousMonth = (date: Dayjs) => {
return date.clone().subtract(1, "month");
}
};
public getMonthArray(date: Dayjs) {
public getMonthArray = (date: Dayjs) => {
const firstMonth = date.clone().startOf("year");

@@ -302,17 +302,17 @@ const monthArray = [firstMonth];

return monthArray;
}
};
public getYear(date: Dayjs) {
public getYear = (date: Dayjs) => {
return date.year();
}
};
public setYear(date: Dayjs, year: number) {
public setYear = (date: Dayjs, year: number) => {
return date.clone().set("year", year);
}
};
public mergeDateAndTime(date: Dayjs, time: Dayjs) {
public mergeDateAndTime = (date: Dayjs, time: Dayjs) => {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
}
};
public getWeekdays() {
public getWeekdays = () => {
const start = this.dayjs().startOf("week");

@@ -322,5 +322,5 @@ return [0, 1, 2, 3, 4, 5, 6].map((diff) =>

);
}
};
public isEqual(value: any, comparing: any) {
public isEqual = (value: any, comparing: any) => {
if (value === null && comparing === null) {

@@ -331,5 +331,5 @@ return true;

return this.dayjs(value).isSame(comparing);
}
};
public getWeekArray(date: Dayjs) {
public getWeekArray = (date: Dayjs) => {
const start = this.dayjs(date).clone().startOf("month").startOf("week");

@@ -352,5 +352,5 @@ const end = this.dayjs(date).clone().endOf("month").endOf("week");

return nestedWeeks;
}
};
public getYearRange(start: Dayjs, end: Dayjs) {
public getYearRange = (start: Dayjs, end: Dayjs) => {
const startDate = this.dayjs(start).startOf("year");

@@ -367,7 +367,7 @@ const endDate = this.dayjs(end).endOf("year");

return years;
}
};
public isWithinRange(date: Dayjs, [start, end]: [Dayjs, Dayjs]) {
public isWithinRange = (date: Dayjs, [start, end]: [Dayjs, Dayjs]) => {
return date.isBetween(start, end, null, "[]");
}
};
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc