@date-io/moment
Advanced tools
Comparing version 1.3.13 to 2.0.0
@@ -0,15 +1,32 @@ | ||
import { __assign } from 'tslib'; | ||
import defaultMoment from 'moment'; | ||
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 MomentUtils = /** @class */ (function () { | ||
function MomentUtils(_a) { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, instance = _b.instance, moment = _b.moment; | ||
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.moment = instance || moment || defaultMoment; | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.moment = instance || defaultMoment; | ||
this.locale = locale; | ||
this.formats = __assign(__assign({}, defaultFormats), formats); | ||
} | ||
@@ -63,3 +80,6 @@ MomentUtils.prototype.parse = function (value, format) { | ||
}; | ||
MomentUtils.prototype.format = function (date, formatString) { | ||
MomentUtils.prototype.format = function (date, formatKey) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
}; | ||
MomentUtils.prototype.formatByString = function (date, formatString) { | ||
date.locale(this.locale); | ||
@@ -186,30 +206,2 @@ return date.format(formatString); | ||
}; | ||
// displaying methods | ||
MomentUtils.prototype.getCalendarHeaderText = function (date) { | ||
return this.format(date, this.yearMonthFormat); | ||
}; | ||
MomentUtils.prototype.getYearText = function (date) { | ||
return this.format(date, "YYYY"); | ||
}; | ||
MomentUtils.prototype.getDatePickerHeaderText = function (date) { | ||
return this.format(date, "ddd, MMM D"); | ||
}; | ||
MomentUtils.prototype.getDateTimePickerHeaderText = function (date) { | ||
return this.format(date, "MMM D"); | ||
}; | ||
MomentUtils.prototype.getMonthText = function (date) { | ||
return this.format(date, "MMMM"); | ||
}; | ||
MomentUtils.prototype.getDayText = function (date) { | ||
return this.format(date, "D"); | ||
}; | ||
MomentUtils.prototype.getHourText = function (date, ampm) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
}; | ||
MomentUtils.prototype.getMinuteText = function (date) { | ||
return this.format(date, "mm"); | ||
}; | ||
MomentUtils.prototype.getSecondText = function (date) { | ||
return this.format(date, "ss"); | ||
}; | ||
return MomentUtils; | ||
@@ -216,0 +208,0 @@ }()); |
@@ -5,16 +5,33 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
var defaultMoment = _interopDefault(require('moment')); | ||
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 MomentUtils = /** @class */ (function () { | ||
function MomentUtils(_a) { | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, instance = _b.instance, moment = _b.moment; | ||
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.moment = instance || moment || defaultMoment; | ||
var _b = _a === void 0 ? {} : _a, locale = _b.locale, formats = _b.formats, instance = _b.instance; | ||
this.moment = instance || defaultMoment; | ||
this.locale = locale; | ||
this.formats = tslib.__assign(tslib.__assign({}, defaultFormats), formats); | ||
} | ||
@@ -68,3 +85,6 @@ MomentUtils.prototype.parse = function (value, format) { | ||
}; | ||
MomentUtils.prototype.format = function (date, formatString) { | ||
MomentUtils.prototype.format = function (date, formatKey) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
}; | ||
MomentUtils.prototype.formatByString = function (date, formatString) { | ||
date.locale(this.locale); | ||
@@ -191,30 +211,2 @@ return date.format(formatString); | ||
}; | ||
// displaying methods | ||
MomentUtils.prototype.getCalendarHeaderText = function (date) { | ||
return this.format(date, this.yearMonthFormat); | ||
}; | ||
MomentUtils.prototype.getYearText = function (date) { | ||
return this.format(date, "YYYY"); | ||
}; | ||
MomentUtils.prototype.getDatePickerHeaderText = function (date) { | ||
return this.format(date, "ddd, MMM D"); | ||
}; | ||
MomentUtils.prototype.getDateTimePickerHeaderText = function (date) { | ||
return this.format(date, "MMM D"); | ||
}; | ||
MomentUtils.prototype.getMonthText = function (date) { | ||
return this.format(date, "MMMM"); | ||
}; | ||
MomentUtils.prototype.getDayText = function (date) { | ||
return this.format(date, "D"); | ||
}; | ||
MomentUtils.prototype.getHourText = function (date, ampm) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
}; | ||
MomentUtils.prototype.getMinuteText = function (date) { | ||
return this.format(date, "mm"); | ||
}; | ||
MomentUtils.prototype.getSecondText = function (date) { | ||
return this.format(date, "ss"); | ||
}; | ||
return MomentUtils; | ||
@@ -221,0 +213,0 @@ }()); |
import defaultMoment from "moment"; | ||
import { IUtils } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
interface Opts { | ||
locale?: string; | ||
instance?: typeof defaultMoment; | ||
/** @deprecated */ | ||
moment?: typeof defaultMoment; | ||
formats?: Partial<DateIOFormats>; | ||
} | ||
@@ -13,10 +12,4 @@ declare type Moment = defaultMoment.Moment; | ||
locale?: string; | ||
yearFormat: string; | ||
yearMonthFormat: string; | ||
dateTime12hFormat: string; | ||
dateTime24hFormat: string; | ||
time12hFormat: string; | ||
time24hFormat: string; | ||
dateFormat: string; | ||
constructor({ locale, instance, moment }?: Opts); | ||
formats: DateIOFormats; | ||
constructor({ locale, formats, instance }?: Opts); | ||
parse(value: string, format: string): defaultMoment.Moment; | ||
@@ -35,3 +28,4 @@ date(value?: any): defaultMoment.Moment; | ||
endOfDay(date: Moment): defaultMoment.Moment; | ||
format(date: Moment, formatString: string): string; | ||
format(date: Moment, formatKey: keyof DateIOFormats): string; | ||
formatByString(date: Moment, formatString: string): string; | ||
formatNumber(numberToFormat: string): string; | ||
@@ -64,12 +58,3 @@ getHours(date: Moment): number; | ||
getYearRange(start: Moment, end: Moment): defaultMoment.Moment[]; | ||
getCalendarHeaderText(date: Moment): string; | ||
getYearText(date: Moment): string; | ||
getDatePickerHeaderText(date: Moment): string; | ||
getDateTimePickerHeaderText(date: Moment): string; | ||
getMonthText(date: Moment): string; | ||
getDayText(date: Moment): string; | ||
getHourText(date: Moment, ampm: boolean): string; | ||
getMinuteText(date: Moment): string; | ||
getSecondText(date: Moment): string; | ||
} | ||
export {}; |
{ | ||
"name": "@date-io/moment", | ||
"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" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
"license": "MIT", | ||
"gitHead": "d105764c36b2021cde1fbcddd5445fed582a511c" | ||
"gitHead": "29c8f93efe8086a1b5ebb51b0a99d669219d4cbf" | ||
} |
import defaultMoment from "moment"; | ||
import { IUtils } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
@@ -7,30 +7,42 @@ interface Opts { | ||
instance?: typeof defaultMoment; | ||
/** @deprecated */ | ||
moment?: typeof defaultMoment; | ||
formats?: Partial<DateIOFormats>; | ||
} | ||
type Moment = defaultMoment.Moment; | ||
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 MomentUtils implements IUtils<defaultMoment.Moment> { | ||
public moment: typeof defaultMoment; | ||
public locale?: string; | ||
public formats: DateIOFormats; | ||
public yearFormat = "YYYY"; | ||
constructor({ locale, formats, instance }: Opts = {}) { | ||
this.moment = instance || defaultMoment; | ||
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, moment }: Opts = {}) { | ||
this.moment = instance || moment || defaultMoment; | ||
this.locale = locale; | ||
this.formats = { | ||
...defaultFormats, | ||
...formats | ||
}; | ||
} | ||
@@ -101,3 +113,7 @@ | ||
public format(date: Moment, formatString: string) { | ||
public format(date: Moment, formatKey: keyof DateIOFormats) { | ||
return this.formatByString(date, this.formats[formatKey]); | ||
} | ||
public formatByString(date: Moment, formatString: string) { | ||
date.locale(this.locale); | ||
@@ -263,39 +279,2 @@ return date.format(formatString); | ||
} | ||
// displaying methods | ||
public getCalendarHeaderText(date: Moment) { | ||
return this.format(date, this.yearMonthFormat); | ||
} | ||
public getYearText(date: Moment) { | ||
return this.format(date, "YYYY"); | ||
} | ||
public getDatePickerHeaderText(date: Moment) { | ||
return this.format(date, "ddd, MMM D"); | ||
} | ||
public getDateTimePickerHeaderText(date: Moment) { | ||
return this.format(date, "MMM D"); | ||
} | ||
public getMonthText(date: Moment) { | ||
return this.format(date, "MMMM"); | ||
} | ||
public getDayText(date: Moment) { | ||
return this.format(date, "D"); | ||
} | ||
public getHourText(date: Moment, ampm: boolean) { | ||
return this.format(date, ampm ? "hh" : "HH"); | ||
} | ||
public getMinuteText(date: Moment) { | ||
return this.format(date, "mm"); | ||
} | ||
public getSecondText(date: Moment) { | ||
return this.format(date, "ss"); | ||
} | ||
} |
26472
707
+ Added@date-io/core@2.17.0(transitive)
- Removed@date-io/core@1.3.13(transitive)
Updated@date-io/core@^2.0.0