Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect format() output after using utcOffset(0, true) #2799

Open
iHaPBoy opened this issue Jan 2, 2025 · 0 comments
Open

Incorrect format() output after using utcOffset(0, true) #2799

iHaPBoy opened this issue Jan 2, 2025 · 0 comments

Comments

@iHaPBoy
Copy link

iHaPBoy commented Jan 2, 2025

Describe the bug

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

dayjs.extend(utc);

const timezoneOffset = 0;
const startDate = dayjs('2025-01-06', 'YYYY-MM-DD').utcOffset(timezoneOffset, true);
const endDate = dayjs('2025-01-09', 'YYYY-MM-DD').utcOffset(timezoneOffset, true);
let d = startDate;
while (!d.isAfter(endDate)) {
  console.log('date', d.toISOString(), d.utcOffset(), d.format('YYYY-MM-DD'));
  d = d.add(1, 'day');
}

output:

date 2025-01-06T00:00:00.000Z 0 2025-01-06
date 2025-01-07T00:00:00.000Z 0 2025-01-06
date 2025-01-08T00:00:00.000Z 0 2025-01-07
date 2025-01-09T00:00:00.000Z 0 2025-01-08

Expected behavior

date 2025-01-06T00:00:00.000Z 0 2025-01-06
date 2025-01-07T00:00:00.000Z 0 2025-01-07
date 2025-01-08T00:00:00.000Z 0 2025-01-08
date 2025-01-09T00:00:00.000Z 0 2025-01-09

Information

  • Day.js Version v1.11.13
  • OS: macOS
  • Node.js v20.12.0
  • Time zone: UTC+8
@iHaPBoy iHaPBoy changed the title Incorrect format() output after using utcOffset() Incorrect format() output after using utcOffset(0, true) Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant