iamkun/dayjs

`dayjs.tz()` needs to have timezone parameter as optional #1079

Miikis posted onGitHub

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

True, would you like pulling request for this?

posted by iamkun over 4 years ago

Looks like #1081 beat me to it 😅

posted by Miikis over 4 years ago

Looks like #1081 beat me to it 😅

a-ha 😬

posted by iamkun over 4 years ago

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

posted by gpetrioli over 4 years ago

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

posted by Miikis over 4 years ago

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

The release is available on:

Your semantic-release bot :package::rocket:

posted by iamkun over 4 years ago

Fund this Issue

$0.00
Funded

Pull requests