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

update locale types and add getTimezone from Dayjs instance #2704

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default (o, c, d) => {
return ins
}

proto.getTimezone = function () {
return this.$x.$timezone
}

proto.offsetName = function (type) {
// type: short(default) / long
const zone = this.$x.$timezone || d.tz.guess()
Expand Down
8 changes: 7 additions & 1 deletion types/locale/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ declare interface ILocale {
weekdays?: string[]
months?: string[]
weekStart?: number
yearStart?: number
weekdaysShort?: string[]
monthsShort?: string[]
weekdaysMin?: string[]
ordinal?: (n: number) => number | string
ordinal?: (n: number, period?: string) => number | string
formats: Partial<{
LT: string
LTS: string
L: string
LL: string
LLL: string
LLLL: string
l: string
ll: string
lll: string
llll: string
}>
relativeTime: Partial<{
future: string
Expand All @@ -30,4 +35,5 @@ declare interface ILocale {
y: string
yy: string
}>
meridiem?: (hour: number, minute: number) => string
}
1 change: 1 addition & 0 deletions types/plugin/timezone.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module 'dayjs' {
interface Dayjs {
tz(timezone?: string, keepLocalTime?: boolean): Dayjs
offsetName(type?: 'short' | 'long'): string | undefined
getTimezone(): string | undefined
}

interface DayjsTimezone {
Expand Down
4 changes: 3 additions & 1 deletion types/plugin/updateLocale.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference path="../locale/types.d.ts" />

import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
export function updateLocale(localeName: string, customConfig: Record<string, unknown>): Record<string, unknown>
export function updateLocale(localeName: string, customConfig: Partial<ILocale>): ILocale
}