@date-io/dayjs
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -12,2 +12,3 @@ import defaultDayjs from "dayjs"; | ||
export default class DayjsUtils implements IUtils<defaultDayjs.Dayjs> { | ||
rawDayJsInstance: typeof defaultDayjs; | ||
dayjs: Constructor; | ||
@@ -17,2 +18,4 @@ locale?: string; | ||
constructor({ locale, formats, instance }?: Opts); | ||
is12HourCycleInCurrentLocale(): boolean; | ||
getCurrentLocaleCode(): string; | ||
parse(value: any, format: any): defaultDayjs.Dayjs; | ||
@@ -19,0 +22,0 @@ date(value?: any): defaultDayjs.Dayjs; |
@@ -1,8 +0,7 @@ | ||
import { __assign } from 'tslib'; | ||
import defaultDayjs from 'dayjs'; | ||
import customParseFormat from 'dayjs/plugin/customParseFormat'; | ||
import advancedFormat from 'dayjs/plugin/advancedFormat'; | ||
import customParseFormatPlugin from 'dayjs/plugin/customParseFormat'; | ||
import localizedFormatPlugin from 'dayjs/plugin/localizedFormat'; | ||
defaultDayjs.extend(customParseFormat); | ||
defaultDayjs.extend(advancedFormat); | ||
defaultDayjs.extend(customParseFormatPlugin); | ||
defaultDayjs.extend(localizedFormatPlugin); | ||
var withLocale = function (dayjs, locale) { | ||
@@ -18,5 +17,4 @@ return !locale ? dayjs : function () { | ||
var defaultFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM D", | ||
shortDate: "MMM D", | ||
shortDate: "DD MMMM", | ||
monthAndDate: "MMMM D", | ||
@@ -32,9 +30,13 @@ dayOfMonth: "D", | ||
seconds: "ss", | ||
fullTime: "LT", | ||
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" | ||
fullDate: "ll", | ||
fullDateTime: "lll", | ||
fullDateTime12h: "ll hh:mm A", | ||
fullDateTime24h: "ll HH:mm", | ||
keyboardDate: "L", | ||
keyboardDateTime: "L LT", | ||
keyboardDateTime12h: "L hh:mm A", | ||
keyboardDateTime24h: "L HH:mm" | ||
}; | ||
@@ -44,6 +46,15 @@ var DayjsUtils = /** @class */ (function () { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.rawDayJsInstance = instance || defaultDayjs; | ||
this.dayjs = withLocale(this.rawDayJsInstance, locale); | ||
this.locale = locale; | ||
this.formats = __assign(__assign({}, defaultFormats), formats); | ||
this.formats = Object.assign({}, defaultFormats, formats); | ||
} | ||
DayjsUtils.prototype.is12HourCycleInCurrentLocale = function () { | ||
var _a, _b; | ||
/* istanbul ignore next */ | ||
return /A|a/.test((_b = (_a = this.rawDayJsInstance.Ls[this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT); | ||
}; | ||
DayjsUtils.prototype.getCurrentLocaleCode = function () { | ||
return this.locale || "en"; | ||
}; | ||
DayjsUtils.prototype.parse = function (value, format) { | ||
@@ -50,0 +61,0 @@ if (value === "") { |
@@ -5,9 +5,8 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
var defaultDayjs = _interopDefault(require('dayjs')); | ||
var customParseFormat = _interopDefault(require('dayjs/plugin/customParseFormat')); | ||
var advancedFormat = _interopDefault(require('dayjs/plugin/advancedFormat')); | ||
var customParseFormatPlugin = _interopDefault(require('dayjs/plugin/customParseFormat')); | ||
var localizedFormatPlugin = _interopDefault(require('dayjs/plugin/localizedFormat')); | ||
defaultDayjs.extend(customParseFormat); | ||
defaultDayjs.extend(advancedFormat); | ||
defaultDayjs.extend(customParseFormatPlugin); | ||
defaultDayjs.extend(localizedFormatPlugin); | ||
var withLocale = function (dayjs, locale) { | ||
@@ -23,5 +22,4 @@ return !locale ? dayjs : function () { | ||
var defaultFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM D", | ||
shortDate: "MMM D", | ||
shortDate: "DD MMMM", | ||
monthAndDate: "MMMM D", | ||
@@ -37,9 +35,13 @@ dayOfMonth: "D", | ||
seconds: "ss", | ||
fullTime: "LT", | ||
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" | ||
fullDate: "ll", | ||
fullDateTime: "lll", | ||
fullDateTime12h: "ll hh:mm A", | ||
fullDateTime24h: "ll HH:mm", | ||
keyboardDate: "L", | ||
keyboardDateTime: "L LT", | ||
keyboardDateTime12h: "L hh:mm A", | ||
keyboardDateTime24h: "L HH:mm" | ||
}; | ||
@@ -49,6 +51,15 @@ var DayjsUtils = /** @class */ (function () { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.rawDayJsInstance = instance || defaultDayjs; | ||
this.dayjs = withLocale(this.rawDayJsInstance, locale); | ||
this.locale = locale; | ||
this.formats = tslib.__assign(tslib.__assign({}, defaultFormats), formats); | ||
this.formats = Object.assign({}, defaultFormats, formats); | ||
} | ||
DayjsUtils.prototype.is12HourCycleInCurrentLocale = function () { | ||
var _a, _b; | ||
/* istanbul ignore next */ | ||
return /A|a/.test((_b = (_a = this.rawDayJsInstance.Ls[this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats) === null || _b === void 0 ? void 0 : _b.LT); | ||
}; | ||
DayjsUtils.prototype.getCurrentLocaleCode = function () { | ||
return this.locale || "en"; | ||
}; | ||
DayjsUtils.prototype.parse = function (value, format) { | ||
@@ -55,0 +66,0 @@ if (value === "") { |
{ | ||
"name": "@date-io/dayjs", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Abstraction over common javascript date management libraries", | ||
@@ -12,3 +12,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@date-io/core": "^2.0.0" | ||
"@date-io/core": "^2.1.0" | ||
}, | ||
@@ -45,3 +45,3 @@ "devDependencies": { | ||
"license": "MIT", | ||
"gitHead": "4d4dc93068fce81e887a8e1771fc20984e915556" | ||
"gitHead": "7589b2f00ad970ae4c835b7fd4c195fa3dc38615" | ||
} |
import defaultDayjs from "dayjs"; | ||
import customParseFormat from "dayjs/plugin/customParseFormat"; | ||
import advancedFormat from "dayjs/plugin/advancedFormat"; | ||
import customParseFormatPlugin from "dayjs/plugin/customParseFormat"; | ||
import localizedFormatPlugin from "dayjs/plugin/localizedFormat"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
defaultDayjs.extend(customParseFormat); | ||
defaultDayjs.extend(advancedFormat); | ||
defaultDayjs.extend(customParseFormatPlugin); | ||
defaultDayjs.extend(localizedFormatPlugin); | ||
@@ -23,5 +23,4 @@ interface Opts { | ||
const defaultFormats: DateIOFormats = { | ||
fullDate: "YYYY, MMMM Do", | ||
normalDate: "ddd, MMM D", | ||
shortDate: "MMM D", | ||
shortDate: "DD MMMM", | ||
monthAndDate: "MMMM D", | ||
@@ -37,12 +36,25 @@ dayOfMonth: "D", | ||
seconds: "ss", | ||
fullTime: "LT", | ||
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" | ||
fullDate: "ll", | ||
fullDateTime: "lll", | ||
fullDateTime12h: "ll hh:mm A", | ||
fullDateTime24h: "ll HH:mm", | ||
keyboardDate: "L", | ||
keyboardDateTime: "L LT", | ||
keyboardDateTime12h: "L hh:mm A", | ||
keyboardDateTime24h: "L HH:mm" | ||
}; | ||
const localizedFormats = { | ||
fullTime12h: "LT", | ||
fullTime24h: "LT", | ||
keyboardDate: "L", | ||
keyboardDateTime12h: "L LT", | ||
keyboardDateTime24h: "L LT" | ||
}; | ||
export default class DayjsUtils implements IUtils<defaultDayjs.Dayjs> { | ||
public rawDayJsInstance: typeof defaultDayjs; | ||
public dayjs: Constructor; | ||
@@ -53,11 +65,18 @@ public locale?: string; | ||
constructor({ locale, formats, instance }: Opts = {}) { | ||
this.dayjs = withLocale(instance || defaultDayjs, locale); | ||
this.rawDayJsInstance = instance || defaultDayjs; | ||
this.dayjs = withLocale(this.rawDayJsInstance, locale); | ||
this.locale = locale; | ||
this.formats = { | ||
...defaultFormats, | ||
...formats | ||
}; | ||
this.formats = Object.assign({}, defaultFormats, formats); | ||
} | ||
public is12HourCycleInCurrentLocale() { | ||
/* istanbul ignore next */ | ||
return /A|a/.test(this.rawDayJsInstance.Ls[this.locale || "en"]?.formats?.LT); | ||
} | ||
public getCurrentLocaleCode() { | ||
return this.locale || "en"; | ||
} | ||
public parse(value: any, format: any) { | ||
@@ -64,0 +83,0 @@ if (value === "") { |
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
29837
786
Updated@date-io/core@^2.1.0