is_numeric check after augmentOutput() fails for core date field type using smart date formatter

Created on 8 March 2024, 8 months ago
Updated 11 May 2024, 6 months ago

Problem/Motivation

The smart date formatter is available for use with the core date field type. Those values are stored in the YYYY-MM-DDTHH:MM:SS format. When passing through `\Drupal\smart_date\SmartDateTrait::augmentOutput` the code assumes start_ts and end_ts are unix timestamps and pass it through to DrupalDateTime::createFromTimestamp which causes it to fail the is_numeric check.

Steps to reproduce

- Create a date field (not smart date)
- Assign the smart date formatter
- Use Date Augmenter to trigger \Drupal\smart_date\SmartDateTrait::augmentOutput

Proposed resolution

Add is_numeric() checks in augmentOutput for $start_ts and $end_ts and convert strtotime() if they exist.

I assume $end_ts should equal $start_ts if it is null?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Date Augmenter Integration

Created by

πŸ‡ΊπŸ‡ΈUnited States joewhitsitt Iowa

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

Merge Requests

Comments & Activities

  • Issue created by @joewhitsitt
  • Merge request !87numeric checks and conversions β†’ (Merged) created by joewhitsitt
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States joewhitsitt Iowa
  • First commit to issue fork.
  • πŸ‡¨πŸ‡¦Canada mandclu

    Thanks for identifying this, and for suggesting a fix. The approach you've taken seems sensible enough, but I wonder if it wouldn't be better to update the call to augmentOutput() within SmartDateTrait::viewElements to pass in the calculated $start_ts and $end_ts values instead (or maybe in addition?).

    The original code looks like it did that, which makes me think there's a reason I decided not when this was refactored. A year later, however, I don't seem to have any notes on that.

    I'm inclined to want to test that first, to see if there's an obvious reason why using the $start_ts and $end_ts values already calculated wouldn't be a better approach.

  • Pipeline finished with Skipped
    7 months ago
    #158538
  • Status changed to Fixed 7 months ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    After giving this some more thought, it only makes sense to ensure the values are numeric without the augmentOutput method, whether or not the method should be fed the original, unaltered values. I added a todo to revisit that question, and also moved the code that normalizes the values before the loop. Merged in.

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

Production build 0.71.5 2024