fenextjs-date
Advanced tools
Comparing version 1.2.0 to 2.0.0
export interface FenextjsDateFormatOptions extends Intl.DateTimeFormatOptions { | ||
locales?: string | string[] | undefined; | ||
} | ||
export type FenextjsDateFormats<F extends string> = { | ||
[id in F]?: FenextjsDateFormatOptions; | ||
export type FenextjsDateFormats = { | ||
[id: string]: FenextjsDateFormatOptions; | ||
}; | ||
export interface FenextjsDateProps<F extends string> { | ||
export interface FenextjsDateProps { | ||
defaultDate?: Date; | ||
formats?: FenextjsDateFormats<F>; | ||
onCallback?: (date: FenextjsDate<F>) => void; | ||
formats?: FenextjsDateFormats; | ||
onCallback?: (date: Date) => void; | ||
} | ||
export type FenextjsDateValue = Date | number | string; | ||
export type FenextjsDateConstructor<F extends string> = FenextjsDateValue | FenextjsDateProps<F>; | ||
export declare class FenextjsDate<F extends string> extends Date { | ||
export type FenextjsDateConstructor = FenextjsDateValue | FenextjsDateProps; | ||
export declare class FenextjsDate { | ||
date: Date; | ||
private formats; | ||
@@ -19,4 +20,4 @@ private onCallback; | ||
private DateByCalendar; | ||
constructor(options?: FenextjsDateConstructor<F>); | ||
setOnCallback(callback: (date: FenextjsDate<F>) => void): void; | ||
constructor(options?: FenextjsDateConstructor); | ||
setOnCallback(callback: (date: Date) => void): void; | ||
addTime(time: number): void; | ||
@@ -31,3 +32,3 @@ addMilliseconds(milliseconds: number): void; | ||
onFormat(options: FenextjsDateFormatOptions, date?: FenextjsDateValue): string; | ||
onFormatId(id: keyof F, date?: FenextjsDateValue): string; | ||
onFormatId(id: string, date?: FenextjsDateValue): string; | ||
getDateByMonth(): Date[]; | ||
@@ -34,0 +35,0 @@ setDateByMonth(DateByMonth: Date[]): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FenextjsDate = void 0; | ||
class FenextjsDate extends Date { | ||
class FenextjsDate { | ||
date; | ||
formats = {}; | ||
@@ -20,3 +21,3 @@ onCallback = undefined; | ||
} | ||
super(date); | ||
this.date = date; | ||
if (!isDate) { | ||
@@ -31,39 +32,39 @@ this.formats = options?.formats ?? {}; | ||
addTime(time) { | ||
this.setTime(this.getTime() + time); | ||
this.onCallback?.(this); | ||
this.date.setTime(this.date.getTime() + time); | ||
this.onCallback?.(this.date); | ||
} | ||
addMilliseconds(milliseconds) { | ||
this.setMilliseconds(this.getMilliseconds() + milliseconds); | ||
this.onCallback?.(this); | ||
this.date.setMilliseconds(this.date.getMilliseconds() + milliseconds); | ||
this.onCallback?.(this.date); | ||
} | ||
addSeconds(seconds) { | ||
this.setSeconds(this.getSeconds() + seconds); | ||
this.onCallback?.(this); | ||
this.date.setSeconds(this.date.getSeconds() + seconds); | ||
this.onCallback?.(this.date); | ||
} | ||
addMinutes(minutes) { | ||
this.setMinutes(this.getMinutes() + minutes); | ||
this.onCallback?.(this); | ||
this.date.setMinutes(this.date.getMinutes() + minutes); | ||
this.onCallback?.(this.date); | ||
} | ||
addHours(hours) { | ||
this.setHours(this.getHours() + hours); | ||
this.onCallback?.(this); | ||
this.date.setHours(this.date.getHours() + hours); | ||
this.onCallback?.(this.date); | ||
} | ||
addDate(date) { | ||
this.setDate(this.getDate() + date); | ||
this.onCallback?.(this); | ||
this.date.setDate(this.date.getDate() + date); | ||
this.onCallback?.(this.date); | ||
} | ||
addMonth(month) { | ||
this.setMonth(this.getMonth() + month); | ||
this.onCallback?.(this); | ||
this.date.setMonth(this.date.getMonth() + month); | ||
this.onCallback?.(this.date); | ||
} | ||
addYear(year) { | ||
this.setFullYear(this.getFullYear() + year); | ||
this.onCallback?.(this); | ||
this.date.setFullYear(this.date.getFullYear() + year); | ||
this.onCallback?.(this.date); | ||
} | ||
onFormat(options, date) { | ||
const formatter = new Intl.DateTimeFormat(options?.locales, options); | ||
return formatter.format(new Date(date ?? this)); | ||
return formatter.format(new Date(date ?? this.date)); | ||
} | ||
onFormatId(id, date) { | ||
return this.onFormat(this.formats?.[id] ?? {}, date); | ||
return this.onFormat(this.formats?.[id] ?? {}, date ?? this.date); | ||
} | ||
@@ -77,3 +78,3 @@ getDateByMonth() { | ||
onGenerateDateByMonth(date) { | ||
const DATE = new Date(date ?? this.getTime()); | ||
const DATE = new Date(date ?? this.date.getTime()); | ||
DATE.setDate(1); | ||
@@ -96,3 +97,3 @@ const MONTH = DATE.getMonth(); | ||
onGenerateDateByCalendar(date) { | ||
const D = new Date(date ?? this.getTime()); | ||
const D = new Date(date ?? this.date); | ||
const DATE = new Date(D.getTime()); | ||
@@ -99,0 +100,0 @@ DATE.setDate(1); |
{ | ||
"name": "fenextjs-date", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
Sorry, the diff of this file is not supported yet
11729
158