@date-io/dayjs
Advanced tools
Comparing version 2.5.1 to 2.6.0
@@ -19,2 +19,3 @@ import defaultDayjs from "dayjs"; | ||
getCurrentLocaleCode(): string; | ||
getFormatHelperText(format: string): string; | ||
parse(value: any, format: any): defaultDayjs.Dayjs; | ||
@@ -21,0 +22,0 @@ date(value?: any): defaultDayjs.Dayjs; |
@@ -60,2 +60,21 @@ import defaultDayjs from 'dayjs'; | ||
}; | ||
DayjsUtils.prototype.getFormatHelperText = function (format) { | ||
var _this = this; | ||
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js | ||
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g; | ||
return format | ||
.match(localFormattingTokens) | ||
.map(function (token) { | ||
var _a, _b; | ||
var firstCharacter = token[0]; | ||
if (firstCharacter === "L") { | ||
/* istanbul ignore next */ | ||
return _b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token], (_b !== null && _b !== void 0 ? _b : token); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/a/gi, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
DayjsUtils.prototype.parse = function (value, format) { | ||
@@ -197,3 +216,6 @@ if (value === "") { | ||
DayjsUtils.prototype.mergeDateAndTime = function (date, time) { | ||
return this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)); | ||
return date | ||
.hour(time.hour()) | ||
.minute(time.minute()) | ||
.second(time.second()); | ||
}; | ||
@@ -200,0 +222,0 @@ DayjsUtils.prototype.getWeekdays = function () { |
@@ -64,2 +64,21 @@ 'use strict'; | ||
}; | ||
DayjsUtils.prototype.getFormatHelperText = function (format) { | ||
var _this = this; | ||
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js | ||
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g; | ||
return format | ||
.match(localFormattingTokens) | ||
.map(function (token) { | ||
var _a, _b; | ||
var firstCharacter = token[0]; | ||
if (firstCharacter === "L") { | ||
/* istanbul ignore next */ | ||
return _b = (_a = _this.rawDayJsInstance.Ls[_this.locale || "en"]) === null || _a === void 0 ? void 0 : _a.formats[token], (_b !== null && _b !== void 0 ? _b : token); | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/a/gi, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
}; | ||
DayjsUtils.prototype.parse = function (value, format) { | ||
@@ -201,3 +220,6 @@ if (value === "") { | ||
DayjsUtils.prototype.mergeDateAndTime = function (date, time) { | ||
return this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)); | ||
return date | ||
.hour(time.hour()) | ||
.minute(time.minute()) | ||
.second(time.second()); | ||
}; | ||
@@ -204,0 +226,0 @@ DayjsUtils.prototype.getWeekdays = function () { |
{ | ||
"name": "@date-io/dayjs", | ||
"version": "2.5.1", | ||
"version": "2.6.0", | ||
"description": "Abstraction over common javascript date management libraries", | ||
@@ -12,3 +12,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@date-io/core": "^2.5.0" | ||
"@date-io/core": "^2.6.0" | ||
}, | ||
@@ -45,3 +45,3 @@ "devDependencies": { | ||
"license": "MIT", | ||
"gitHead": "b7acda842159519578c0aa345e5c693232aacd03" | ||
"gitHead": "d6db25c9863530a6d5934a2f8b97b1f0162d967d" | ||
} |
@@ -82,2 +82,20 @@ import defaultDayjs from "dayjs"; | ||
public getFormatHelperText(format: string) { | ||
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js | ||
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g; | ||
return format | ||
.match(localFormattingTokens) | ||
.map(token => { | ||
var firstCharacter = token[0]; | ||
if (firstCharacter === "L") { | ||
/* istanbul ignore next */ | ||
return this.rawDayJsInstance.Ls[this.locale || "en"]?.formats[token] ?? token; | ||
} | ||
return token; | ||
}) | ||
.join("") | ||
.replace(/a/gi, "(a|p)m") | ||
.toLocaleLowerCase(); | ||
} | ||
public parse(value: any, format: any) { | ||
@@ -264,6 +282,6 @@ if (value === "") { | ||
public mergeDateAndTime(date: Dayjs, time: Dayjs) { | ||
return this.setMinutes( | ||
this.setHours(date, this.getHours(time)), | ||
this.getMinutes(time) | ||
); | ||
return date | ||
.hour(time.hour()) | ||
.minute(time.minute()) | ||
.second(time.second()); | ||
} | ||
@@ -270,0 +288,0 @@ |
34745
903
Updated@date-io/core@^2.6.0