Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-29279

Inconsistencies in values displayed by Date Field Type

    Details

      Description

      There are some inconsistencies in values displayed by Date Field Types when using Legacy Bridge, between frontoffice and the backoffice and the legacy stack and the new stack. Or when having data from legacy (migration/upgrade).

      There are also issues in eZ Platform itself here overlapping with this covered in EZP-29136.

      Steps to reproduce

      1. Create new eZ Platform installation with Legacy Bridge. I have date.timezone setting in php.ini set to "Europe/Warsaw" and have the browser's timezone set analogically (this affects the results below, meaning that the displayed values might be different if using different timezones).
      2. In the app/config/ezplatform.yml, add the following configuration:

        ez_publish_legacy:
            system:
                ezdemo_site_clean_group:
                    templating:
                        view_layout: AppBundle::pagelayout.html.twig
        

      3. Create file src/AppBundle/Resources/views/pagelayout.html.twig with the following content:

        <!doctype html>
        <html>
        <body>
            <h1>The legacy generated content</h1>
            <div class="content">
                {% block content %}{% endblock %}
            </div>
            <h1>The new stack generated content (using ez_render_field)</h1>
            <div class="content">
                {{ ez_render_field(
                    content,
                    'date'
                ) }}
                {{ ez_render_field(
                    content,
                    'date_and_time'
                ) }}
            </div>
        </body>
        </html>
        

      4. Create a Content Type with a Date and DateAndTime Field Definitions. Put 'date' and 'date_and_time' as their identifiers, respectively.
      5. In the Legacy backoffice, create a Content Object of this Content Type, giving it a date value in one field (for example "01/06/2018") and date and time value in other field (for example "01/06/2018 12:00 pm").
      6. Check the values displayed for this Content Object:
        • In the Legacy backoffice, navigate to this Content Object. You should see its fields values displayed correctly:

          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          

        • In the Platform UI, navigate to this Content Object. You should see the following values (note the wrong value for Date Field Type):

          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          

        • In the frontoffice, navigate to this Content Object. If you display it using Legacy stack ("The legacy generated content"), you will see the following values (correct):

          01/06/2018
          01/06/2018 12:00 pm
          

        • If you display the same Content Object using ez_render_field ("The new stack generated content"), you will see the following values (note the wrong value for Date Field Type):

          31/05/2018
          01/06/2018, 12:00
          

      7. Now, after I change date.timezone setting in php.ini set to "America/Puerto_Rico" (without republishing the Content), I have the following results:
        • In the Legacy backoffice values are displayed like the following (the same as before):

          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          

        • In the Platform UI nothing changes (value for Date Field Type is still wrong):

          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          

        • In the frontoffice, using the Legacy stack, the values are the following (also the same as before):

          01/06/2018
          01/06/2018 12:00 pm
          

        • In the frontoffice, using the new stack, both values are different (the Date Field Type by 2 days, while Date and time by 6 hours):

          30/05/2018
          01/06/2018, 06:00
          

        Issue Links

          Activity

          Jacek Foremski (Inactive) created issue -
          Jacek Foremski (Inactive) made changes -
          Field Original Value New Value
          Link This issue relates to EZP-29136 [ EZP-29136 ]
          Jacek Foremski (Inactive) made changes -
          Link This issue relates to CS-6770 [ CS-6770 ]
          Jacek Foremski (Inactive) made changes -
          Status Open [ 1 ] Confirmed [ 10037 ]
          Jacek Foremski (Inactive) made changes -
          Status Confirmed [ 10037 ] InputQ [ 10001 ]
          André Rømcke made changes -
          Summary Inconsistencies in values displayed by Date and DateAndTime Field Types when using Legacy Bridge Inconsistencies in values displayed by Date and DateAndTime Field Types
          André Rømcke made changes -
          Description There are some inconsistencies in values displayed by Date and DateandTime Field Types when using Legacy Bridge, between frontoffice and the backoffice and the legacy stack and the new stack.

          *Steps to reproduce*
          # Create new eZ Platform installation with Legacy Bridge. I have {{date.timezone}} setting in php.ini set to {{"Europe/Warsaw"}} and have the browser's timezone set analogically (this affects the results below, meaning that the displayed values might be different if using different timezones).
          # In the {{app/config/ezplatform.yml}}, add the following configuration:
          {code}
          ez_publish_legacy:
              system:
                  ezdemo_site_clean_group:
                      templating:
                          view_layout: AppBundle::pagelayout.html.twig
          {code}
          # Create file {{src/AppBundle/Resources/views/pagelayout.html.twig}} with the following content:
          {code}
          <!doctype html>
          <html>
          <body>
              <h1>The legacy generated content</h1>
              <div class="content">
                  {% block content %}{% endblock %}
              </div>
              <h1>The new stack generated content (using ez_render_field)</h1>
              <div class="content">
                  {{ ez_render_field(
                      content,
                      'date'
                  ) }}
                  {{ ez_render_field(
                      content,
                      'date_and_time'
                  ) }}
              </div>
          </body>
          </html>
          {code}
          # Create a Content Type with a Date and DateAndTime Field Definitions. Put 'date' and 'date_and_time' as their identifiers, respectively.
          # In the Legacy backoffice, create a Content Object of this Content Type, giving it a date value in one field (for example "01/06/2018") and date and time value in other field (for example "01/06/2018 12:00 pm").
          # Check the values displayed for this Content Object:
          #* In the Legacy backoffice, navigate to this Content Object. You should see its fields values displayed correctly:
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI, navigate to this Content Object. You should see the following values (note the wrong value for Date Field Type):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, navigate to this Content Object. If you display it using Legacy stack ("The legacy generated content"), you will see the following values (correct):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* If you display the same Content Object using {{ez_render_field}} ("The new stack generated content"), you will see the following values (note the wrong value for Date Field Type):
          {code}
          31/05/2018
          01/06/2018, 12:00
          {code}
          # Now, after I change {{date.timezone}} setting in php.ini set to {{"America/Puerto_Rico"}} (without republishing the Content), I have the following results:
          #* In the Legacy backoffice values are displayed like the following (the same as before):
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI nothing changes (value for Date Field Type is still wrong):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, using the Legacy stack, the values are the following (also the same as before):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* In the frontoffice, using the new stack, both values are different (the Date Field Type by 2 days, while Date and time by 6 hours):
          {code}
          30/05/2018
          01/06/2018, 06:00
          {code}
          There are some inconsistencies in values displayed by Date and DateandTime Field Types when using Legacy Bridge, between frontoffice and the backoffice and the legacy stack and the new stack. Or when having data from legacy _(migration/upgrade)_.

          There are also issues in eZ Platform itself here overlapping with this covered in EZP-29136.

          *Steps to reproduce*
          # Create new eZ Platform installation with Legacy Bridge. I have {{date.timezone}} setting in php.ini set to {{"Europe/Warsaw"}} and have the browser's timezone set analogically (this affects the results below, meaning that the displayed values might be different if using different timezones).
          # In the {{app/config/ezplatform.yml}}, add the following configuration:
          {code}
          ez_publish_legacy:
              system:
                  ezdemo_site_clean_group:
                      templating:
                          view_layout: AppBundle::pagelayout.html.twig
          {code}
          # Create file {{src/AppBundle/Resources/views/pagelayout.html.twig}} with the following content:
          {code}
          <!doctype html>
          <html>
          <body>
              <h1>The legacy generated content</h1>
              <div class="content">
                  {% block content %}{% endblock %}
              </div>
              <h1>The new stack generated content (using ez_render_field)</h1>
              <div class="content">
                  {{ ez_render_field(
                      content,
                      'date'
                  ) }}
                  {{ ez_render_field(
                      content,
                      'date_and_time'
                  ) }}
              </div>
          </body>
          </html>
          {code}
          # Create a Content Type with a Date and DateAndTime Field Definitions. Put 'date' and 'date_and_time' as their identifiers, respectively.
          # In the Legacy backoffice, create a Content Object of this Content Type, giving it a date value in one field (for example "01/06/2018") and date and time value in other field (for example "01/06/2018 12:00 pm").
          # Check the values displayed for this Content Object:
          #* In the Legacy backoffice, navigate to this Content Object. You should see its fields values displayed correctly:
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI, navigate to this Content Object. You should see the following values (note the wrong value for Date Field Type):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, navigate to this Content Object. If you display it using Legacy stack ("The legacy generated content"), you will see the following values (correct):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* If you display the same Content Object using {{ez_render_field}} ("The new stack generated content"), you will see the following values (note the wrong value for Date Field Type):
          {code}
          31/05/2018
          01/06/2018, 12:00
          {code}
          # Now, after I change {{date.timezone}} setting in php.ini set to {{"America/Puerto_Rico"}} (without republishing the Content), I have the following results:
          #* In the Legacy backoffice values are displayed like the following (the same as before):
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI nothing changes (value for Date Field Type is still wrong):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, using the Legacy stack, the values are the following (also the same as before):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* In the frontoffice, using the new stack, both values are different (the Date Field Type by 2 days, while Date and time by 6 hours):
          {code}
          30/05/2018
          01/06/2018, 06:00
          {code}
          Hide
          Bertrand Dunogier added a comment - - edited

          I've had a look at the code involved in rendering those values in the kernel. In content_fields.html.twig, we use the localized_date filter for all fieldtypes (date, time and date time). One difference is that for time, UTC is passed as the timezone parameter, while no value is specified for date and datetime.

          Show
          Bertrand Dunogier added a comment - - edited I've had a look at the code involved in rendering those values in the kernel. In content_fields.html.twig , we use the localized_date filter for all fieldtypes (date, time and date time). One difference is that for time, UTC is passed as the timezone parameter , while no value is specified for date and datetime.
          Mateusz Bieniek made changes -
          Assignee Mateusz Bieniek [ mateusz.biniek@ez.no ]
          André Rømcke made changes -
          Link This issue is cloned by EZP-29545 [ EZP-29545 ]
          André Rømcke made changes -
          Summary Inconsistencies in values displayed by Date and DateAndTime Field Types Inconsistencies in values displayed by DateAndTime Field Types
          André Rømcke made changes -
          Summary Inconsistencies in values displayed by DateAndTime Field Types Inconsistencies in values displayed by Date Field Types
          André Rømcke made changes -
          Summary Inconsistencies in values displayed by Date Field Types Inconsistencies in values displayed by Date Field Type
          André Rømcke made changes -
          Description There are some inconsistencies in values displayed by Date and DateandTime Field Types when using Legacy Bridge, between frontoffice and the backoffice and the legacy stack and the new stack. Or when having data from legacy _(migration/upgrade)_.

          There are also issues in eZ Platform itself here overlapping with this covered in EZP-29136.

          *Steps to reproduce*
          # Create new eZ Platform installation with Legacy Bridge. I have {{date.timezone}} setting in php.ini set to {{"Europe/Warsaw"}} and have the browser's timezone set analogically (this affects the results below, meaning that the displayed values might be different if using different timezones).
          # In the {{app/config/ezplatform.yml}}, add the following configuration:
          {code}
          ez_publish_legacy:
              system:
                  ezdemo_site_clean_group:
                      templating:
                          view_layout: AppBundle::pagelayout.html.twig
          {code}
          # Create file {{src/AppBundle/Resources/views/pagelayout.html.twig}} with the following content:
          {code}
          <!doctype html>
          <html>
          <body>
              <h1>The legacy generated content</h1>
              <div class="content">
                  {% block content %}{% endblock %}
              </div>
              <h1>The new stack generated content (using ez_render_field)</h1>
              <div class="content">
                  {{ ez_render_field(
                      content,
                      'date'
                  ) }}
                  {{ ez_render_field(
                      content,
                      'date_and_time'
                  ) }}
              </div>
          </body>
          </html>
          {code}
          # Create a Content Type with a Date and DateAndTime Field Definitions. Put 'date' and 'date_and_time' as their identifiers, respectively.
          # In the Legacy backoffice, create a Content Object of this Content Type, giving it a date value in one field (for example "01/06/2018") and date and time value in other field (for example "01/06/2018 12:00 pm").
          # Check the values displayed for this Content Object:
          #* In the Legacy backoffice, navigate to this Content Object. You should see its fields values displayed correctly:
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI, navigate to this Content Object. You should see the following values (note the wrong value for Date Field Type):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, navigate to this Content Object. If you display it using Legacy stack ("The legacy generated content"), you will see the following values (correct):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* If you display the same Content Object using {{ez_render_field}} ("The new stack generated content"), you will see the following values (note the wrong value for Date Field Type):
          {code}
          31/05/2018
          01/06/2018, 12:00
          {code}
          # Now, after I change {{date.timezone}} setting in php.ini set to {{"America/Puerto_Rico"}} (without republishing the Content), I have the following results:
          #* In the Legacy backoffice values are displayed like the following (the same as before):
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI nothing changes (value for Date Field Type is still wrong):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, using the Legacy stack, the values are the following (also the same as before):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* In the frontoffice, using the new stack, both values are different (the Date Field Type by 2 days, while Date and time by 6 hours):
          {code}
          30/05/2018
          01/06/2018, 06:00
          {code}
          There are some inconsistencies in values displayed by Date Field Types when using Legacy Bridge, between frontoffice and the backoffice and the legacy stack and the new stack. Or when having data from legacy _(migration/upgrade)_.

          There are also issues in eZ Platform itself here overlapping with this covered in EZP-29136.

          *Steps to reproduce*
          # Create new eZ Platform installation with Legacy Bridge. I have {{date.timezone}} setting in php.ini set to {{"Europe/Warsaw"}} and have the browser's timezone set analogically (this affects the results below, meaning that the displayed values might be different if using different timezones).
          # In the {{app/config/ezplatform.yml}}, add the following configuration:
          {code}
          ez_publish_legacy:
              system:
                  ezdemo_site_clean_group:
                      templating:
                          view_layout: AppBundle::pagelayout.html.twig
          {code}
          # Create file {{src/AppBundle/Resources/views/pagelayout.html.twig}} with the following content:
          {code}
          <!doctype html>
          <html>
          <body>
              <h1>The legacy generated content</h1>
              <div class="content">
                  {% block content %}{% endblock %}
              </div>
              <h1>The new stack generated content (using ez_render_field)</h1>
              <div class="content">
                  {{ ez_render_field(
                      content,
                      'date'
                  ) }}
                  {{ ez_render_field(
                      content,
                      'date_and_time'
                  ) }}
              </div>
          </body>
          </html>
          {code}
          # Create a Content Type with a Date and DateAndTime Field Definitions. Put 'date' and 'date_and_time' as their identifiers, respectively.
          # In the Legacy backoffice, create a Content Object of this Content Type, giving it a date value in one field (for example "01/06/2018") and date and time value in other field (for example "01/06/2018 12:00 pm").
          # Check the values displayed for this Content Object:
          #* In the Legacy backoffice, navigate to this Content Object. You should see its fields values displayed correctly:
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI, navigate to this Content Object. You should see the following values (note the wrong value for Date Field Type):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, navigate to this Content Object. If you display it using Legacy stack ("The legacy generated content"), you will see the following values (correct):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* If you display the same Content Object using {{ez_render_field}} ("The new stack generated content"), you will see the following values (note the wrong value for Date Field Type):
          {code}
          31/05/2018
          01/06/2018, 12:00
          {code}
          # Now, after I change {{date.timezone}} setting in php.ini set to {{"America/Puerto_Rico"}} (without republishing the Content), I have the following results:
          #* In the Legacy backoffice values are displayed like the following (the same as before):
          {code}
          Date:
          01/06/2018
          Date and time:
          01/06/2018 12:00 pm
          {code}
          #* In the Platform UI nothing changes (value for Date Field Type is still wrong):
          {code}
          Date
          31 May 2018
          Date and time
          1 June 2018, 12:00
          {code}
          #* In the frontoffice, using the Legacy stack, the values are the following (also the same as before):
          {code}
          01/06/2018
          01/06/2018 12:00 pm
          {code}
          #* In the frontoffice, using the new stack, both values are different (the Date Field Type by 2 days, while Date and time by 6 hours):
          {code}
          30/05/2018
          01/06/2018, 06:00
          {code}
          Hide
          André Rømcke added a comment - - edited

          NOTE: This issue was split in two, so this is now only covering Date field type, while DateTime is moved to EZP-29545 as it has somewhat different issue and will need different handling.

          Show
          André Rømcke added a comment - - edited NOTE: This issue was split in two, so this is now only covering Date field type, while DateTime is moved to EZP-29545 as it has somewhat different issue and will need different handling.
          Mateusz Bieniek made changes -
          Affects Version/s 2.2.2 [ 15010 ]
          Affects Version/s 1.7.8 [ 14923 ]
          Affects Version/s 5.4.12 [ 14877 ]
          Mateusz Bieniek made changes -
          Link This issue relates to CS-6983 [ CS-6983 ]
          Mateusz Bieniek made changes -
          Status InputQ [ 10001 ] Development [ 3 ]
          Mateusz Bieniek made changes -
          Status Development [ 3 ] Development Review [ 10006 ]
          Hide
          Mateusz Bieniek added a comment - - edited

          PRs:

          For v1:

          For v2:

          For Legacy:

          Show
          Mateusz Bieniek added a comment - - edited PRs: For v1: Frontend fix from here: https://github.com/ezsystems/ezpublish-kernel/pull/2422 (merged) Backend fix from here: https://github.com/ezsystems/PlatformUIBundle/pull/984 (merged) For v2: Frontend fix from here: https://github.com/ezsystems/ezpublish-kernel/pull/2422 (merged) Backend fix from here: https://github.com/ezsystems/ezplatform-admin-ui/pull/598 (merged) For Legacy: Legacy timestamp fix here: https://github.com/ezsystems/ezpublish-legacy/pull/1401 (merged) Migration script here: https://github.com/ezsystems/ezpublish-kernel/pull/2499 (merged)
          André Rømcke made changes -
          Status Development Review [ 10006 ] Documentation Review done [ 10011 ]
          Assignee Mateusz Bieniek [ mateusz.biniek@ez.no ]
          Hide
          Jérôme Vieilledent added a comment -

          While I see the point of PRs mentioned above, by enforcing the use of UTC in legacy and kernel, I can propose a different approach, which can be considered as a workaround.

          namespace eZ\Publish\Core\FieldType\Date;
           
          class Value extends BaseValue
          {
              // ...
              public static function fromTimestamp($timestamp)
              {
                  try {
                      $dateTime = new DateTime("@{$timestamp}");
                      $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
                      return new static($dateTime);
                  } catch (Exception $e) {
                      throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
                  }
              }
          }
          

          The only addition is $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));.
          Since admin and front office are (supposedly) in the same timezone, configured in php.ini (or overriden elsewhere, it doesn't matter), then we'll have the expected date to display.

          Being a workaround, it won't replace the real fix, but can at least be shipped in a maintenance release I guess.

          WDYT?

          Show
          Jérôme Vieilledent added a comment - While I see the point of PRs mentioned above, by enforcing the use of UTC in legacy and kernel, I can propose a different approach, which can be considered as a workaround. namespace eZ\Publish\Core\FieldType\Date;   class Value extends BaseValue { // ... public static function fromTimestamp($timestamp) { try { $dateTime = new DateTime("@{$timestamp}"); $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get())); return new static($dateTime); } catch (Exception $e) { throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e); } } } The only addition is $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get())); . Since admin and front office are (supposedly) in the same timezone, configured in php.ini (or overriden elsewhere, it doesn't matter), then we'll have the expected date to display. Being a workaround, it won't replace the real fix, but can at least be shipped in a maintenance release I guess. WDYT?
          Hide
          Jérôme Vieilledent added a comment -

          Forget my suggestion. This change will affect existing dates.

          Show
          Jérôme Vieilledent added a comment - Forget my suggestion. This change will affect existing dates.
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Confirmed Confirmed
          1m 39s 1 jacek.foremski@ez.no 04/Jun/18 11:40 AM
          Confirmed Confirmed InputQ InputQ
          6s 1 jacek.foremski@ez.no 04/Jun/18 11:40 AM
          InputQ InputQ Development Development
          197d 2h 39m 1 mateusz.biniek@ez.no 18/Dec/18 1:20 PM
          Development Development Development Review Development Review
          29s 1 mateusz.biniek@ez.no 18/Dec/18 1:20 PM
          Development Review Development Review Documentation Review done Documentation Review done
          23d 1h 33m 1 André Rømcke 10/Jan/19 2:53 PM

            People

            • Assignee:
              Unassigned
              Reporter:
              Jacek Foremski (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated: