startOf not working when the timezone is set to UTC+0:00
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When I set the timezone to Africa/Accra(UTC+00:00), the startOf function starts behaving weirdly.
Code
```
import './App.css';
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import { useState } from 'react';
dayjs.extend(timezone);
dayjs.extend(utc);
function App() {
const renderTime = (tz) => {
const inputDate = dayjs("2023-07-10 09:00:00").tz("Asia/Calcutta")
dayjs.tz.setDefault(tz)
const now = dayjs.tz(inputDate)
const date = now.format();
const startDate = now.startOf('d').format();
return {
date,
startDate
}
};
const {date, startDate} = renderTime('Africa/Accra')
const {date: date1, startDate: startDate1} = renderTime('Asia/Calcutta')
return (
Current time: {date}
Start time: {startDate}
Current time: {date1}
Start time: {startDate1}
);
}
export default App;
```
**Expected behavior**
The Start time in case of 'Africa/Accra' should be 2023-07-10T00:00:00Z and not 2023-07-09T18:30:00Z
**Information**
- Day.js Version 1.11.7
- OS: 13.4.1
- Browser: Version 114.0.5735.198 (Official Build) (arm64)
- Time zone: GMT+05:30
Contributor guide
Research direction
Start by reproducing the provided renderTime example with the timezone and utc plugins, comparing Africa/Accra and Asia/Calcutta. Trace the startOf('d') behavior through the timezone-related entry points and add a regression test for the expected Africa/Accra midnight result. Done means the reproduced case returns 2023-07-10T00:00:00Z without breaking the other timezone case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100