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

@date-io/moment

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@date-io/moment - npm Package Compare versions

Comparing version 2.16.1 to 2.17.0

230

build/index.esm.js
import defaultMoment from 'moment';
var defaultFormats = {
const defaultFormats = {
normalDateWithWeekday: "ddd, MMM D",

@@ -32,105 +32,113 @@ normalDate: "D MMMM",

};
var MomentUtils = /** @class */ (function () {
function MomentUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance;
class MomentUtils {
constructor({ locale, formats, instance } = {}) {
this.lib = "moment";
this.is12HourCycleInCurrentLocale = function () {
return /A|a/.test(_this.moment.localeData(_this.getCurrentLocaleCode()).longDateFormat("LT"));
this.is12HourCycleInCurrentLocale = () => {
return /A|a/.test(this.moment.localeData(this.getCurrentLocaleCode()).longDateFormat("LT"));
};
this.getFormatHelperText = function (format) {
this.getFormatHelperText = (format) => {
var _a, _b;
// @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var firstCharacter = token[0];
const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
return ((_b = (_a = format
.match(localFormattingTokens)) === null || _a === void 0 ? void 0 : _a.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "L" || firstCharacter === ";") {
return _this.moment
.localeData(_this.getCurrentLocaleCode())
return this.moment
.localeData(this.getCurrentLocaleCode())
.longDateFormat(token);
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
}).join("").replace(/a/gi, "(a|p)m").toLocaleLowerCase()) !== null && _b !== void 0 ? _b : format);
};
this.getCurrentLocaleCode = function () {
return _this.locale || _this.moment.locale();
this.getCurrentLocaleCode = () => {
return this.locale || this.moment.locale();
};
this.parseISO = function (isoString) {
return _this.moment(isoString, true);
this.parseISO = (isoString) => {
return this.moment(isoString, true);
};
this.toISO = function (value) {
this.toISO = (value) => {
return value.toISOString();
};
this.parse = function (value, format) {
this.parse = (value, format) => {
if (value === "") {
return null;
}
if (_this.locale) {
return _this.moment(value, format, _this.locale, true);
if (this.locale) {
return this.moment(value, format, this.locale, true);
}
return _this.moment(value, format, true);
return this.moment(value, format, true);
};
this.date = function (value) {
this.date = (value) => {
if (value === null) {
return null;
}
var moment = _this.moment(value);
moment.locale(_this.locale);
const moment = this.moment(value);
if (this.locale) {
moment.locale(this.locale);
}
return moment;
};
this.toJsDate = function (value) {
this.toJsDate = (value) => {
return value.toDate();
};
this.isValid = function (value) {
return _this.moment(value).isValid();
this.isValid = (value) => {
return this.moment(value).isValid();
};
this.isNull = function (date) {
this.isNull = (date) => {
return date === null;
};
this.getDiff = function (date, comparing, unit) {
this.getDiff = (date, comparing, unit) => {
if (!this.moment(comparing).isValid()) {
return 0;
}
return date.diff(comparing, unit);
};
this.isAfter = function (date, value) {
this.isAfter = (date, value) => {
return date.isAfter(value);
};
this.isBefore = function (date, value) {
this.isBefore = (date, value) => {
return date.isBefore(value);
};
this.isAfterDay = function (date, value) {
this.isAfterDay = (date, value) => {
return date.isAfter(value, "day");
};
this.isBeforeDay = function (date, value) {
this.isBeforeDay = (date, value) => {
return date.isBefore(value, "day");
};
this.isBeforeYear = function (date, value) {
this.isBeforeMonth = (date, value) => {
return date.isBefore(value, "month");
};
this.isAfterMonth = (date, value) => {
return date.isAfter(value, "month");
};
this.isBeforeYear = (date, value) => {
return date.isBefore(value, "year");
};
this.isAfterYear = function (date, value) {
this.isAfterYear = (date, value) => {
return date.isAfter(value, "year");
};
this.startOfDay = function (date) {
this.startOfDay = (date) => {
return date.clone().startOf("day");
};
this.endOfDay = function (date) {
this.endOfDay = (date) => {
return date.clone().endOf("day");
};
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) {
var clonedDate = date.clone();
clonedDate.locale(_this.locale);
this.formatByString = (date, formatString) => {
const clonedDate = date.clone();
if (this.locale) {
clonedDate.locale(this.locale);
}
return clonedDate.format(formatString);
};
this.formatNumber = function (numberToFormat) {
this.formatNumber = (numberToFormat) => {
return numberToFormat;
};
this.getHours = function (date) {
this.getHours = (date) => {
return date.get("hours");
};
this.addSeconds = function (date, count) {
this.addSeconds = (date, count) => {
return count < 0

@@ -140,3 +148,3 @@ ? date.clone().subtract(Math.abs(count), "seconds")

};
this.addMinutes = function (date, count) {
this.addMinutes = (date, count) => {
return count < 0

@@ -146,3 +154,3 @@ ? date.clone().subtract(Math.abs(count), "minutes")

};
this.addHours = function (date, count) {
this.addHours = (date, count) => {
return count < 0

@@ -152,3 +160,3 @@ ? date.clone().subtract(Math.abs(count), "hours")

};
this.addDays = function (date, count) {
this.addDays = (date, count) => {
return count < 0

@@ -158,3 +166,3 @@ ? date.clone().subtract(Math.abs(count), "days")

};
this.addWeeks = function (date, count) {
this.addWeeks = (date, count) => {
return count < 0

@@ -164,3 +172,3 @@ ? date.clone().subtract(Math.abs(count), "weeks")

};
this.addMonths = function (date, count) {
this.addMonths = (date, count) => {
return count < 0

@@ -170,3 +178,3 @@ ? date.clone().subtract(Math.abs(count), "months")

};
this.addYears = function (date, count) {
this.addYears = (date, count) => {
return count < 0

@@ -176,43 +184,43 @@ ? date.clone().subtract(Math.abs(count), "years")

};
this.setHours = function (date, count) {
this.setHours = (date, count) => {
return date.clone().hours(count);
};
this.getMinutes = function (date) {
this.getMinutes = (date) => {
return date.get("minutes");
};
this.setMinutes = function (date, count) {
this.setMinutes = (date, count) => {
return date.clone().minutes(count);
};
this.getSeconds = function (date) {
this.getSeconds = (date) => {
return date.get("seconds");
};
this.setSeconds = function (date, count) {
this.setSeconds = (date, count) => {
return date.clone().seconds(count);
};
this.getMonth = function (date) {
this.getMonth = (date) => {
return date.get("month");
};
this.getDaysInMonth = function (date) {
this.getDaysInMonth = (date) => {
return date.daysInMonth();
};
this.isSameDay = function (date, comparing) {
this.isSameDay = (date, comparing) => {
return date.isSame(comparing, "day");
};
this.isSameMonth = function (date, comparing) {
this.isSameMonth = (date, comparing) => {
return date.isSame(comparing, "month");
};
this.isSameYear = function (date, comparing) {
this.isSameYear = (date, comparing) => {
return date.isSame(comparing, "year");
};
this.isSameHour = function (date, comparing) {
this.isSameHour = (date, comparing) => {
return date.isSame(comparing, "hour");
};
this.setMonth = function (date, count) {
this.setMonth = (date, count) => {
return date.clone().month(count);
};
this.getMeridiemText = function (ampm) {
if (_this.is12HourCycleInCurrentLocale()) {
this.getMeridiemText = (ampm) => {
if (this.is12HourCycleInCurrentLocale()) {
// AM/PM translation only possible in those who have 12 hour cycle in locale.
return _this.moment
.localeData(_this.getCurrentLocaleCode())
return this.moment
.localeData(this.getCurrentLocaleCode())
.meridiem(ampm === "am" ? 0 : 13, 0, false);

@@ -222,67 +230,67 @@ }

};
this.startOfYear = function (date) {
this.startOfYear = (date) => {
return date.clone().startOf("year");
};
this.endOfYear = function (date) {
this.endOfYear = (date) => {
return date.clone().endOf("year");
};
this.startOfMonth = function (date) {
this.startOfMonth = (date) => {
return date.clone().startOf("month");
};
this.endOfMonth = function (date) {
this.endOfMonth = (date) => {
return date.clone().endOf("month");
};
this.startOfWeek = function (date) {
this.startOfWeek = (date) => {
return date.clone().startOf("week");
};
this.endOfWeek = function (date) {
this.endOfWeek = (date) => {
return date.clone().endOf("week");
};
this.getNextMonth = function (date) {
this.getNextMonth = (date) => {
return date.clone().add(1, "month");
};
this.getPreviousMonth = function (date) {
this.getPreviousMonth = (date) => {
return date.clone().subtract(1, "month");
};
this.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
this.getMonthArray = (date) => {
const firstMonth = date.clone().startOf("year");
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.getYear = function (date) {
this.getYear = (date) => {
return date.get("year");
};
this.setYear = function (date, year) {
this.setYear = (date, year) => {
return date.clone().set("year", year);
};
this.getDate = function (date) {
this.getDate = (date) => {
return date.get("date");
};
this.setDate = function (date, year) {
this.setDate = (date, year) => {
return date.clone().set("date", year);
};
this.mergeDateAndTime = function (date, time) {
this.mergeDateAndTime = (date, time) => {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
this.getWeekdays = function () {
return _this.moment.weekdaysShort(true);
this.getWeekdays = () => {
return this.moment.weekdaysShort(true);
};
this.isEqual = function (value, comparing) {
this.isEqual = (value, comparing) => {
if (value === null && comparing === null) {
return true;
}
return _this.moment(value).isSame(comparing);
return this.moment(value).isSame(comparing);
};
this.getWeekArray = function (date) {
var start = date.clone().startOf("month").startOf("week");
var end = date.clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
this.getWeekArray = (date) => {
const start = date.clone().startOf("month").startOf("week");
const end = date.clone().endOf("month").endOf("week");
let count = 0;
let current = start;
const nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
const weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];

@@ -295,7 +303,7 @@ nestedWeeks[weekNumber].push(current);

};
this.getYearRange = function (start, end) {
var startDate = _this.moment(start).startOf("year");
var endDate = _this.moment(end).endOf("year");
var years = [];
var current = startDate;
this.getYearRange = (start, end) => {
const startDate = this.moment(start).startOf("year");
const endDate = this.moment(end).endOf("year");
const years = [];
let current = startDate;
while (current.isBefore(endDate)) {

@@ -307,4 +315,3 @@ years.push(current);

};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
this.isWithinRange = (date, [start, end]) => {
return date.isBetween(start, end, null, "[]");

@@ -316,5 +323,4 @@ };

}
return MomentUtils;
}());
}
export { MomentUtils as default };

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

var defaultFormats = {
const defaultFormats = {
normalDateWithWeekday: "ddd, MMM D",

@@ -39,105 +39,113 @@ normalDate: "D MMMM",

};
var MomentUtils = /** @class */ (function () {
function MomentUtils(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance;
class MomentUtils {
constructor({ locale, formats, instance } = {}) {
this.lib = "moment";
this.is12HourCycleInCurrentLocale = function () {
return /A|a/.test(_this.moment.localeData(_this.getCurrentLocaleCode()).longDateFormat("LT"));
this.is12HourCycleInCurrentLocale = () => {
return /A|a/.test(this.moment.localeData(this.getCurrentLocaleCode()).longDateFormat("LT"));
};
this.getFormatHelperText = function (format) {
this.getFormatHelperText = (format) => {
var _a, _b;
// @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
return format
.match(localFormattingTokens)
.map(function (token) {
var firstCharacter = token[0];
const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
return ((_b = (_a = format
.match(localFormattingTokens)) === null || _a === void 0 ? void 0 : _a.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "L" || firstCharacter === ";") {
return _this.moment
.localeData(_this.getCurrentLocaleCode())
return this.moment
.localeData(this.getCurrentLocaleCode())
.longDateFormat(token);
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
}).join("").replace(/a/gi, "(a|p)m").toLocaleLowerCase()) !== null && _b !== void 0 ? _b : format);
};
this.getCurrentLocaleCode = function () {
return _this.locale || _this.moment.locale();
this.getCurrentLocaleCode = () => {
return this.locale || this.moment.locale();
};
this.parseISO = function (isoString) {
return _this.moment(isoString, true);
this.parseISO = (isoString) => {
return this.moment(isoString, true);
};
this.toISO = function (value) {
this.toISO = (value) => {
return value.toISOString();
};
this.parse = function (value, format) {
this.parse = (value, format) => {
if (value === "") {
return null;
}
if (_this.locale) {
return _this.moment(value, format, _this.locale, true);
if (this.locale) {
return this.moment(value, format, this.locale, true);
}
return _this.moment(value, format, true);
return this.moment(value, format, true);
};
this.date = function (value) {
this.date = (value) => {
if (value === null) {
return null;
}
var moment = _this.moment(value);
moment.locale(_this.locale);
const moment = this.moment(value);
if (this.locale) {
moment.locale(this.locale);
}
return moment;
};
this.toJsDate = function (value) {
this.toJsDate = (value) => {
return value.toDate();
};
this.isValid = function (value) {
return _this.moment(value).isValid();
this.isValid = (value) => {
return this.moment(value).isValid();
};
this.isNull = function (date) {
this.isNull = (date) => {
return date === null;
};
this.getDiff = function (date, comparing, unit) {
this.getDiff = (date, comparing, unit) => {
if (!this.moment(comparing).isValid()) {
return 0;
}
return date.diff(comparing, unit);
};
this.isAfter = function (date, value) {
this.isAfter = (date, value) => {
return date.isAfter(value);
};
this.isBefore = function (date, value) {
this.isBefore = (date, value) => {
return date.isBefore(value);
};
this.isAfterDay = function (date, value) {
this.isAfterDay = (date, value) => {
return date.isAfter(value, "day");
};
this.isBeforeDay = function (date, value) {
this.isBeforeDay = (date, value) => {
return date.isBefore(value, "day");
};
this.isBeforeYear = function (date, value) {
this.isBeforeMonth = (date, value) => {
return date.isBefore(value, "month");
};
this.isAfterMonth = (date, value) => {
return date.isAfter(value, "month");
};
this.isBeforeYear = (date, value) => {
return date.isBefore(value, "year");
};
this.isAfterYear = function (date, value) {
this.isAfterYear = (date, value) => {
return date.isAfter(value, "year");
};
this.startOfDay = function (date) {
this.startOfDay = (date) => {
return date.clone().startOf("day");
};
this.endOfDay = function (date) {
this.endOfDay = (date) => {
return date.clone().endOf("day");
};
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) {
var clonedDate = date.clone();
clonedDate.locale(_this.locale);
this.formatByString = (date, formatString) => {
const clonedDate = date.clone();
if (this.locale) {
clonedDate.locale(this.locale);
}
return clonedDate.format(formatString);
};
this.formatNumber = function (numberToFormat) {
this.formatNumber = (numberToFormat) => {
return numberToFormat;
};
this.getHours = function (date) {
this.getHours = (date) => {
return date.get("hours");
};
this.addSeconds = function (date, count) {
this.addSeconds = (date, count) => {
return count < 0

@@ -147,3 +155,3 @@ ? date.clone().subtract(Math.abs(count), "seconds")

};
this.addMinutes = function (date, count) {
this.addMinutes = (date, count) => {
return count < 0

@@ -153,3 +161,3 @@ ? date.clone().subtract(Math.abs(count), "minutes")

};
this.addHours = function (date, count) {
this.addHours = (date, count) => {
return count < 0

@@ -159,3 +167,3 @@ ? date.clone().subtract(Math.abs(count), "hours")

};
this.addDays = function (date, count) {
this.addDays = (date, count) => {
return count < 0

@@ -165,3 +173,3 @@ ? date.clone().subtract(Math.abs(count), "days")

};
this.addWeeks = function (date, count) {
this.addWeeks = (date, count) => {
return count < 0

@@ -171,3 +179,3 @@ ? date.clone().subtract(Math.abs(count), "weeks")

};
this.addMonths = function (date, count) {
this.addMonths = (date, count) => {
return count < 0

@@ -177,3 +185,3 @@ ? date.clone().subtract(Math.abs(count), "months")

};
this.addYears = function (date, count) {
this.addYears = (date, count) => {
return count < 0

@@ -183,43 +191,43 @@ ? date.clone().subtract(Math.abs(count), "years")

};
this.setHours = function (date, count) {
this.setHours = (date, count) => {
return date.clone().hours(count);
};
this.getMinutes = function (date) {
this.getMinutes = (date) => {
return date.get("minutes");
};
this.setMinutes = function (date, count) {
this.setMinutes = (date, count) => {
return date.clone().minutes(count);
};
this.getSeconds = function (date) {
this.getSeconds = (date) => {
return date.get("seconds");
};
this.setSeconds = function (date, count) {
this.setSeconds = (date, count) => {
return date.clone().seconds(count);
};
this.getMonth = function (date) {
this.getMonth = (date) => {
return date.get("month");
};
this.getDaysInMonth = function (date) {
this.getDaysInMonth = (date) => {
return date.daysInMonth();
};
this.isSameDay = function (date, comparing) {
this.isSameDay = (date, comparing) => {
return date.isSame(comparing, "day");
};
this.isSameMonth = function (date, comparing) {
this.isSameMonth = (date, comparing) => {
return date.isSame(comparing, "month");
};
this.isSameYear = function (date, comparing) {
this.isSameYear = (date, comparing) => {
return date.isSame(comparing, "year");
};
this.isSameHour = function (date, comparing) {
this.isSameHour = (date, comparing) => {
return date.isSame(comparing, "hour");
};
this.setMonth = function (date, count) {
this.setMonth = (date, count) => {
return date.clone().month(count);
};
this.getMeridiemText = function (ampm) {
if (_this.is12HourCycleInCurrentLocale()) {
this.getMeridiemText = (ampm) => {
if (this.is12HourCycleInCurrentLocale()) {
// AM/PM translation only possible in those who have 12 hour cycle in locale.
return _this.moment
.localeData(_this.getCurrentLocaleCode())
return this.moment
.localeData(this.getCurrentLocaleCode())
.meridiem(ampm === "am" ? 0 : 13, 0, false);

@@ -229,67 +237,67 @@ }

};
this.startOfYear = function (date) {
this.startOfYear = (date) => {
return date.clone().startOf("year");
};
this.endOfYear = function (date) {
this.endOfYear = (date) => {
return date.clone().endOf("year");
};
this.startOfMonth = function (date) {
this.startOfMonth = (date) => {
return date.clone().startOf("month");
};
this.endOfMonth = function (date) {
this.endOfMonth = (date) => {
return date.clone().endOf("month");
};
this.startOfWeek = function (date) {
this.startOfWeek = (date) => {
return date.clone().startOf("week");
};
this.endOfWeek = function (date) {
this.endOfWeek = (date) => {
return date.clone().endOf("week");
};
this.getNextMonth = function (date) {
this.getNextMonth = (date) => {
return date.clone().add(1, "month");
};
this.getPreviousMonth = function (date) {
this.getPreviousMonth = (date) => {
return date.clone().subtract(1, "month");
};
this.getMonthArray = function (date) {
var firstMonth = date.clone().startOf("year");
var monthArray = [firstMonth];
this.getMonthArray = (date) => {
const firstMonth = date.clone().startOf("year");
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.getYear = function (date) {
this.getYear = (date) => {
return date.get("year");
};
this.setYear = function (date, year) {
this.setYear = (date, year) => {
return date.clone().set("year", year);
};
this.getDate = function (date) {
this.getDate = (date) => {
return date.get("date");
};
this.setDate = function (date, year) {
this.setDate = (date, year) => {
return date.clone().set("date", year);
};
this.mergeDateAndTime = function (date, time) {
this.mergeDateAndTime = (date, time) => {
return date.hour(time.hour()).minute(time.minute()).second(time.second());
};
this.getWeekdays = function () {
return _this.moment.weekdaysShort(true);
this.getWeekdays = () => {
return this.moment.weekdaysShort(true);
};
this.isEqual = function (value, comparing) {
this.isEqual = (value, comparing) => {
if (value === null && comparing === null) {
return true;
}
return _this.moment(value).isSame(comparing);
return this.moment(value).isSame(comparing);
};
this.getWeekArray = function (date) {
var start = date.clone().startOf("month").startOf("week");
var end = date.clone().endOf("month").endOf("week");
var count = 0;
var current = start;
var nestedWeeks = [];
this.getWeekArray = (date) => {
const start = date.clone().startOf("month").startOf("week");
const end = date.clone().endOf("month").endOf("week");
let count = 0;
let current = start;
const nestedWeeks = [];
while (current.isBefore(end)) {
var weekNumber = Math.floor(count / 7);
const weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];

@@ -302,7 +310,7 @@ nestedWeeks[weekNumber].push(current);

};
this.getYearRange = function (start, end) {
var startDate = _this.moment(start).startOf("year");
var endDate = _this.moment(end).endOf("year");
var years = [];
var current = startDate;
this.getYearRange = (start, end) => {
const startDate = this.moment(start).startOf("year");
const endDate = this.moment(end).endOf("year");
const years = [];
let current = startDate;
while (current.isBefore(endDate)) {

@@ -314,4 +322,3 @@ years.push(current);

};
this.isWithinRange = function (date, _a) {
var start = _a[0], end = _a[1];
this.isWithinRange = (date, [start, end]) => {
return date.isBetween(start, end, null, "[]");

@@ -323,5 +330,4 @@ };

}
return MomentUtils;
}());
}
module.exports = MomentUtils;

@@ -8,3 +8,3 @@ import defaultMoment from "moment";

}
declare type Moment = defaultMoment.Moment;
type Moment = defaultMoment.Moment;
export default class MomentUtils implements IUtils<defaultMoment.Moment> {

@@ -21,4 +21,4 @@ moment: typeof defaultMoment;

toISO: (value: Moment) => string;
parse: (value: string, format: string) => defaultMoment.Moment;
date: (value?: any) => defaultMoment.Moment;
parse: (value: string, format: string) => defaultMoment.Moment | null;
date: (value?: any) => defaultMoment.Moment | null;
toJsDate: (value: Moment) => Date;

@@ -32,2 +32,4 @@ isValid: (value: any) => boolean;

isBeforeDay: (date: Moment, value: Moment) => boolean;
isBeforeMonth: (date: Moment, value: Moment) => boolean;
isAfterMonth: (date: Moment, value: Moment) => boolean;
isBeforeYear: (date: Moment, value: Moment) => boolean;

@@ -34,0 +36,0 @@ isAfterYear: (date: Moment, value: Moment) => boolean;

{
"name": "@date-io/moment",
"version": "2.16.1",
"version": "2.17.0",
"description": "Abstraction over common javascript date management libraries",

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

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

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

"rollup": "^2.0.2",
"typescript": "^3.7.2"
"typescript": "^5.0.0"
},

@@ -50,3 +50,3 @@ "scripts": {

"license": "MIT",
"gitHead": "6c16bac1b2ad5d8630c481383d7f575519ef47db"
"gitHead": "e497a04c456f04211c8b0877d002c85e72ea98a2"
}

@@ -63,17 +63,20 @@ import defaultMoment, { LongDateFormatKey } from "moment";

const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
return format
.match(localFormattingTokens)
.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "L" || firstCharacter === ";") {
return this.moment
.localeData(this.getCurrentLocaleCode())
.longDateFormat(token as LongDateFormatKey);
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase();
return (
format
.match(localFormattingTokens)
?.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "L" || firstCharacter === ";") {
return this.moment
.localeData(this.getCurrentLocaleCode())
.longDateFormat(token as LongDateFormatKey);
}
return token;
})
.join("")
.replace(/a/gi, "(a|p)m")
.toLocaleLowerCase() ?? format
);
};

@@ -111,3 +114,5 @@

const moment = this.moment(value);
moment.locale(this.locale);
if (this.locale) {
moment.locale(this.locale);
}

@@ -130,2 +135,6 @@ return moment;

public getDiff = (date: Moment, comparing: Moment | string, unit?: Unit) => {
if (!this.moment(comparing).isValid()) {
return 0;
}
return date.diff(comparing, unit);

@@ -150,2 +159,10 @@ };

public isBeforeMonth = (date: Moment, value: Moment) => {
return date.isBefore(value, "month");
};
public isAfterMonth = (date: Moment, value: Moment) => {
return date.isAfter(value, "month");
};
public isBeforeYear = (date: Moment, value: Moment) => {

@@ -173,3 +190,5 @@ return date.isBefore(value, "year");

const clonedDate = date.clone();
clonedDate.locale(this.locale);
if (this.locale) {
clonedDate.locale(this.locale);
}
return clonedDate.format(formatString);

@@ -176,0 +195,0 @@ };

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