@date-io/dayjs
Advanced tools
Comparing version 1.3.13 to 2.0.0
import defaultDayjs from "dayjs"; | ||
import { IUtils } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
interface Opts { | ||
@@ -7,4 +7,3 @@ locale?: string; | ||
instance?: typeof defaultDayjs; | ||
/** @deprecated */ | ||
dayjs?: typeof defaultDayjs; | ||
formats?: Partial<DateIOFormats>; | ||
} | ||
@@ -16,10 +15,4 @@ declare type Dayjs = defaultDayjs.Dayjs; | ||
locale?: string; | ||
yearFormat: string; | ||
yearMonthFormat: string; | ||
dateTime12hFormat: string; | ||
dateTime24hFormat: string; | ||
time12hFormat: string; | ||
time24hFormat: string; | ||
dateFormat: string; | ||
constructor({ locale, instance, dayjs }?: Opts); | ||
formats: DateIOFormats; | ||
constructor({ locale, formats, instance }?: Opts); | ||
parse(value: any, format: any): defaultDayjs.Dayjs; | ||
@@ -38,3 +31,4 @@ date(value?: any): defaultDayjs.Dayjs; | ||
endOfDay(date: Dayjs): defaultDayjs.Dayjs; | ||
format(date: Dayjs, formatString: string): string; | ||
format(date: Dayjs, formatKey: keyof DateIOFormats): string; | ||
formatByString(date: Dayjs, formatString: string): string; | ||
formatNumber(numberToFormat: string): string; | ||
@@ -60,3 +54,2 @@ getHours(date: Dayjs): number; | ||
getMonthArray(date: Dayjs): defaultDayjs.Dayjs[]; | ||
getMonthText(date: Dayjs): string; | ||
getYear(date: Dayjs): number; | ||
@@ -69,11 +62,3 @@ setYear(date: Dayjs, year: number): defaultDayjs.Dayjs; | ||
getYearRange(start: Dayjs, end: Dayjs): defaultDayjs.Dayjs[]; | ||
getCalendarHeaderText(date: Dayjs): string; | ||
getYearText(date: Dayjs): string; | ||
getDatePickerHeaderText(date: Dayjs): string; | ||
getDateTimePickerHeaderText(date: Dayjs): string; | ||
getDayText(date: Dayjs): string; | ||
getHourText(date: Dayjs, ampm: boolean): string; | ||
getMinuteText(date: Dayjs): string; | ||
getSecondText(date: Dayjs): string; | ||
} | ||
export {}; |
@@ -0,1 +1,2 @@ | ||
import { __assign } from 'tslib'; | ||
import defaultDayjs from 'dayjs'; | ||
@@ -16,14 +17,30 @@ import customParseFormat from 'dayjs/plugin/customParseFormat'; | ||
}; | ||
var defaultFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM Do", | ||
shortDate: "MMM Do", | ||
monthAndDate: "MMMM Do", | ||
dayOfMonth: "D", | ||
year: "YYYY", | ||
month: "MMMM", | ||
monthShort: "MMM", | ||
monthAndYear: "MMMM YYYY", | ||
minutes: "mm", | ||
hours12h: "hh", | ||
hours24h: "HH", | ||
seconds: "ss", | ||
fullTime12h: "hh:mm A", | ||
fullTime24h: "HH:mm", | ||
fullDateTime12h: "YYYY, MMM Do hh:mm A", | ||
fullDateTime24h: "YYYY, MMM Do HH:mm", | ||
keyboardDate: "YYYY/MM/DD", | ||
keyboardDateTime12h: "YYYY/MM/DD hh:mm A", | ||
keyboardDateTime24h: "YYYY/MM/DD HH:mm" | ||
}; | ||
var DayjsUtils = /** @class */ (function () { | ||
function DayjsUtils(_a) { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, instance = _b.instance, dayjs = _b.dayjs; | ||
this.yearFormat = "YYYY"; | ||
this.yearMonthFormat = "MMMM YYYY"; | ||
this.dateTime12hFormat = "MMMM Do hh:mm a"; | ||
this.dateTime24hFormat = "MMMM Do HH:mm"; | ||
this.time12hFormat = "hh:mm A"; | ||
this.time24hFormat = "HH:mm"; | ||
this.dateFormat = "MMMM Do"; | ||
this.dayjs = withLocale(instance || dayjs || defaultDayjs, locale); | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.locale = locale; | ||
this.formats = __assign(__assign({}, defaultFormats), formats); | ||
} | ||
@@ -75,3 +92,6 @@ DayjsUtils.prototype.parse = function (value, format) { | ||
}; | ||
DayjsUtils.prototype.format = function (date, formatString) { | ||
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); | ||
@@ -147,5 +167,2 @@ }; | ||
}; | ||
DayjsUtils.prototype.getMonthText = function (date) { | ||
return this.format(date, "MMMM"); | ||
}; | ||
DayjsUtils.prototype.getYear = function (date) { | ||
@@ -163,3 +180,5 @@ return date.year(); | ||
var start = this.dayjs().startOf("week"); | ||
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) { return _this.format(start.add(diff, "day"), "dd"); }); | ||
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) { | ||
return _this.formatByString(start.add(diff, "day"), "dd"); | ||
}); | ||
}; | ||
@@ -204,27 +223,2 @@ DayjsUtils.prototype.isEqual = function (value, comparing) { | ||
}; | ||
// displaying methods | ||
DayjsUtils.prototype.getCalendarHeaderText = function (date) { | ||
return this.format(date, "MMMM YYYY"); | ||
}; | ||
DayjsUtils.prototype.getYearText = function (date) { | ||
return this.format(date, "YYYY"); | ||
}; | ||
DayjsUtils.prototype.getDatePickerHeaderText = function (date) { | ||
return this.format(date, "ddd, MMM D"); | ||
}; | ||
DayjsUtils.prototype.getDateTimePickerHeaderText = function (date) { | ||
return this.format(date, "MMM D"); | ||
}; | ||
DayjsUtils.prototype.getDayText = function (date) { | ||
return this.format(date, "D"); | ||
}; | ||
DayjsUtils.prototype.getHourText = function (date, ampm) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
}; | ||
DayjsUtils.prototype.getMinuteText = function (date) { | ||
return this.format(date, "mm"); | ||
}; | ||
DayjsUtils.prototype.getSecondText = function (date) { | ||
return this.format(date, "ss"); | ||
}; | ||
return DayjsUtils; | ||
@@ -231,0 +225,0 @@ }()); |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
var defaultDayjs = _interopDefault(require('dayjs')); | ||
@@ -21,14 +22,30 @@ var customParseFormat = _interopDefault(require('dayjs/plugin/customParseFormat')); | ||
}; | ||
var defaultFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM Do", | ||
shortDate: "MMM Do", | ||
monthAndDate: "MMMM Do", | ||
dayOfMonth: "D", | ||
year: "YYYY", | ||
month: "MMMM", | ||
monthShort: "MMM", | ||
monthAndYear: "MMMM YYYY", | ||
minutes: "mm", | ||
hours12h: "hh", | ||
hours24h: "HH", | ||
seconds: "ss", | ||
fullTime12h: "hh:mm A", | ||
fullTime24h: "HH:mm", | ||
fullDateTime12h: "YYYY, MMM Do hh:mm A", | ||
fullDateTime24h: "YYYY, MMM Do HH:mm", | ||
keyboardDate: "YYYY/MM/DD", | ||
keyboardDateTime12h: "YYYY/MM/DD hh:mm A", | ||
keyboardDateTime24h: "YYYY/MM/DD HH:mm" | ||
}; | ||
var DayjsUtils = /** @class */ (function () { | ||
function DayjsUtils(_a) { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, instance = _b.instance, dayjs = _b.dayjs; | ||
this.yearFormat = "YYYY"; | ||
this.yearMonthFormat = "MMMM YYYY"; | ||
this.dateTime12hFormat = "MMMM Do hh:mm a"; | ||
this.dateTime24hFormat = "MMMM Do HH:mm"; | ||
this.time12hFormat = "hh:mm A"; | ||
this.time24hFormat = "HH:mm"; | ||
this.dateFormat = "MMMM Do"; | ||
this.dayjs = withLocale(instance || dayjs || defaultDayjs, locale); | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.locale = locale; | ||
this.formats = tslib.__assign(tslib.__assign({}, defaultFormats), formats); | ||
} | ||
@@ -80,3 +97,6 @@ DayjsUtils.prototype.parse = function (value, format) { | ||
}; | ||
DayjsUtils.prototype.format = function (date, formatString) { | ||
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); | ||
@@ -152,5 +172,2 @@ }; | ||
}; | ||
DayjsUtils.prototype.getMonthText = function (date) { | ||
return this.format(date, "MMMM"); | ||
}; | ||
DayjsUtils.prototype.getYear = function (date) { | ||
@@ -168,3 +185,5 @@ return date.year(); | ||
var start = this.dayjs().startOf("week"); | ||
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) { return _this.format(start.add(diff, "day"), "dd"); }); | ||
return [0, 1, 2, 3, 4, 5, 6].map(function (diff) { | ||
return _this.formatByString(start.add(diff, "day"), "dd"); | ||
}); | ||
}; | ||
@@ -209,27 +228,2 @@ DayjsUtils.prototype.isEqual = function (value, comparing) { | ||
}; | ||
// displaying methods | ||
DayjsUtils.prototype.getCalendarHeaderText = function (date) { | ||
return this.format(date, "MMMM YYYY"); | ||
}; | ||
DayjsUtils.prototype.getYearText = function (date) { | ||
return this.format(date, "YYYY"); | ||
}; | ||
DayjsUtils.prototype.getDatePickerHeaderText = function (date) { | ||
return this.format(date, "ddd, MMM D"); | ||
}; | ||
DayjsUtils.prototype.getDateTimePickerHeaderText = function (date) { | ||
return this.format(date, "MMM D"); | ||
}; | ||
DayjsUtils.prototype.getDayText = function (date) { | ||
return this.format(date, "D"); | ||
}; | ||
DayjsUtils.prototype.getHourText = function (date, ampm) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
}; | ||
DayjsUtils.prototype.getMinuteText = function (date) { | ||
return this.format(date, "mm"); | ||
}; | ||
DayjsUtils.prototype.getSecondText = function (date) { | ||
return this.format(date, "ss"); | ||
}; | ||
return DayjsUtils; | ||
@@ -236,0 +230,0 @@ }()); |
{ | ||
"name": "@date-io/dayjs", | ||
"version": "1.3.13", | ||
"version": "2.0.0", | ||
"description": "Abstraction over common javascript date management libraries", | ||
@@ -12,3 +12,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@date-io/core": "^1.3.13" | ||
"@date-io/core": "^2.0.0" | ||
}, | ||
@@ -45,3 +45,3 @@ "devDependencies": { | ||
"license": "MIT", | ||
"gitHead": "d105764c36b2021cde1fbcddd5445fed582a511c" | ||
"gitHead": "29c8f93efe8086a1b5ebb51b0a99d669219d4cbf" | ||
} |
import defaultDayjs from "dayjs"; | ||
import customParseFormat from "dayjs/plugin/customParseFormat"; | ||
import advancedFormat from "dayjs/plugin/advancedFormat"; | ||
import { IUtils } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
@@ -13,4 +13,3 @@ defaultDayjs.extend(customParseFormat); | ||
instance?: typeof defaultDayjs; | ||
/** @deprecated */ | ||
dayjs?: typeof defaultDayjs; | ||
formats?: Partial<DateIOFormats>; | ||
} | ||
@@ -24,24 +23,38 @@ | ||
const defaultFormats: DateIOFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM Do", | ||
shortDate: "MMM Do", | ||
monthAndDate: "MMMM Do", | ||
dayOfMonth: "D", | ||
year: "YYYY", | ||
month: "MMMM", | ||
monthShort: "MMM", | ||
monthAndYear: "MMMM YYYY", | ||
minutes: "mm", | ||
hours12h: "hh", | ||
hours24h: "HH", | ||
seconds: "ss", | ||
fullTime12h: "hh:mm A", | ||
fullTime24h: "HH:mm", | ||
fullDateTime12h: "YYYY, MMM Do hh:mm A", | ||
fullDateTime24h: "YYYY, MMM Do HH:mm", | ||
keyboardDate: "YYYY/MM/DD", | ||
keyboardDateTime12h: "YYYY/MM/DD hh:mm A", | ||
keyboardDateTime24h: "YYYY/MM/DD HH:mm" | ||
}; | ||
export default class DayjsUtils implements IUtils<defaultDayjs.Dayjs> { | ||
public dayjs: Constructor; | ||
public locale?: string; | ||
public formats: DateIOFormats; | ||
public yearFormat = "YYYY"; | ||
constructor({ locale, formats, instance }: Opts = {}) { | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.locale = locale; | ||
public yearMonthFormat = "MMMM YYYY"; | ||
public dateTime12hFormat = "MMMM Do hh:mm a"; | ||
public dateTime24hFormat = "MMMM Do HH:mm"; | ||
public time12hFormat = "hh:mm A"; | ||
public time24hFormat = "HH:mm"; | ||
public dateFormat = "MMMM Do"; | ||
constructor({ locale, instance, dayjs }: Opts = {}) { | ||
this.dayjs = withLocale(instance || dayjs || defaultDayjs, locale); | ||
this.locale = locale; | ||
this.formats = { | ||
...defaultFormats, | ||
...formats | ||
}; | ||
} | ||
@@ -109,3 +122,7 @@ | ||
public format(date: Dayjs, formatString: string) { | ||
public format(date: Dayjs, formatKey: keyof DateIOFormats) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
} | ||
public formatByString(date: Dayjs, formatString: string) { | ||
return this.dayjs(date).format(formatString); | ||
@@ -204,6 +221,2 @@ } | ||
public getMonthText(date: Dayjs) { | ||
return this.format(date, "MMMM"); | ||
} | ||
public getYear(date: Dayjs) { | ||
@@ -226,3 +239,5 @@ return date.year(); | ||
const start = this.dayjs().startOf("week"); | ||
return [0, 1, 2, 3, 4, 5, 6].map(diff => this.format(start.add(diff, "day"), "dd")); | ||
return [0, 1, 2, 3, 4, 5, 6].map(diff => | ||
this.formatByString(start.add(diff, "day"), "dd") | ||
); | ||
} | ||
@@ -277,35 +292,2 @@ | ||
} | ||
// displaying methods | ||
public getCalendarHeaderText(date: Dayjs) { | ||
return this.format(date, "MMMM YYYY"); | ||
} | ||
public getYearText(date: Dayjs) { | ||
return this.format(date, "YYYY"); | ||
} | ||
public getDatePickerHeaderText(date: Dayjs) { | ||
return this.format(date, "ddd, MMM D"); | ||
} | ||
public getDateTimePickerHeaderText(date: Dayjs) { | ||
return this.format(date, "MMM D"); | ||
} | ||
public getDayText(date: Dayjs) { | ||
return this.format(date, "D"); | ||
} | ||
public getHourText(date: Dayjs, ampm: boolean) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
} | ||
public getMinuteText(date: Dayjs) { | ||
return this.format(date, "mm"); | ||
} | ||
public getSecondText(date: Dayjs) { | ||
return this.format(date, "ss"); | ||
} | ||
} |
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
28255
745
+ Added@date-io/core@2.17.0(transitive)
- Removed@date-io/core@1.3.13(transitive)
Updated@date-io/core@^2.0.0