Skip to content

CustomParseFormat does't use a timezone #1750

Open
@tenorok

Description

@tenorok

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions