question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
iamkuncommented, Sep 28, 2020

🎉 This issue has been resolved in version 1.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
iamkuncommented, Sep 26, 2020

True, would you like pulling request for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Time Zone
Day.js supports time zone via the Internationalization API in supported environments. By using the native API, no extra bytes of timezone data need...
Read more >
Dayjs format with timezone abbreviation i.e. 'z' like in moment.js
I have added the utc and timezone plugins and can't see any other plugins needed to make this work, I notice on Dayjs...
Read more >
Date.prototype.toLocaleTimeString() - JavaScript | MDN
The toLocaleTimeString() method returns a string with a language-sensitive representation of the time portion of the date.
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
now() to directly get the time stamp without having to create a new Date object. Parsing a Date. Converting a string to a...
Read more >
Class Dayjs - @formio/core
Parameters. Optional config: null | string | number | Date | Dayjs ... Still, dayjs#clone can create a clone of the current object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found