start_time and end_time properties don't work

Created on 16 March 2023, almost 2 years ago
Updated 26 August 2023, over 1 year ago

Problem/Motivation

The start_time and end_time computed properties don't work, and I suspect they never have. The DateTimeComputed class constructs a DrupalDateTime object using the field value and either DateTimeItemInterface::DATE_STORAGE_FORMAT or DateTimeItemInterface::DATETIME_STORAGE_FORMAT as date format. There is no support for timestamps.

Steps to reproduce

Get the start_time property from a field that has a start date and time, like this:

$entity->get('field_schedule_entry_date')->start_time

This will return NULL.

Proposed resolution

Create a new DateTimeComputed class parsing field values as timestamps.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dieterholvoet
  • @dieterholvoet opened merge request.
  • Status changed to Needs review almost 2 years ago
  • 🇩🇪Germany daveiano

    With the patch applied, the start_time and end_time properties return at least data, in my case the following as an example (actual output is from a GraphQL request, but this should not make any difference):

    "fieldWhen": [
      {
          "value": 1681115400,
          "endValue": 1681119000,
          "startTime": "2023-04-10 10:30:00 Europe/Berlin",
          "endTime": "2023-04-10 11:30:00 Europe/Berlin",
          "rrule": null,
          "rruleIndex": null,
          "timezone": "",
          "duration": 60
      }
    ]
    

    Is this the intended output of start_time and end_time? Just asking, I thought this should only return the actual time, eg: 10:30:00?

  • 🇧🇪Belgium dieterholvoet Brussels

    actual output is from a GraphQL request, but this should not make any difference

    It does make a difference. If you run the code from the field description you get an instance of DrupalDateTime, if you use GraphQL you get the normalized version of that object.

    I thought this should only return the actual time, eg: 10:30:00?

    No, if you look at SmartDateItem::propertyDefinitions you'll see that start_time and end_time are supposed to contain respectively The computed start DateTime object. and The computed end DateTime object..

  • First commit to issue fork.
  • Status changed to Fixed almost 2 years ago
  • 🇨🇦Canada mandclu

    Thanks very much for the work on this. This has been merged into the 3.7.x and 4.0.x branches.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed over 1 year ago
  • 🇧🇪Belgium dieterholvoet Brussels

    I just thought of something: shouldn't we consider the timezone stored in the field item when creating the DateTime object in DateTimeComputed::getValue()? If so, I'll create a new issue to fix that.

  • 🇨🇦Canada mandclu

    Ah great point. If a timezone has been provided, it should definitely be considered. Please open a child issue for that.

Production build 0.71.5 2024