dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

CustomParseFormat does't use a timezone

Open tenorok opened this issue 4 years ago • 3 comments

Describe the bug

When using input format as array then output format does't take specified timezone.

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

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);
dayjs.tz.setDefault('Europe/Moscow');

// Incorrect, output:
// 31.05.2021 21:00
console.log(
    dayjs
        .tz('01.06.2021 00:00', ['DD.MM.YYYY HH:mm'], 'Europe/Moscow')
        .format('DD.MM.YYYY HH:mm'),
);

Expected behavior

When using just a string for input format the timezone takes correctly.

// Correct, output:
// 01.06.2021 00:00
console.log(
    dayjs
        .tz('01.06.2021 00:00', 'DD.MM.YYYY HH:mm', 'Europe/Moscow')
        .format('DD.MM.YYYY HH:mm'),
);

Information

  • Day.js Version: v1.10.7
  • OS: macOS 12.0.1 (21A559)
  • Browser: NodeJS v15.14.0
  • Time zone: GMT+03:00

Links

  • Doc about format: https://day.js.org/docs/en/parse/string-format
  • PR with supports of array for format: https://github.com/iamkun/dayjs/pull/906/files

tenorok avatar Dec 26 '21 12:12 tenorok

yes, I met the same problem. Any fix?

Haixing-Hu avatar Jan 10 '22 09:01 Haixing-Hu

I could reproduce the issue even with the current version (v1.11.2). I am preparing a PR for issue #1596, which solves even this problem. So I expect that this problem will be solved not too far in the future ;-)

BePo65 avatar May 25 '22 04:05 BePo65

https://github.com/iamkun/dayjs/issues/944 https://github.com/iamkun/dayjs/pull/1914 I hope that these issues, including this one, will be resolved.

usd-yamazaki avatar Dec 04 '25 09:12 usd-yamazaki