I am trying to output an ISO-8061-compliant time string in a View, based on the value of a Date field. When I tried to use a custom date format consisting of the single character 'c', which is shorthand for the ISO 8061 format, I noticed that the formatted date string was being printed twice.
After some investigation, I found that the problem stems from incorrect values being assigned by date_formatter_process(). Specifically, for a format string of 'c', this function returns the following array:
Array
(
...
[formatted] => 2012-11-07T22:00:00-06:00
[formatted_iso] => 2012-11-07T22:00:00-06:00
[formatted_date] => 2012-11-07T22:00:00-06:00
[formatted_time] => 2012-11-07T22:00:00-06:00
[formatted_timezone] => 2012-11-07T22:00:00-06:00
...
)
These values eventually make their way to the Date module's theme functions, which essentially do the following:
...
return '<span ... >' . $date . $timezone . '</span>';
$date and $timezone correspond to the [formatted] and [formatted_timezone] values above, respectively. So in the case of a 'c' formatter, the formatted string ends up being printed twice.
I have attached a one-line patch adds a special case for a 'c' formatter in date_formatter_process(). This is the same way that the module currently handles 'U' formatters (which print a standard UNIX timestamp). With this patch applied, the returned array becomes:
Array
(
...
[formatted] => 2012-11-07T22:00:00-06:00
[formatted_iso] => 2012-11-07T22:00:00-06:00
[formatted_date] => 2012-11-07T22:00:00-06:00
[formatted_time] =>
[formatted_timezone] =>
...
)
With this patch applied, 'c' format strings can be used without issue, and the resulting time string is correctly printed only once.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | full_date_formats_print_twice-1826598-7.patch | 695 bytes | jyee |
| c-formatter-fix.patch | 677 bytes | eromba |
Comments
Comment #2
eromba commentedc-formatter-fix.patch queued for re-testing.
Comment #4
rokrI can reproduce it with custom time format "r" which i want to use for RSS (pubdate, RFC 822).
It works with node create date but not with date field.
Comment #5
rokrI reproduced it on a clean drupal 7.18, date 7.x-2.6 (also dev), views 7.x-3.5.
I created a date and time format using "r". Using this format with views results in a field which prints its content twice, like...
Mon, 07 Jan 2013 18:15:00 +0100 Mon, 07 Jan 2013 18:15:00 +0100The same date format works as field formatter.
Work around: i'm using this format now
D, d M Y H:i:s O. See PHP: datehth, rokr
Comment #6
rokrComment #7
jyee commentedPatch against latest git revision (84b66b7)
Comment #8
wooody commentedThank you jyee...
Comment #9
vijaycs85Committed 31c8b30 and pushed to 7.x-2.x. Thanks!
Comment #10
defconjuan commentedConfirm that #7 works.