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.

Comments

Status: Needs review » Needs work

The last submitted patch, c-formatter-fix.patch, failed testing.

eromba’s picture

Status: Needs work » Needs review

c-formatter-fix.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, c-formatter-fix.patch, failed testing.

rokr’s picture

I 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.

rokr’s picture

I 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 +0100

The 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: date

hth, rokr

rokr’s picture

Title: 'c' formatter causes date to be printed twice » 'c' and 'r' formatter causes date to be printed twice in views
jyee’s picture

Version: 7.x-2.6 » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new695 bytes

Patch against latest git revision (84b66b7)

wooody’s picture

Thank you jyee...

vijaycs85’s picture

Issue summary: View changes
Status: Needs review » Fixed

Committed 31c8b30 and pushed to 7.x-2.x. Thanks!

defconjuan’s picture

Confirm that #7 works.

Status: Fixed » Closed (fixed)

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