Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shorthand units to UnitType #470

Merged
merged 2 commits into from
Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ declare namespace dayjs {

export type OptionType = { locale: string }

export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'quarter' | 'year' | 'date' | UnitTypeShort;

type OpUnitTypeShort = 'w'
export type OpUnitType = UnitType | "week" | OpUnitTypeShort;

interface DayjsObject {
years: number
Expand Down Expand Up @@ -44,17 +48,17 @@ declare namespace dayjs {

set(unit: UnitType, value: number): Dayjs

add(value: number, unit: UnitType): Dayjs
add(value: number, unit: OpUnitType): Dayjs

subtract(value: number, unit: UnitType): Dayjs
subtract(value: number, unit: OpUnitType): Dayjs

startOf(unit: UnitType): Dayjs
startOf(unit: OpUnitType): Dayjs

endOf(unit: UnitType): Dayjs
endOf(unit: OpUnitType): Dayjs

format(template?: string): string

diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number
diff(dayjs: Dayjs, unit: OpUnitType, float?: boolean): number

valueOf(): number

Expand All @@ -74,11 +78,11 @@ declare namespace dayjs {

toString(): string

isBefore(dayjs: Dayjs, unit?: UnitType): boolean
isBefore(dayjs: Dayjs, unit?: OpUnitType): boolean

isSame(dayjs: Dayjs, unit?: UnitType): boolean
isSame(dayjs: Dayjs, unit?: OpUnitType): boolean

isAfter(dayjs: Dayjs, unit?: UnitType): boolean
isAfter(dayjs: Dayjs, unit?: OpUnitType): boolean

isLeapYear(): boolean

Expand Down