Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Time Field with Different Model & View Timezones Behaves Differently During Daylight Savings Time #18366

Closed
@chrisguitarguy

Description

@chrisguitarguy

Let's say you add a time field like this:

/** @var FormBuilderInterface $builder */
$builder->add('time', TimeTime::class, [
  'model_timezone' => 'UTC',
  'view_timezone' => 'America/New_York',
]);

So users are entering the "time" field in their local time. Right now (2016-03-30) this happens to be during daylight savings time in (most of) the US: UTC is four hours ahead.

Saving the form with a time value of 1AM, I would expect the UTC time to be 5am. Instead it comes back as 6am because the model transformer uses 1970-01-01 as the date (not during DST).

I'm not sure if this is actually a bug or not. The behavior makes sense when you look at it from the perspective of the field being time only without a frame of reference for the date -- it doesn't care about DST.

But the fact that it does conversion from one TZ to another makes it a bit weird: the conversion doesn't act as expected.

Might be useful to pass a reference date to the form that the model transformer can use and default that value to 1970-01-01?

$builder->add('time', TimeTime::class, [
  'model_timezone' => 'UTC',
  'view_timezone' => 'America/New_York',
  'current_date' => new \DateTime('now'), // default to 1970-01-01
]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions