iamkun / iamkun/dayjs

`dayjs("2013-11-18T11:55:20").tz("America/Toronto")` does not work

Open
#2,102 11 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
`dayjs("2013-11-18T11:55:20").tz("America/Toronto")` (as suggested in the [docs](https://day.js.org/docs/en/timezone/timezone)) outputs the following:

```js
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)

console.log(dayjs('2013-11-18T11:55:20').tz('America/Toronto'))

// Output
{
'$L': 'en',
'$d': Invalid Date,
'$x': { '$timezone': 'America/Toronto' },
'$y': NaN,
'$M': NaN,
'$D': NaN,
'$W': NaN,
'$H': NaN,
'$m': NaN,
'$s': NaN,
'$ms': NaN,
'$offset': NaN,
'$u': false
}
```

**Expected behavior**

The following should be the output:

```js
{
'$L': 'en',
'$d': 2013-11-18T10:55:20.000Z,
'$x': { '$localOffset': -60, '$timezone': 'America/Toronto' },
'$y': 2013,
'$M': 10,
'$D': 18,
'$W': 1,
'$H': 11,
'$m': 55,
'$s': 20,
'$ms': 0,
'$offset': -300
}
```

**Information**
- Day.js Version: `1.11.6`, `1.11.0`, `1.10.0`, `1.9.0` (it seems like the bug is in all versions since `utc` plugin was introduced)
- OS: [e.g. iOS]: Arch Linux
- Browser [e.g. chrome 62]: n/a
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]: tested with `America/Toronto` and `Europe/Slovakia`; I don’t think it matters;
- Node version: `19.0.0`
- NPM version: `8.19.2`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.