Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297594

DrupalDateTime does not respect \Drupal::time() when interpreting strings as dates

$
0
0

The DrupalDateTime extends Drupal's DateTimePlus class in wrapping php's \DateTime, to add additional refinements.

One such refinement is that DrupalDateTime interprets date strings like "5pm" in the current user timezone when constructing a date object based on them.

However, DrupalDateTime has not yet been made aware of the datetime.time service introduced in Drupal 8.3. This service allows the manipulation of the current time in Drupal, which is helpful for testing purposes. Because of this omission, DrupalDateTime will interpret date strings like "now" or "+1 hour" with reference to the current system time as returned by time(), not Drupal's current time as returned by \Drupal::time()->getCurrentTime().

Fixing this would increase the ease of testing code that depends on the current time and creates dates from strings.

Fortunately the logic of doing this is not too hard, because php's date_parse() does the heavy lifting. I have a preliminary implementation here: https://github.com/jonathanjfshaw/datetime_testing/blob/master/src/TestDateTime.php


Viewing all articles
Browse latest Browse all 297594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>