Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
field date is not ISO 8601, it stores only UTC , and w/o timezone info.
ok.. i "want" now to save with UTC too (I'm using decoupled aproach, no drupal frontend), I will have same error because
$c = new DrupalDateTime($data[$mappedField], 'UTC');
$utc = $c->format('c'); // or $utc = $c->format(DATE_ISO8601, ['timezone' => 'UTC']);
$node->$field = $utc;
$node->save();
is
2017-10-10T07:10:10+00:00 or 2017-10-10T07:10:10+0000
trying to save proper ISO 8601 thows error
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column ...
because column is limited to 20 chars. WHY?! I don't even talk now about idea of saving date as UTC
So, i must use this
$utc = $c->format('Y-m-d\TH:i:s');
I hope I get it right
regards
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedyurii_2016 created an issue. See original summary.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedComment #3
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedComment #4
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedComment #5
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedp.s.
and that's how i output date now
amazing, is this the correct way? I hope so
Comment #6
mpdonadioThere are constants to use for that:
That should work, though in general, the ::create methods are preferred over calling the DrupalDateTime constructor directly.
Postponing this to see if this solves the problem; reopen if it doesn't. This is also potentially related to (or duplicates of)
#2716891: DateTimeIso8601::setDateTime() vs. DateTimeItem::schema(): (at least) one of them is broken
#2768651: Let TimestampItem (de)normalize to/from RFC3339 timestamps, not UNIX timestamps, for better DX
I do agree, though, that this situation isn't ideal. Even w/o changing storage, I think this should be more accommodating of timezones and formats, and handle the conversion to the storage format internally.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedafter digging date field i'm outputing date this way for now
which looks sufficient.
Problem is with misleading description of date field module. Because it is not ISO 8601 ( https://en.wikipedia.org/wiki/ISO_8601 ), you don't store timezone, like 'Z' etc
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commented