@date-io/date-fns
Advanced tools
Comparing version 2.10.6 to 2.10.7
@@ -12,58 +12,58 @@ import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils"; | ||
}); | ||
is12HourCycleInCurrentLocale(): boolean; | ||
getFormatHelperText(format: string): string; | ||
getCurrentLocaleCode(): string; | ||
addSeconds(value: Date, count: number): Date; | ||
addMinutes(value: Date, count: number): Date; | ||
addHours(value: Date, count: number): Date; | ||
addDays(value: Date, count: number): Date; | ||
addWeeks(value: Date, count: number): Date; | ||
addMonths(value: Date, count: number): Date; | ||
isValid(value: any): boolean; | ||
getDiff(value: Date, comparing: Date | string, unit?: Unit): number; | ||
isAfter(value: Date, comparing: Date): boolean; | ||
isBefore(value: Date, comparing: Date): boolean; | ||
startOfDay(value: Date): Date; | ||
endOfDay(value: Date): Date; | ||
getHours(value: Date): number; | ||
setHours(value: Date, count: number): Date; | ||
setMinutes(value: Date, count: number): Date; | ||
getSeconds(value: Date): number; | ||
setSeconds(value: Date, count: number): Date; | ||
isSameDay(value: Date, comparing: Date): boolean; | ||
isSameMonth(value: Date, comparing: Date): boolean; | ||
isSameYear(value: Date, comparing: Date): boolean; | ||
isSameHour(value: Date, comparing: Date): boolean; | ||
startOfMonth(value: Date): Date; | ||
endOfMonth(value: Date): Date; | ||
startOfWeek(value: Date): Date; | ||
endOfWeek(value: Date): Date; | ||
getYear(value: Date): number; | ||
setYear(value: Date, count: number): Date; | ||
date(value?: any): Date; | ||
toJsDate(value: Date): Date; | ||
parse(value: string, formatString: string): Date; | ||
format(date: Date, formatKey: keyof DateIOFormats): string; | ||
formatByString(date: Date, formatString: string): string; | ||
isEqual(date: any, comparing: any): boolean; | ||
isNull(date: Date): boolean; | ||
isAfterDay(date: Date, value: Date): boolean; | ||
isBeforeDay(date: Date, value: Date): boolean; | ||
isBeforeYear(date: Date, value: Date): boolean; | ||
isAfterYear(date: Date, value: Date): boolean; | ||
isWithinRange(date: Date, [start, end]: [Date, Date]): boolean; | ||
formatNumber(numberToFormat: string): string; | ||
getMinutes(date: Date): number; | ||
getMonth(date: Date): number; | ||
getDaysInMonth(date: Date): number; | ||
setMonth(date: Date, count: number): Date; | ||
getMeridiemText(ampm: "am" | "pm"): "AM" | "PM"; | ||
getNextMonth(date: Date): Date; | ||
getPreviousMonth(date: Date): Date; | ||
getMonthArray(date: Date): Date[]; | ||
mergeDateAndTime(date: Date, time: Date): Date; | ||
getWeekdays(): string[]; | ||
getWeekArray(date: Date): Date[][]; | ||
getYearRange(start: Date, end: Date): Date[]; | ||
is12HourCycleInCurrentLocale: () => boolean; | ||
getFormatHelperText: (format: string) => string; | ||
getCurrentLocaleCode: () => string; | ||
addSeconds: (value: Date, count: number) => Date; | ||
addMinutes: (value: Date, count: number) => Date; | ||
addHours: (value: Date, count: number) => Date; | ||
addDays: (value: Date, count: number) => Date; | ||
addWeeks: (value: Date, count: number) => Date; | ||
addMonths: (value: Date, count: number) => Date; | ||
isValid: (value: any) => boolean; | ||
getDiff: (value: Date, comparing: Date | string, unit?: Unit) => number; | ||
isAfter: (value: Date, comparing: Date) => boolean; | ||
isBefore: (value: Date, comparing: Date) => boolean; | ||
startOfDay: (value: Date) => Date; | ||
endOfDay: (value: Date) => Date; | ||
getHours: (value: Date) => number; | ||
setHours: (value: Date, count: number) => Date; | ||
setMinutes: (value: Date, count: number) => Date; | ||
getSeconds: (value: Date) => number; | ||
setSeconds: (value: Date, count: number) => Date; | ||
isSameDay: (value: Date, comparing: Date) => boolean; | ||
isSameMonth: (value: Date, comparing: Date) => boolean; | ||
isSameYear: (value: Date, comparing: Date) => boolean; | ||
isSameHour: (value: Date, comparing: Date) => boolean; | ||
startOfMonth: (value: Date) => Date; | ||
endOfMonth: (value: Date) => Date; | ||
startOfWeek: (value: Date) => Date; | ||
endOfWeek: (value: Date) => Date; | ||
getYear: (value: Date) => number; | ||
setYear: (value: Date, count: number) => Date; | ||
date: (value?: any) => Date; | ||
toJsDate: (value: Date) => Date; | ||
parse: (value: string, formatString: string) => Date; | ||
format: (date: Date, formatKey: keyof DateIOFormats) => string; | ||
formatByString: (date: Date, formatString: string) => string; | ||
isEqual: (date: any, comparing: any) => boolean; | ||
isNull: (date: Date) => boolean; | ||
isAfterDay: (date: Date, value: Date) => boolean; | ||
isBeforeDay: (date: Date, value: Date) => boolean; | ||
isBeforeYear: (date: Date, value: Date) => boolean; | ||
isAfterYear: (date: Date, value: Date) => boolean; | ||
isWithinRange: (date: Date, [start, end]: [Date, Date]) => boolean; | ||
formatNumber: (numberToFormat: string) => string; | ||
getMinutes: (date: Date) => number; | ||
getMonth: (date: Date) => number; | ||
getDaysInMonth: (date: Date) => number; | ||
setMonth: (date: Date, count: number) => Date; | ||
getMeridiemText: (ampm: "am" | "pm") => "AM" | "PM"; | ||
getNextMonth: (date: Date) => Date; | ||
getPreviousMonth: (date: Date) => Date; | ||
getMonthArray: (date: Date) => Date[]; | ||
mergeDateAndTime: (date: Date, time: Date) => Date; | ||
getWeekdays: () => string[]; | ||
getWeekArray: (date: Date) => Date[][]; | ||
getYearRange: (start: Date, end: Date) => Date[]; | ||
} | ||
export {}; |
@@ -37,2 +37,3 @@ import addDays from 'date-fns/addDays'; | ||
import setMonth from 'date-fns/setMonth'; | ||
import getDay from 'date-fns/getDay'; | ||
import getDaysInMonth from 'date-fns/getDaysInMonth'; | ||
@@ -81,258 +82,263 @@ import setSeconds from 'date-fns/setSeconds'; | ||
function DateFnsUtils(_a) { | ||
var _this = this; | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.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()); | ||
} | ||
// By default date-fns is using en-US locale with am/pm enabled | ||
return true; | ||
}; | ||
this.getFormatHelperText = function (format) { | ||
// @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]; | ||
if (firstCharacter === "p" || firstCharacter === "P") { | ||
var longFormatter = longFormatters[firstCharacter]; | ||
return longFormatter(token, locale.formatLong, {}); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/(aaa|aa|a)/g, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
this.getCurrentLocaleCode = function () { | ||
var _a; | ||
return ((_a = _this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US"; | ||
}; | ||
this.addSeconds = function (value, count) { | ||
return addSeconds(value, count); | ||
}; | ||
this.addMinutes = function (value, count) { | ||
return addMinutes(value, count); | ||
}; | ||
this.addHours = function (value, count) { | ||
return addHours(value, count); | ||
}; | ||
this.addDays = function (value, count) { | ||
return addDays(value, count); | ||
}; | ||
this.addWeeks = function (value, count) { | ||
return addWeeks(value, count); | ||
}; | ||
this.addMonths = function (value, count) { | ||
return addMonths(value, count); | ||
}; | ||
this.isValid = function (value) { | ||
return isValid(_this.date(value)); | ||
}; | ||
this.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears(value, _this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters(value, _this.date(comparing)); | ||
case "months": | ||
return differenceInMonths(value, _this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks(value, _this.date(comparing)); | ||
case "days": | ||
return differenceInDays(value, _this.date(comparing)); | ||
case "hours": | ||
return differenceInHours(value, _this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes(value, _this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds(value, _this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds(value, _this.date(comparing)); | ||
} | ||
} | ||
}; | ||
this.isAfter = function (value, comparing) { | ||
return isAfter(value, comparing); | ||
}; | ||
this.isBefore = function (value, comparing) { | ||
return isBefore(value, comparing); | ||
}; | ||
this.startOfDay = function (value) { | ||
return startOfDay(value); | ||
}; | ||
this.endOfDay = function (value) { | ||
return endOfDay(value); | ||
}; | ||
this.getHours = function (value) { | ||
return getHours(value); | ||
}; | ||
this.setHours = function (value, count) { | ||
return setHours(value, count); | ||
}; | ||
this.setMinutes = function (value, count) { | ||
return setMinutes(value, count); | ||
}; | ||
this.getSeconds = function (value) { | ||
return getSeconds(value); | ||
}; | ||
this.setSeconds = function (value, count) { | ||
return setSeconds(value, count); | ||
}; | ||
this.isSameDay = function (value, comparing) { | ||
return isSameDay(value, comparing); | ||
}; | ||
this.isSameMonth = function (value, comparing) { | ||
return isSameMonth(value, comparing); | ||
}; | ||
this.isSameYear = function (value, comparing) { | ||
return isSameYear(value, comparing); | ||
}; | ||
this.isSameHour = function (value, comparing) { | ||
return isSameHour(value, comparing); | ||
}; | ||
this.startOfMonth = function (value) { | ||
return startOfMonth(value); | ||
}; | ||
this.endOfMonth = function (value) { | ||
return endOfMonth(value); | ||
}; | ||
this.startOfWeek = function (value) { | ||
return startOfWeek(value, { locale: _this.locale }); | ||
}; | ||
this.endOfWeek = function (value) { | ||
return endOfWeek(value, { locale: _this.locale }); | ||
}; | ||
this.getYear = function (value) { | ||
return getYear(value); | ||
}; | ||
this.setYear = function (value, count) { | ||
return setYear(value, count); | ||
}; | ||
this.date = function (value) { | ||
if (typeof value === "undefined") { | ||
return new Date(); | ||
} | ||
if (value === null) { | ||
return null; | ||
} | ||
return new Date(value); | ||
}; | ||
this.toJsDate = function (value) { | ||
return value; | ||
}; | ||
this.parse = function (value, formatString) { | ||
if (value === "") { | ||
return null; | ||
} | ||
return dateFnsParse(value, formatString, new Date(), { locale: _this.locale }); | ||
}; | ||
this.format = function (date, formatKey) { | ||
return _this.formatByString(date, _this.formats[formatKey]); | ||
}; | ||
this.formatByString = function (date, formatString) { | ||
return format(date, formatString, { locale: _this.locale }); | ||
}; | ||
this.isEqual = function (date, comparing) { | ||
if (date === null && comparing === null) { | ||
return true; | ||
} | ||
return isEqual(date, comparing); | ||
}; | ||
this.isNull = function (date) { | ||
return date === null; | ||
}; | ||
this.isAfterDay = function (date, value) { | ||
return isAfter(date, endOfDay(value)); | ||
}; | ||
this.isBeforeDay = function (date, value) { | ||
return isBefore(date, startOfDay(value)); | ||
}; | ||
this.isBeforeYear = function (date, value) { | ||
return isBefore(date, startOfYear(value)); | ||
}; | ||
this.isAfterYear = function (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.formatNumber = function (numberToFormat) { | ||
return numberToFormat; | ||
}; | ||
this.getMinutes = function (date) { | ||
return date.getMinutes(); | ||
}; | ||
this.getMonth = function (date) { | ||
return date.getMonth(); | ||
}; | ||
this.getDaysInMonth = function (date) { | ||
return getDaysInMonth(date); | ||
}; | ||
this.setMonth = function (date, count) { | ||
return setMonth(date, count); | ||
}; | ||
this.getMeridiemText = function (ampm) { | ||
return ampm === "am" ? "AM" : "PM"; | ||
}; | ||
this.getNextMonth = function (date) { | ||
return addMonths(date, 1); | ||
}; | ||
this.getPreviousMonth = function (date) { | ||
return addMonths(date, -1); | ||
}; | ||
this.getMonthArray = function (date) { | ||
var firstMonth = startOfYear(date); | ||
var monthArray = [firstMonth]; | ||
while (monthArray.length < 12) { | ||
var 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.getWeekdays = function () { | ||
var 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"); }); | ||
}; | ||
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; | ||
while (isBefore(current, end)) { | ||
var weekNumber = Math.floor(count / 7); | ||
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || []; | ||
var day = getDay(current); | ||
if (lastDay !== day) { | ||
lastDay = day; | ||
nestedWeeks[weekNumber].push(current); | ||
count += 1; | ||
} | ||
current = addDays(current, 1); | ||
} | ||
return nestedWeeks; | ||
}; | ||
this.getYearRange = function (start, end) { | ||
var startDate = startOfYear(start); | ||
var endDate = endOfYear(end); | ||
var years = []; | ||
var current = startDate; | ||
while (isBefore(current, endDate)) { | ||
years.push(current); | ||
current = addYears(current, 1); | ||
} | ||
return years; | ||
}; | ||
this.locale = locale; | ||
this.formats = Object.assign({}, defaultFormats, formats); | ||
} | ||
// 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. | ||
DateFnsUtils.prototype.is12HourCycleInCurrentLocale = function () { | ||
if (this.locale) { | ||
return /a/.test(this.locale.formatLong.time()); | ||
} | ||
// By default date-fns is using en-US locale with am/pm enabled | ||
return true; | ||
}; | ||
DateFnsUtils.prototype.getFormatHelperText = function (format) { | ||
// @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]; | ||
if (firstCharacter === "p" || firstCharacter === "P") { | ||
var longFormatter = longFormatters[firstCharacter]; | ||
return longFormatter(token, locale.formatLong, {}); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/(aaa|aa|a)/g, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
DateFnsUtils.prototype.getCurrentLocaleCode = function () { | ||
var _a; | ||
return ((_a = this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US"; | ||
}; | ||
DateFnsUtils.prototype.addSeconds = function (value, count) { | ||
return addSeconds(value, count); | ||
}; | ||
DateFnsUtils.prototype.addMinutes = function (value, count) { | ||
return addMinutes(value, count); | ||
}; | ||
DateFnsUtils.prototype.addHours = function (value, count) { | ||
return addHours(value, count); | ||
}; | ||
DateFnsUtils.prototype.addDays = function (value, count) { | ||
return addDays(value, count); | ||
}; | ||
DateFnsUtils.prototype.addWeeks = function (value, count) { | ||
return addWeeks(value, count); | ||
}; | ||
DateFnsUtils.prototype.addMonths = function (value, count) { | ||
return addMonths(value, count); | ||
}; | ||
DateFnsUtils.prototype.isValid = function (value) { | ||
return isValid(this.date(value)); | ||
}; | ||
DateFnsUtils.prototype.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears(value, this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters(value, this.date(comparing)); | ||
case "months": | ||
return differenceInMonths(value, this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks(value, this.date(comparing)); | ||
case "days": | ||
return differenceInDays(value, this.date(comparing)); | ||
case "hours": | ||
return differenceInHours(value, this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes(value, this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds(value, this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds(value, this.date(comparing)); | ||
} | ||
} | ||
}; | ||
DateFnsUtils.prototype.isAfter = function (value, comparing) { | ||
return isAfter(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isBefore = function (value, comparing) { | ||
return isBefore(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.startOfDay = function (value) { | ||
return startOfDay(value); | ||
}; | ||
DateFnsUtils.prototype.endOfDay = function (value) { | ||
return endOfDay(value); | ||
}; | ||
DateFnsUtils.prototype.getHours = function (value) { | ||
return getHours(value); | ||
}; | ||
DateFnsUtils.prototype.setHours = function (value, count) { | ||
return setHours(value, count); | ||
}; | ||
DateFnsUtils.prototype.setMinutes = function (value, count) { | ||
return setMinutes(value, count); | ||
}; | ||
DateFnsUtils.prototype.getSeconds = function (value) { | ||
return getSeconds(value); | ||
}; | ||
DateFnsUtils.prototype.setSeconds = function (value, count) { | ||
return setSeconds(value, count); | ||
}; | ||
DateFnsUtils.prototype.isSameDay = function (value, comparing) { | ||
return isSameDay(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameMonth = function (value, comparing) { | ||
return isSameMonth(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameYear = function (value, comparing) { | ||
return isSameYear(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameHour = function (value, comparing) { | ||
return isSameHour(value, comparing); | ||
}; | ||
DateFnsUtils.prototype.startOfMonth = function (value) { | ||
return startOfMonth(value); | ||
}; | ||
DateFnsUtils.prototype.endOfMonth = function (value) { | ||
return endOfMonth(value); | ||
}; | ||
DateFnsUtils.prototype.startOfWeek = function (value) { | ||
return startOfWeek(value, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.endOfWeek = function (value) { | ||
return endOfWeek(value, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.getYear = function (value) { | ||
return getYear(value); | ||
}; | ||
DateFnsUtils.prototype.setYear = function (value, count) { | ||
return setYear(value, count); | ||
}; | ||
DateFnsUtils.prototype.date = function (value) { | ||
if (typeof value === "undefined") { | ||
return new Date(); | ||
} | ||
if (value === null) { | ||
return null; | ||
} | ||
return new Date(value); | ||
}; | ||
DateFnsUtils.prototype.toJsDate = function (value) { | ||
return value; | ||
}; | ||
DateFnsUtils.prototype.parse = function (value, formatString) { | ||
if (value === "") { | ||
return null; | ||
} | ||
return dateFnsParse(value, formatString, new Date(), { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.format = function (date, formatKey) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
}; | ||
DateFnsUtils.prototype.formatByString = function (date, formatString) { | ||
return format(date, formatString, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.isEqual = function (date, comparing) { | ||
if (date === null && comparing === null) { | ||
return true; | ||
} | ||
return isEqual(date, comparing); | ||
}; | ||
DateFnsUtils.prototype.isNull = function (date) { | ||
return date === null; | ||
}; | ||
DateFnsUtils.prototype.isAfterDay = function (date, value) { | ||
return isAfter(date, endOfDay(value)); | ||
}; | ||
DateFnsUtils.prototype.isBeforeDay = function (date, value) { | ||
return isBefore(date, startOfDay(value)); | ||
}; | ||
DateFnsUtils.prototype.isBeforeYear = function (date, value) { | ||
return isBefore(date, startOfYear(value)); | ||
}; | ||
DateFnsUtils.prototype.isAfterYear = function (date, value) { | ||
return isAfter(date, endOfYear(value)); | ||
}; | ||
DateFnsUtils.prototype.isWithinRange = function (date, _a) { | ||
var start = _a[0], end = _a[1]; | ||
return isWithinInterval(date, { start: start, end: end }); | ||
}; | ||
DateFnsUtils.prototype.formatNumber = function (numberToFormat) { | ||
return numberToFormat; | ||
}; | ||
DateFnsUtils.prototype.getMinutes = function (date) { | ||
return date.getMinutes(); | ||
}; | ||
DateFnsUtils.prototype.getMonth = function (date) { | ||
return date.getMonth(); | ||
}; | ||
DateFnsUtils.prototype.getDaysInMonth = function (date) { | ||
return getDaysInMonth(date); | ||
}; | ||
DateFnsUtils.prototype.setMonth = function (date, count) { | ||
return setMonth(date, count); | ||
}; | ||
DateFnsUtils.prototype.getMeridiemText = function (ampm) { | ||
return ampm === "am" ? "AM" : "PM"; | ||
}; | ||
DateFnsUtils.prototype.getNextMonth = function (date) { | ||
return addMonths(date, 1); | ||
}; | ||
DateFnsUtils.prototype.getPreviousMonth = function (date) { | ||
return addMonths(date, -1); | ||
}; | ||
DateFnsUtils.prototype.getMonthArray = function (date) { | ||
var firstMonth = startOfYear(date); | ||
var monthArray = [firstMonth]; | ||
while (monthArray.length < 12) { | ||
var prevMonth = monthArray[monthArray.length - 1]; | ||
monthArray.push(this.getNextMonth(prevMonth)); | ||
} | ||
return monthArray; | ||
}; | ||
DateFnsUtils.prototype.mergeDateAndTime = function (date, time) { | ||
return this.setSeconds(this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), this.getSeconds(time)); | ||
}; | ||
DateFnsUtils.prototype.getWeekdays = function () { | ||
var _this = this; | ||
var 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"); }); | ||
}; | ||
DateFnsUtils.prototype.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 = []; | ||
while (isBefore(current, end)) { | ||
var weekNumber = Math.floor(count / 7); | ||
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || []; | ||
nestedWeeks[weekNumber].push(current); | ||
current = addDays(current, 1); | ||
count += 1; | ||
} | ||
return nestedWeeks; | ||
}; | ||
DateFnsUtils.prototype.getYearRange = function (start, end) { | ||
var startDate = startOfYear(start); | ||
var endDate = endOfYear(end); | ||
var years = []; | ||
var current = startDate; | ||
while (isBefore(current, endDate)) { | ||
years.push(current); | ||
current = addYears(current, 1); | ||
} | ||
return years; | ||
}; | ||
return DateFnsUtils; | ||
@@ -339,0 +345,0 @@ }()); |
@@ -39,2 +39,3 @@ 'use strict'; | ||
var setMonth = require('date-fns/setMonth'); | ||
var getDay = require('date-fns/getDay'); | ||
var getDaysInMonth = require('date-fns/getDaysInMonth'); | ||
@@ -90,2 +91,3 @@ var setSeconds = require('date-fns/setSeconds'); | ||
var setMonth__default = /*#__PURE__*/_interopDefaultLegacy(setMonth); | ||
var getDay__default = /*#__PURE__*/_interopDefaultLegacy(getDay); | ||
var getDaysInMonth__default = /*#__PURE__*/_interopDefaultLegacy(getDaysInMonth); | ||
@@ -134,258 +136,263 @@ var setSeconds__default = /*#__PURE__*/_interopDefaultLegacy(setSeconds); | ||
function DateFnsUtils(_a) { | ||
var _this = this; | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.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()); | ||
} | ||
// By default date-fns is using en-US locale with am/pm enabled | ||
return true; | ||
}; | ||
this.getFormatHelperText = function (format) { | ||
// @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]; | ||
if (firstCharacter === "p" || firstCharacter === "P") { | ||
var longFormatter = longFormatters__default['default'][firstCharacter]; | ||
return longFormatter(token, locale.formatLong, {}); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/(aaa|aa|a)/g, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
this.getCurrentLocaleCode = function () { | ||
var _a; | ||
return ((_a = _this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US"; | ||
}; | ||
this.addSeconds = function (value, count) { | ||
return addSeconds__default['default'](value, count); | ||
}; | ||
this.addMinutes = function (value, count) { | ||
return addMinutes__default['default'](value, count); | ||
}; | ||
this.addHours = function (value, count) { | ||
return addHours__default['default'](value, count); | ||
}; | ||
this.addDays = function (value, count) { | ||
return addDays__default['default'](value, count); | ||
}; | ||
this.addWeeks = function (value, count) { | ||
return addWeeks__default['default'](value, count); | ||
}; | ||
this.addMonths = function (value, count) { | ||
return addMonths__default['default'](value, count); | ||
}; | ||
this.isValid = function (value) { | ||
return isValid__default['default'](_this.date(value)); | ||
}; | ||
this.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears__default['default'](value, _this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters__default['default'](value, _this.date(comparing)); | ||
case "months": | ||
return differenceInMonths__default['default'](value, _this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks__default['default'](value, _this.date(comparing)); | ||
case "days": | ||
return differenceInDays__default['default'](value, _this.date(comparing)); | ||
case "hours": | ||
return differenceInHours__default['default'](value, _this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes__default['default'](value, _this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds__default['default'](value, _this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds__default['default'](value, _this.date(comparing)); | ||
} | ||
} | ||
}; | ||
this.isAfter = function (value, comparing) { | ||
return isAfter__default['default'](value, comparing); | ||
}; | ||
this.isBefore = function (value, comparing) { | ||
return isBefore__default['default'](value, comparing); | ||
}; | ||
this.startOfDay = function (value) { | ||
return startOfDay__default['default'](value); | ||
}; | ||
this.endOfDay = function (value) { | ||
return endOfDay__default['default'](value); | ||
}; | ||
this.getHours = function (value) { | ||
return getHours__default['default'](value); | ||
}; | ||
this.setHours = function (value, count) { | ||
return setHours__default['default'](value, count); | ||
}; | ||
this.setMinutes = function (value, count) { | ||
return setMinutes__default['default'](value, count); | ||
}; | ||
this.getSeconds = function (value) { | ||
return getSeconds__default['default'](value); | ||
}; | ||
this.setSeconds = function (value, count) { | ||
return setSeconds__default['default'](value, count); | ||
}; | ||
this.isSameDay = function (value, comparing) { | ||
return isSameDay__default['default'](value, comparing); | ||
}; | ||
this.isSameMonth = function (value, comparing) { | ||
return isSameMonth__default['default'](value, comparing); | ||
}; | ||
this.isSameYear = function (value, comparing) { | ||
return isSameYear__default['default'](value, comparing); | ||
}; | ||
this.isSameHour = function (value, comparing) { | ||
return isSameHour__default['default'](value, comparing); | ||
}; | ||
this.startOfMonth = function (value) { | ||
return startOfMonth__default['default'](value); | ||
}; | ||
this.endOfMonth = function (value) { | ||
return endOfMonth__default['default'](value); | ||
}; | ||
this.startOfWeek = function (value) { | ||
return startOfWeek__default['default'](value, { locale: _this.locale }); | ||
}; | ||
this.endOfWeek = function (value) { | ||
return endOfWeek__default['default'](value, { locale: _this.locale }); | ||
}; | ||
this.getYear = function (value) { | ||
return getYear__default['default'](value); | ||
}; | ||
this.setYear = function (value, count) { | ||
return setYear__default['default'](value, count); | ||
}; | ||
this.date = function (value) { | ||
if (typeof value === "undefined") { | ||
return new Date(); | ||
} | ||
if (value === null) { | ||
return null; | ||
} | ||
return new Date(value); | ||
}; | ||
this.toJsDate = function (value) { | ||
return value; | ||
}; | ||
this.parse = function (value, formatString) { | ||
if (value === "") { | ||
return null; | ||
} | ||
return dateFnsParse__default['default'](value, formatString, new Date(), { locale: _this.locale }); | ||
}; | ||
this.format = function (date, formatKey) { | ||
return _this.formatByString(date, _this.formats[formatKey]); | ||
}; | ||
this.formatByString = function (date, formatString) { | ||
return format__default['default'](date, formatString, { locale: _this.locale }); | ||
}; | ||
this.isEqual = function (date, comparing) { | ||
if (date === null && comparing === null) { | ||
return true; | ||
} | ||
return isEqual__default['default'](date, comparing); | ||
}; | ||
this.isNull = function (date) { | ||
return date === null; | ||
}; | ||
this.isAfterDay = function (date, value) { | ||
return isAfter__default['default'](date, endOfDay__default['default'](value)); | ||
}; | ||
this.isBeforeDay = function (date, value) { | ||
return isBefore__default['default'](date, startOfDay__default['default'](value)); | ||
}; | ||
this.isBeforeYear = function (date, value) { | ||
return isBefore__default['default'](date, startOfYear__default['default'](value)); | ||
}; | ||
this.isAfterYear = function (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.formatNumber = function (numberToFormat) { | ||
return numberToFormat; | ||
}; | ||
this.getMinutes = function (date) { | ||
return date.getMinutes(); | ||
}; | ||
this.getMonth = function (date) { | ||
return date.getMonth(); | ||
}; | ||
this.getDaysInMonth = function (date) { | ||
return getDaysInMonth__default['default'](date); | ||
}; | ||
this.setMonth = function (date, count) { | ||
return setMonth__default['default'](date, count); | ||
}; | ||
this.getMeridiemText = function (ampm) { | ||
return ampm === "am" ? "AM" : "PM"; | ||
}; | ||
this.getNextMonth = function (date) { | ||
return addMonths__default['default'](date, 1); | ||
}; | ||
this.getPreviousMonth = function (date) { | ||
return addMonths__default['default'](date, -1); | ||
}; | ||
this.getMonthArray = function (date) { | ||
var firstMonth = startOfYear__default['default'](date); | ||
var monthArray = [firstMonth]; | ||
while (monthArray.length < 12) { | ||
var 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.getWeekdays = function () { | ||
var 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"); }); | ||
}; | ||
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; | ||
while (isBefore__default['default'](current, end)) { | ||
var weekNumber = Math.floor(count / 7); | ||
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || []; | ||
var day = getDay__default['default'](current); | ||
if (lastDay !== day) { | ||
lastDay = day; | ||
nestedWeeks[weekNumber].push(current); | ||
count += 1; | ||
} | ||
current = addDays__default['default'](current, 1); | ||
} | ||
return nestedWeeks; | ||
}; | ||
this.getYearRange = function (start, end) { | ||
var startDate = startOfYear__default['default'](start); | ||
var endDate = endOfYear__default['default'](end); | ||
var years = []; | ||
var current = startDate; | ||
while (isBefore__default['default'](current, endDate)) { | ||
years.push(current); | ||
current = addYears__default['default'](current, 1); | ||
} | ||
return years; | ||
}; | ||
this.locale = locale; | ||
this.formats = Object.assign({}, defaultFormats, formats); | ||
} | ||
// 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. | ||
DateFnsUtils.prototype.is12HourCycleInCurrentLocale = function () { | ||
if (this.locale) { | ||
return /a/.test(this.locale.formatLong.time()); | ||
} | ||
// By default date-fns is using en-US locale with am/pm enabled | ||
return true; | ||
}; | ||
DateFnsUtils.prototype.getFormatHelperText = function (format) { | ||
// @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]; | ||
if (firstCharacter === "p" || firstCharacter === "P") { | ||
var longFormatter = longFormatters__default['default'][firstCharacter]; | ||
return longFormatter(token, locale.formatLong, {}); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/(aaa|aa|a)/g, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
DateFnsUtils.prototype.getCurrentLocaleCode = function () { | ||
var _a; | ||
return ((_a = this.locale) === null || _a === void 0 ? void 0 : _a.code) || "en-US"; | ||
}; | ||
DateFnsUtils.prototype.addSeconds = function (value, count) { | ||
return addSeconds__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.addMinutes = function (value, count) { | ||
return addMinutes__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.addHours = function (value, count) { | ||
return addHours__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.addDays = function (value, count) { | ||
return addDays__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.addWeeks = function (value, count) { | ||
return addWeeks__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.addMonths = function (value, count) { | ||
return addMonths__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.isValid = function (value) { | ||
return isValid__default['default'](this.date(value)); | ||
}; | ||
DateFnsUtils.prototype.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears__default['default'](value, this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters__default['default'](value, this.date(comparing)); | ||
case "months": | ||
return differenceInMonths__default['default'](value, this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks__default['default'](value, this.date(comparing)); | ||
case "days": | ||
return differenceInDays__default['default'](value, this.date(comparing)); | ||
case "hours": | ||
return differenceInHours__default['default'](value, this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes__default['default'](value, this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds__default['default'](value, this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds__default['default'](value, this.date(comparing)); | ||
} | ||
} | ||
}; | ||
DateFnsUtils.prototype.isAfter = function (value, comparing) { | ||
return isAfter__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isBefore = function (value, comparing) { | ||
return isBefore__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.startOfDay = function (value) { | ||
return startOfDay__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.endOfDay = function (value) { | ||
return endOfDay__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.getHours = function (value) { | ||
return getHours__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.setHours = function (value, count) { | ||
return setHours__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.setMinutes = function (value, count) { | ||
return setMinutes__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.getSeconds = function (value) { | ||
return getSeconds__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.setSeconds = function (value, count) { | ||
return setSeconds__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.isSameDay = function (value, comparing) { | ||
return isSameDay__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameMonth = function (value, comparing) { | ||
return isSameMonth__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameYear = function (value, comparing) { | ||
return isSameYear__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.isSameHour = function (value, comparing) { | ||
return isSameHour__default['default'](value, comparing); | ||
}; | ||
DateFnsUtils.prototype.startOfMonth = function (value) { | ||
return startOfMonth__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.endOfMonth = function (value) { | ||
return endOfMonth__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.startOfWeek = function (value) { | ||
return startOfWeek__default['default'](value, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.endOfWeek = function (value) { | ||
return endOfWeek__default['default'](value, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.getYear = function (value) { | ||
return getYear__default['default'](value); | ||
}; | ||
DateFnsUtils.prototype.setYear = function (value, count) { | ||
return setYear__default['default'](value, count); | ||
}; | ||
DateFnsUtils.prototype.date = function (value) { | ||
if (typeof value === "undefined") { | ||
return new Date(); | ||
} | ||
if (value === null) { | ||
return null; | ||
} | ||
return new Date(value); | ||
}; | ||
DateFnsUtils.prototype.toJsDate = function (value) { | ||
return value; | ||
}; | ||
DateFnsUtils.prototype.parse = function (value, formatString) { | ||
if (value === "") { | ||
return null; | ||
} | ||
return dateFnsParse__default['default'](value, formatString, new Date(), { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.format = function (date, formatKey) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
}; | ||
DateFnsUtils.prototype.formatByString = function (date, formatString) { | ||
return format__default['default'](date, formatString, { locale: this.locale }); | ||
}; | ||
DateFnsUtils.prototype.isEqual = function (date, comparing) { | ||
if (date === null && comparing === null) { | ||
return true; | ||
} | ||
return isEqual__default['default'](date, comparing); | ||
}; | ||
DateFnsUtils.prototype.isNull = function (date) { | ||
return date === null; | ||
}; | ||
DateFnsUtils.prototype.isAfterDay = function (date, value) { | ||
return isAfter__default['default'](date, endOfDay__default['default'](value)); | ||
}; | ||
DateFnsUtils.prototype.isBeforeDay = function (date, value) { | ||
return isBefore__default['default'](date, startOfDay__default['default'](value)); | ||
}; | ||
DateFnsUtils.prototype.isBeforeYear = function (date, value) { | ||
return isBefore__default['default'](date, startOfYear__default['default'](value)); | ||
}; | ||
DateFnsUtils.prototype.isAfterYear = function (date, value) { | ||
return isAfter__default['default'](date, endOfYear__default['default'](value)); | ||
}; | ||
DateFnsUtils.prototype.isWithinRange = function (date, _a) { | ||
var start = _a[0], end = _a[1]; | ||
return isWithinInterval__default['default'](date, { start: start, end: end }); | ||
}; | ||
DateFnsUtils.prototype.formatNumber = function (numberToFormat) { | ||
return numberToFormat; | ||
}; | ||
DateFnsUtils.prototype.getMinutes = function (date) { | ||
return date.getMinutes(); | ||
}; | ||
DateFnsUtils.prototype.getMonth = function (date) { | ||
return date.getMonth(); | ||
}; | ||
DateFnsUtils.prototype.getDaysInMonth = function (date) { | ||
return getDaysInMonth__default['default'](date); | ||
}; | ||
DateFnsUtils.prototype.setMonth = function (date, count) { | ||
return setMonth__default['default'](date, count); | ||
}; | ||
DateFnsUtils.prototype.getMeridiemText = function (ampm) { | ||
return ampm === "am" ? "AM" : "PM"; | ||
}; | ||
DateFnsUtils.prototype.getNextMonth = function (date) { | ||
return addMonths__default['default'](date, 1); | ||
}; | ||
DateFnsUtils.prototype.getPreviousMonth = function (date) { | ||
return addMonths__default['default'](date, -1); | ||
}; | ||
DateFnsUtils.prototype.getMonthArray = function (date) { | ||
var firstMonth = startOfYear__default['default'](date); | ||
var monthArray = [firstMonth]; | ||
while (monthArray.length < 12) { | ||
var prevMonth = monthArray[monthArray.length - 1]; | ||
monthArray.push(this.getNextMonth(prevMonth)); | ||
} | ||
return monthArray; | ||
}; | ||
DateFnsUtils.prototype.mergeDateAndTime = function (date, time) { | ||
return this.setSeconds(this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), this.getSeconds(time)); | ||
}; | ||
DateFnsUtils.prototype.getWeekdays = function () { | ||
var _this = this; | ||
var 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"); }); | ||
}; | ||
DateFnsUtils.prototype.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 = []; | ||
while (isBefore__default['default'](current, end)) { | ||
var weekNumber = Math.floor(count / 7); | ||
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || []; | ||
nestedWeeks[weekNumber].push(current); | ||
current = addDays__default['default'](current, 1); | ||
count += 1; | ||
} | ||
return nestedWeeks; | ||
}; | ||
DateFnsUtils.prototype.getYearRange = function (start, end) { | ||
var startDate = startOfYear__default['default'](start); | ||
var endDate = endOfYear__default['default'](end); | ||
var years = []; | ||
var current = startDate; | ||
while (isBefore__default['default'](current, endDate)) { | ||
years.push(current); | ||
current = addYears__default['default'](current, 1); | ||
} | ||
return years; | ||
}; | ||
return DateFnsUtils; | ||
@@ -392,0 +399,0 @@ }()); |
{ | ||
"name": "@date-io/date-fns", | ||
"version": "2.10.6", | ||
"version": "2.10.7", | ||
"description": "Abstraction over common javascript date management libraries", | ||
@@ -36,3 +36,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@date-io/core": "^2.10.6" | ||
"@date-io/core": "^2.10.7" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "3082a238a35ec86f0ba6a2fd410a2d69a88e48d3" | ||
"gitHead": "9c5e30787db67c9a9729c3cf26f584499366270e" | ||
} |
@@ -37,2 +37,3 @@ import addDays from "date-fns/addDays"; | ||
import setMonth from "date-fns/setMonth"; | ||
import getDay from "date-fns/getDay"; | ||
import getDaysInMonth from "date-fns/getDaysInMonth"; | ||
@@ -98,3 +99,3 @@ import setSeconds from "date-fns/setSeconds"; | ||
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage. | ||
public is12HourCycleInCurrentLocale() { | ||
public is12HourCycleInCurrentLocale = () => { | ||
if (this.locale) { | ||
@@ -106,5 +107,5 @@ return /a/.test(this.locale.formatLong.time()); | ||
return true; | ||
} | ||
}; | ||
public getFormatHelperText(format: string) { | ||
public getFormatHelperText = (format: string) => { | ||
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31 | ||
@@ -126,37 +127,37 @@ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; | ||
.toLocaleLowerCase(); | ||
} | ||
}; | ||
public getCurrentLocaleCode() { | ||
public getCurrentLocaleCode = () => { | ||
return this.locale?.code || "en-US"; | ||
} | ||
}; | ||
public addSeconds(value: Date, count: number) { | ||
public addSeconds = (value: Date, count: number) => { | ||
return addSeconds(value, count); | ||
} | ||
}; | ||
public addMinutes(value: Date, count: number) { | ||
public addMinutes = (value: Date, count: number) => { | ||
return addMinutes(value, count); | ||
} | ||
}; | ||
public addHours(value: Date, count: number) { | ||
public addHours = (value: Date, count: number) => { | ||
return addHours(value, count); | ||
} | ||
}; | ||
public addDays(value: Date, count: number) { | ||
public addDays = (value: Date, count: number) => { | ||
return addDays(value, count); | ||
} | ||
}; | ||
public addWeeks(value: Date, count: number) { | ||
public addWeeks = (value: Date, count: number) => { | ||
return addWeeks(value, count); | ||
} | ||
}; | ||
public addMonths(value: Date, count: number) { | ||
public addMonths = (value: Date, count: number) => { | ||
return addMonths(value, count); | ||
} | ||
}; | ||
public isValid(value: any) { | ||
public isValid = (value: any) => { | ||
return isValid(this.date(value)); | ||
} | ||
}; | ||
public getDiff(value: Date, comparing: Date | string, unit?: Unit) { | ||
public getDiff = (value: Date, comparing: Date | string, unit?: Unit) => { | ||
switch (unit) { | ||
@@ -183,81 +184,81 @@ case "years": | ||
} | ||
} | ||
}; | ||
public isAfter(value: Date, comparing: Date) { | ||
public isAfter = (value: Date, comparing: Date) => { | ||
return isAfter(value, comparing); | ||
} | ||
}; | ||
public isBefore(value: Date, comparing: Date) { | ||
public isBefore = (value: Date, comparing: Date) => { | ||
return isBefore(value, comparing); | ||
} | ||
}; | ||
public startOfDay(value: Date) { | ||
public startOfDay = (value: Date) => { | ||
return startOfDay(value); | ||
} | ||
}; | ||
public endOfDay(value: Date) { | ||
public endOfDay = (value: Date) => { | ||
return endOfDay(value); | ||
} | ||
}; | ||
public getHours(value: Date) { | ||
public getHours = (value: Date) => { | ||
return getHours(value); | ||
} | ||
}; | ||
public setHours(value: Date, count: number) { | ||
public setHours = (value: Date, count: number) => { | ||
return setHours(value, count); | ||
} | ||
}; | ||
public setMinutes(value: Date, count: number) { | ||
public setMinutes = (value: Date, count: number) => { | ||
return setMinutes(value, count); | ||
} | ||
}; | ||
public getSeconds(value: Date) { | ||
public getSeconds = (value: Date) => { | ||
return getSeconds(value); | ||
} | ||
}; | ||
public setSeconds(value: Date, count: number) { | ||
public setSeconds = (value: Date, count: number) => { | ||
return setSeconds(value, count); | ||
} | ||
}; | ||
public isSameDay(value: Date, comparing: Date) { | ||
public isSameDay = (value: Date, comparing: Date) => { | ||
return isSameDay(value, comparing); | ||
} | ||
}; | ||
public isSameMonth(value: Date, comparing: Date) { | ||
public isSameMonth = (value: Date, comparing: Date) => { | ||
return isSameMonth(value, comparing); | ||
} | ||
}; | ||
public isSameYear(value: Date, comparing: Date) { | ||
public isSameYear = (value: Date, comparing: Date) => { | ||
return isSameYear(value, comparing); | ||
} | ||
}; | ||
public isSameHour(value: Date, comparing: Date) { | ||
public isSameHour = (value: Date, comparing: Date) => { | ||
return isSameHour(value, comparing); | ||
} | ||
}; | ||
public startOfMonth(value: Date) { | ||
public startOfMonth = (value: Date) => { | ||
return startOfMonth(value); | ||
} | ||
}; | ||
public endOfMonth(value: Date) { | ||
public endOfMonth = (value: Date) => { | ||
return endOfMonth(value); | ||
} | ||
}; | ||
public startOfWeek(value: Date) { | ||
public startOfWeek = (value: Date) => { | ||
return startOfWeek(value, { locale: this.locale }); | ||
} | ||
}; | ||
public endOfWeek(value: Date) { | ||
public endOfWeek = (value: Date) => { | ||
return endOfWeek(value, { locale: this.locale }); | ||
} | ||
}; | ||
public getYear(value: Date) { | ||
public getYear = (value: Date) => { | ||
return getYear(value); | ||
} | ||
}; | ||
public setYear(value: Date, count: number) { | ||
public setYear = (value: Date, count: number) => { | ||
return setYear(value, count); | ||
} | ||
}; | ||
public date(value?: any) { | ||
public date = (value?: any) => { | ||
if (typeof value === "undefined") { | ||
@@ -272,9 +273,9 @@ return new Date(); | ||
return new Date(value); | ||
} | ||
}; | ||
public toJsDate(value: Date) { | ||
public toJsDate = (value: Date) => { | ||
return value; | ||
} | ||
}; | ||
public parse(value: string, formatString: string) { | ||
public parse = (value: string, formatString: string) => { | ||
if (value === "") { | ||
@@ -285,13 +286,13 @@ return null; | ||
return dateFnsParse(value, formatString, new Date(), { locale: this.locale }); | ||
} | ||
}; | ||
public format(date: Date, formatKey: keyof DateIOFormats) { | ||
public format = (date: Date, formatKey: keyof DateIOFormats) => { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
} | ||
}; | ||
public formatByString(date: Date, formatString: string) { | ||
public formatByString = (date: Date, formatString: string) => { | ||
return format(date, formatString, { locale: this.locale }); | ||
} | ||
}; | ||
public isEqual(date: any, comparing: any) { | ||
public isEqual = (date: any, comparing: any) => { | ||
if (date === null && comparing === null) { | ||
@@ -302,61 +303,61 @@ return true; | ||
return isEqual(date, comparing); | ||
} | ||
}; | ||
public isNull(date: Date) { | ||
public isNull = (date: Date) => { | ||
return date === null; | ||
} | ||
}; | ||
public isAfterDay(date: Date, value: Date) { | ||
public isAfterDay = (date: Date, value: Date) => { | ||
return isAfter(date, endOfDay(value)); | ||
} | ||
}; | ||
public isBeforeDay(date: Date, value: Date) { | ||
public isBeforeDay = (date: Date, value: Date) => { | ||
return isBefore(date, startOfDay(value)); | ||
} | ||
}; | ||
public isBeforeYear(date: Date, value: Date) { | ||
public isBeforeYear = (date: Date, value: Date) => { | ||
return isBefore(date, startOfYear(value)); | ||
} | ||
}; | ||
public isAfterYear(date: Date, value: Date) { | ||
public isAfterYear = (date: Date, value: Date) => { | ||
return isAfter(date, endOfYear(value)); | ||
} | ||
}; | ||
public isWithinRange(date: Date, [start, end]: [Date, Date]) { | ||
public isWithinRange = (date: Date, [start, end]: [Date, Date]) => { | ||
return isWithinInterval(date, { start, end }); | ||
} | ||
}; | ||
public formatNumber(numberToFormat: string) { | ||
public formatNumber = (numberToFormat: string) => { | ||
return numberToFormat; | ||
} | ||
}; | ||
public getMinutes(date: Date) { | ||
public getMinutes = (date: Date) => { | ||
return date.getMinutes(); | ||
} | ||
}; | ||
public getMonth(date: Date) { | ||
public getMonth = (date: Date) => { | ||
return date.getMonth(); | ||
} | ||
}; | ||
public getDaysInMonth(date: Date) { | ||
public getDaysInMonth = (date: Date) => { | ||
return getDaysInMonth(date); | ||
} | ||
}; | ||
public setMonth(date: Date, count: number) { | ||
public setMonth = (date: Date, count: number) => { | ||
return setMonth(date, count); | ||
} | ||
}; | ||
public getMeridiemText(ampm: "am" | "pm") { | ||
public getMeridiemText = (ampm: "am" | "pm") => { | ||
return ampm === "am" ? "AM" : "PM"; | ||
} | ||
}; | ||
public getNextMonth(date: Date) { | ||
public getNextMonth = (date: Date) => { | ||
return addMonths(date, 1); | ||
} | ||
}; | ||
public getPreviousMonth(date: Date) { | ||
public getPreviousMonth = (date: Date) => { | ||
return addMonths(date, -1); | ||
} | ||
}; | ||
public getMonthArray(date: Date) { | ||
public getMonthArray = (date: Date) => { | ||
const firstMonth = startOfYear(date); | ||
@@ -371,5 +372,5 @@ const monthArray = [firstMonth]; | ||
return monthArray; | ||
} | ||
}; | ||
public mergeDateAndTime(date: Date, time: Date) { | ||
public mergeDateAndTime = (date: Date, time: Date) => { | ||
return this.setSeconds( | ||
@@ -379,5 +380,5 @@ this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), | ||
); | ||
} | ||
}; | ||
public getWeekdays() { | ||
public getWeekdays = () => { | ||
const now = new Date(); | ||
@@ -388,5 +389,5 @@ return eachDayOfInterval({ | ||
}).map((day) => this.formatByString(day, "EEEEEE")); | ||
} | ||
}; | ||
public getWeekArray(date: Date) { | ||
public getWeekArray = (date: Date) => { | ||
const start = startOfWeek(startOfMonth(date), { locale: this.locale }); | ||
@@ -398,15 +399,18 @@ const end = endOfWeek(endOfMonth(date), { locale: this.locale }); | ||
const nestedWeeks: Date[][] = []; | ||
let lastDay = null; | ||
while (isBefore(current, end)) { | ||
const weekNumber = Math.floor(count / 7); | ||
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || []; | ||
nestedWeeks[weekNumber].push(current); | ||
const day = getDay(current); | ||
if (lastDay !== day) { | ||
lastDay = day; | ||
nestedWeeks[weekNumber].push(current); | ||
count += 1; | ||
} | ||
current = addDays(current, 1); | ||
count += 1; | ||
} | ||
return nestedWeeks; | ||
} | ||
}; | ||
public getYearRange(start: Date, end: Date) { | ||
public getYearRange = (start: Date, end: Date) => { | ||
const startDate = startOfYear(start); | ||
@@ -423,3 +427,3 @@ const endDate = endOfYear(end); | ||
return years; | ||
} | ||
}; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50284
1168
Updated@date-io/core@^2.10.7