iamkun / iamkun/dayjs

Getting wrong date on startOf('day') in UTC timezone or any other with 0 offset

Open
#2,278 0 comments 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

**Describe the bug**
startOf('day') has the wrong date ( day of month ) value - minus one day, when the timezone is 0

```
import dayjs from 'dayjs';
var timezone = require('dayjs/plugin/timezone');
dayjs.extend(timezone);

// +0 - wrong, minus one day
const dayjsObj0 = dayjs.tz(new Date().getTime(), 'Africa/Abidjan');
const start0 = dayjsObj0.startOf('day');
console.log(dayjsObj0.date() === start0.date()) // false
console.log(dayjsObj0.date());
console.log(start0.date());

// +1 - correct
const dayjsObj1 = dayjs.tz(new Date().getTime(), 'Europe/London');
const start1 = dayjsObj1.startOf('day');
console.log(dayjsObj1.date() === start1.date()) // true

// +9 - correct
const dayjsObj2 = dayjs.tz(new Date().getTime(), 'Asia/Tokyo');
const start2 = dayjsObj2.startOf('day');
console.log(dayjsObj2.date() === start2.date()) // true

// -7 - correct
const dayjsObj3 = dayjs.tz(new Date().getTime(), 'America/Los_Angeles');
const start3 = dayjsObj3.startOf('day');
console.log(dayjsObj3.date() === start3.date()) // true

// 0 - wrong, minus one day
const dayjsObj4 = dayjs.tz(new Date().getTime(), 'UTC');
const start4 = dayjsObj4.startOf('day');
console.log(dayjsObj4.date() === start4.date()) // false
console.log(dayjsObj4.date());
console.log(start4.date());

// without tz - correct
const dayjsObj5 = dayjs();
const start5 = dayjsObj5.startOf('day');
console.log(dayjsObj5.date() === start5.date()) // true

```

**Expected behavior**
The day is not shifted back.

**Information**
- Day.js Version: 1.11.7
- OS: Windows
- Browser: Chrome 111
- Time zone: GMT+3

Example here - https://stackblitz.com/edit/dayjs-playground-qdinab?file=package.json,index.js

Contributor guide

Open the contributing guide

Research direction

Start with the timezone plugin and the startOf('day') path, using the supplied Africa/Abidjan and UTC reproductions as the first checks. The issue is done when startOf('day') preserves the date for zero-offset zones without regressing the positive, negative, or non-timezone cases shown.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.