iamkun / iamkun/dayjs

DayJS giving wrong output on GMT

Open
#2,042 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

I am trying to convert different times from different zones into GMT. This will allow me to send them notifications according to their time zone. I noticed it worked perfectly for other time zones, but when I passed GMT or UTC, it gave the wrong time.

```js
const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
const timezone = require("dayjs/plugin/timezone");

dayjs.extend(utc);
dayjs.extend(timezone);

let zone = "UTC";
let hrs = 10;
let mins = 0;

const zoneTimeInGMT =
dayjs()
.tz(zone)
.hour(hrs)
.minute(mins)
.utc()
.format("dddd MMMM DD YYYY HH:mm:ss") + " GMT";

console.log({ zoneTimeInGMT });
```
image

For other timezones

```js
let zone = "America/New_York";
let hrs = 10;
let mins = 0;

const zoneTimeInGMT =
dayjs()
.tz(zone)
.hour(hrs)
.minute(mins)
.utc()
.format("dddd MMMM DD YYYY HH:mm:ss") + " GMT";

console.log({ zoneTimeInGMT });
```
image

Contributor guide

Open the contributing guide

Research direction

Reproduce the UTC and America/New_York snippets using the utc and timezone plugin entry points. Compare the formatted UTC result with the requested 10:00 time, then trace how the timezone conversion handles the UTC zone. Done means the UTC case produces the correct GMT time without regressing other zones.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.