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

dayjs.tz().diff() different results on different local timezones #1224

Open
thekip opened this issue Nov 16, 2020 · 2 comments
Open

dayjs.tz().diff() different results on different local timezones #1224

thekip opened this issue Nov 16, 2020 · 2 comments

Comments

@thekip
Copy link

thekip commented Nov 16, 2020

Describe the bug

The test case

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

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

      dayjs.tz.setDefault('America/New_York');

      const startDate = dayjs.tz('2020-10-01');
      const endDate = dayjs.tz('2020-10-30');

      console.log({
        TZ: process.env.TZ,
        diff: endDate.diff(startDate, 'day'),
        start_date_c_month: startDate.toISOString(),
        end_date_c_month: endDate.toISOString(),
      });

Than run node.js with TZ environment var:

env TZ=UTC node test.js

    {
      TZ: 'UTC',
      diff: 29,
      start_date_c_month: '2020-10-01T04:00:00.000Z',
      end_date_c_month: '2020-10-30T04:00:00.000Z'
    }

#########

env TZ=CET node test.js

 console.log
    {
      TZ: 'CET',
      diff: 28,
      start_date_c_month: '2020-10-01T04:00:00.000Z',
      end_date_c_month: '2020-10-30T04:00:00.000Z'
    }

With different local timezone, Dayjs.diff produce different results even if timezone explicitly set.
Probably it just doesn't take timezone into account while calculation day boundaries.

I found this during development node.js application, but think that this could be reproduced in browser as well (but it's not easy to change a browser timezone on the fly)

possible related #1212

Expected behaviour
The results should be consistent and not depend on local timezone.

Information

  • Day.js Version 1.9.4
  • OS: macOs 10.15.7
  • Browser Node 12
  • Time zone: diffrent, see node invocations
@felipeclopes
Copy link

+1

1 similar comment
@RamiTae
Copy link

RamiTae commented Aug 3, 2022

+1

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

3 participants