Dayjs: `dayjs.tz()` needs to have timezone parameter as optional

Created on 25 Sep 2020  ยท  6Comments  ยท  Source: iamkun/dayjs

Describe the bug
Because you can set a default timezone, the dayjs.tz() method should have the second parameter (timezone) as optional. It works fine in JS โ€” just missing the correct types for TS.

Expected behavior

  1. Set dayjs.tz.setDefault("America/Phoenix");
  2. dayjs.tz('some valid date') <- that shouldn't throw a TypeScript error
  3. dayjs('some valid date').tz() <- that shouldn't throw a TypeScript error either

Potential Solution

declare module 'dayjs' {
  interface Dayjs {
    tz(timezone?: string): Dayjs;
  }

  interface DayjsTimezone {
    (date?: ConfigType, timezone?: string): Dayjs;
  }
}

Information

  • Day.js Version: v1.8.36
  • OS: macOS v10.15.6
  • Browser: Firefox Developer Edition v82.0b2
  • Time zone: America/Phoenix
released

Most helpful comment

:tada: This issue has been resolved in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

All 6 comments

True, would you like pulling request for this?

Looks like #1081 beat me to it ๐Ÿ˜…

Looks like #1081 beat me to it ๐Ÿ˜…

a-ha ๐Ÿ˜ฌ

Hey, sorry for just barging in and not asking if i could work on it. I was already inspecting the project and just checked the issues for motivation to dig in the source code and found this.

Sorry again

@gpetrioli hey, no worries ๐Ÿ˜„ Thanks for the PR. @iamkun any word on when the next release for the library is going to be?

:tada: This issue has been resolved in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sohailalam2 picture sohailalam2  ยท  4Comments

vaquel picture vaquel  ยท  3Comments

Wyzix33 picture Wyzix33  ยท  4Comments

dakshshah96 picture dakshshah96  ยท  5Comments

Sunrise1970 picture Sunrise1970  ยท  4Comments