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

Fix Typescript definition to correctly reflect the usage #466

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
164 changes: 72 additions & 92 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,77 @@
export = dayjs;
export default dayjs

declare function dayjs (config?: dayjs.ConfigType, option?: dayjs.OptionType): dayjs.Dayjs
declare const dayjs: DayjsFn

declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs

export type OptionType = { locale: string }

export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'

interface DayjsObject {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

class Dayjs {
constructor (config?: ConfigType)

clone(): Dayjs

isValid(): boolean

year(): number

month(): number

date(): number

day(): number

hour(): number

minute(): number

second(): number

millisecond(): number

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

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

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

startOf(unit: UnitType): Dayjs

endOf(unit: UnitType): Dayjs

format(template?: string): string

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

valueOf(): number

unix(): number

daysInMonth(): number

toDate(): Date

toArray(): number[]

toJSON(): string

toISOString(): string

toObject(): DayjsObject

toString(): string

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

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

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

isLeapYear(): boolean

locale(arg1: any, arg2?: any): Dayjs
}

export type PluginFunc = (option: ConfigType, d1: Dayjs, d2: Dayjs) => void

export function extend(plugin: PluginFunc, option?: ConfigType): Dayjs
type DayjsFn = {
(config?: ConfigType, option?: OptionType): DayjsInstance
extend(plugin: PluginFunc, option?: ConfigType): DayjsInstance
locale(arg1: any, arg2?: any): string
isDayjs(d: any): d is DayjsInstance
unix(t: number): DayjsInstance
}

export function locale(arg1: any, arg2?: any): string
export type ConfigType = string | number | Date | DayjsInstance

export type OptionType = { locale: string }

export type UnitType =
| 'millisecond'
| 'second'
| 'minute'
| 'hour'
| 'day'
| 'week'
| 'month'
| 'quarter'
| 'year'
| 'date'

export type PluginFunc = (
option: ConfigType,
d1: DayjsInstance,
d2: DayjsInstance
) => void

export type DayjsPlainObject = {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

export function isDayjs(d: any): d is Dayjs

export function unix(t: number): Dayjs
export type DayjsInstance = {
clone(): DayjsInstance
isValid(): boolean
year(): number
month(): number
date(): number
day(): number
hour(): number
minute(): number
second(): number
millisecond(): number
set(unit: UnitType, value: number): DayjsInstance
add(value: number, unit: UnitType): DayjsInstance
subtract(value: number, unit: UnitType): DayjsInstance
startOf(unit: UnitType): DayjsInstance
endOf(unit: UnitType): DayjsInstance
format(template?: string): string
diff(dayjs: DayjsInstance, unit: UnitType, float?: boolean): number
valueOf(): number
unix(): number
daysInMonth(): number
toDate(): Date
toArray(): number[]
toJSON(): string
toISOString(): string
toObject(): DayjsPlainObject
toString(): string
isBefore(dayjs: DayjsInstance, unit?: UnitType): boolean
isSame(dayjs: DayjsInstance, unit?: UnitType): boolean
isAfter(dayjs: DayjsInstance, unit?: UnitType): boolean
isLeapYear(): boolean
locale(arg1: any, arg2?: any): DayjsInstance
}
27 changes: 27 additions & 0 deletions src/locale/cs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dayjs from 'dayjs'

const locale = {
name: 'cs',
weekdays: 'Neděle_Pondělí_Úterý_Středa_Čtvrtek_Pátek_Sobota'.split('_'),
months: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
relativeTime: {
future: 'za %s',
past: 'před %s',
s: 'několik sekund',
m: 'minuta',
mm: '%d minut',
h: 'hodina',
hh: '%d hodin',
d: 'den',
dd: '%d dnů',
M: 'měsíc',
MM: '%d měsíců',
y: 'rok',
yy: '%d roků'
},
ordinal: n => `${n}º`
}

dayjs.locale(locale, null, true)

export default locale