Drupal shows wrong current date examples in May for Date fields, Date formats, etc.

For example, at May 7, 2014 it shows '06/07/2014', or 'Jun 7 2014', etc. I think, that's because of following string in date_example_date() function:

  if (date_format($now, 'M') == date_format($now, 'F')) {
    date_modify($now, '+1 month');
  }

date_format($now, 'M') is equal to 'May', and date_format($now, 'F') is equal to 'May', too. So it adds 1 month to current date.

Comments

intrafusion’s picture

Version: 7.x-2.7 » 7.x-2.x-dev
Priority: Minor » Normal

I can confirm that this issue still exists 3 years later, my content editors find this annoying.

Any reason why this code even exists?

JudyPJHsu’s picture

This is the entire function:

/**
 * Creates an example date.
 *
 * This ensures a clear difference between month and day, and 12 and 24 hours.
 */
function date_example_date() {
  $now = date_now();
  if (date_format($now, 'M') == date_format($now, 'F')) {
    date_modify($now, '+1 month');
  }
  if (date_format($now, 'm') == date_format($now, 'd')) {
    date_modify($now, '+1 day');
  }
  if (date_format($now, 'H') == date_format($now, 'h')) {
    date_modify($now, '+12 hours');
  }
  return $now;
}

I think this is to disambiguate date examples. Like if the example is 11/11, doesn't help as an example of date, because the user doesn't know which is month or date, so by adding some extra time, like 11/12 and if the current month is 11, then you kind of get that the format is mm/dd and not dd/mm.

For the month of May, it also doesn't 'help' to show 'May' because it tells you nothing about whether the format of the month should be a three letter representation of the month or the entire word of the month, which is why a month is added so you can see whether the format is Jun or June.

Unfortunately, this throws people off because regular users are expecting the example to be today's date/time as it usually is.