Skip to content

[#200] Fixed date-only field handling and simplified relative date logic.#309

Merged
AlexSkrypnyk merged 1 commit intomasterfrom
feature/200-date-only
Apr 16, 2026
Merged

[#200] Fixed date-only field handling and simplified relative date logic.#309
AlexSkrypnyk merged 1 commit intomasterfrom
feature/200-date-only

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

Iterates on #290 by @ericgsmith. Thank you for the contribution!

Summary

  • Fixed date-only field handling so values are stored using DATE_STORAGE_FORMAT in the site timezone, rather than incorrectly treating them as datetime values.
  • Unified the relative/explicit date branches so relative date stripping happens first, then a single code path handles formatting based on the field's datetime_type setting.
  • Replaced \DateTime with DrupalDateTime for both date-only and datetime values, ensuring proper timezone handling via Drupal's API.
  • Added imports for DrupalDateTime and DateTimeItem to support the new logic.

Problem

The original expand() method in DatetimeHandler had two separate branches:

  1. Relative dates (relative: prefix) - used gmdate / strtotime and always produced a datetime format, ignoring whether the field was date-only.
  2. Explicit dates - used \DateTime and always applied a datetime format with timezone conversion to UTC.

Neither branch was aware of the field's datetime_type setting, so date-only fields (configured as DateTimeItem::DATETIME_TYPE_DATE) received the wrong storage format.

Before / After

Before - two independent branches, no date-type awareness:

if (strpos($value, "relative:") !== FALSE) {
    $relative = trim(str_replace('relative:', '', $value));
    // Always produced a datetime string, even for date-only fields.
    $values[$key] = substr(gmdate('c', strtotime($relative)), 0, 19);
}
else {
    $date = new \DateTime($value, $siteTimezone);
    $date->setTimezone($storageTimezone);
    // Always formatted as datetime, ignoring date-only fields.
    $values[$key] = $date->format('Y-m-d\TH:i:s');
}

After - relative prefix stripped first, then a unified path selects format by field type:

if (strpos($value, 'relative:') !== FALSE) {
    $value = trim(str_replace('relative:', '', $value));
}

if ($this->fieldInfo->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
    // Date-only: store in site timezone using date storage format.
    $date = new DrupalDateTime($value, $siteTimezone);
    $format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
}
else {
    // Datetime: convert from site timezone to storage timezone.
    $date = new DrupalDateTime($value, $siteTimezone);
    $date->setTimezone($storageTimezone);
    $format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
}
$values[$key] = $date->format($format);

Issue

Resolves #200.

Test plan

  • PHPUnit test suite: 36/36 tests passing.
  • Covers both date-only and datetime field types, as well as relative date values for each.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@AlexSkrypnyk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 37 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 36 minutes and 37 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae812ff2-4c55-4d0b-aa7b-5799182f293b

📥 Commits

Reviewing files that changed from the base of the PR and between b36e272 and 2e513ef.

📒 Files selected for processing (1)
  • src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/200-date-only

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…implified relative date logic.

Co-authored-by: Eric Smith <ericsmith@catalyst.net.nz>
@AlexSkrypnyk AlexSkrypnyk force-pushed the feature/200-date-only branch from 682d6e8 to 2e513ef Compare April 16, 2026 09:34
@AlexSkrypnyk AlexSkrypnyk merged commit 435c351 into master Apr 16, 2026
6 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/200-date-only branch April 16, 2026 22:25
@AlexSkrypnyk AlexSkrypnyk added this to the 2.5 milestone Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Date only' date type field is not being created while running behat tests

1 participant