Skip to content

DateInput - incorrect timezone offset being applied #6421

@halocline

Description

@halocline

Expected Behavior

When defaultValue has no timezone, everything is returned without a timezone and is assumed to be local time. The value in state, input, and active calendar date should all display the same value.
Screen Shot 2022-10-13 at 11 21 45 PM

Actual Behavior

The value in state is not in sync with input and active calendar date.
Screen Shot 2022-10-13 at 11 23 27 PM

This is a similar issue to what is reported by #6356.

The fix provided in #6396 should be applied in a few other locations:

Since this logic is duplicated in multiple locations, consider moving to a single util function.

const adjustedDate = new Date(dateValue);
    // if time is not specified in ISOstring, normalize to midnight
    if (dateValue.indexOf('T') === -1) {
      const offset = adjustedDate.getTimezoneOffset();
      const hour = adjustedDate.getHours();
      adjustedDate.setHours(hour, offset < 0 ? -offset : offset);
    }
    result = adjustedDate;

URL, screen shot, or Codepen exhibiting the issue

Steps to Reproduce

  1. Use this story: https://storybook.grommet.io/?path=/story/input-dateinput-format-inline--format-inline
  2. Specifically scenarios 3 & 5
  3. Set OS timezone to IST.

Your Environment

  • Grommet version: 2.27.0
  • Browser Name and version: all
  • Operating System and version (desktop or mobile): MacOS 12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugissue that does not match design or documentation and requires code changes to addresshacktoberfestPRs submitted in October (open-source celebration month)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions