Download & Extend

Hardcoded day/month/week output format for theme_date_nav_title()

Project:Date
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

For a site in French language (use of locale module) I haven't found how I can get the following display (Vendredi 6 Janvier 2009) for the "day title" of the page when I click on a day within a calendar in a block. I've attached both a capture of the date/time administration settings and the page output of the current day from my calendar.
Apart of this request, I would mention that I haven't found any right template for the usual french ouput of a long date, in the administration settings, that is for today : Vendredi 6 Janvier 2009, without any comma.

I've just upgraded my site from 1.x to 2.x.It is working fine. Thank you a lot for such a great work !

AttachmentSizeStatusTest resultOperations
DateHeureSettings.png61.39 KBIgnored: Check issue status.NoneNone
CalenderDayOutput.png27.62 KBIgnored: Check issue status.NoneNone

Comments

#1

Version:5.x-2.0-rc5» 6.x-2.x-dev
Component:Code» User interface

Is this issue still active? I've got the same problem (with latest 2.x-dev Calendar and Date modules)

Regards

#2

Title:Day output format for a day page display with calendar module» Hardcoded day/month/week output format for theme_date_nav_title()
Component:User interface» Code
Category:support request» bug report

I've done further investigations..

I found that "function theme_date_nav_title()" (inside date/theme/theme.inc file) hard-coded the outputed date format for day/week/month titles.
Maybe the right way to retrieve the right format is to have an option in the calendar view, or something that can be used with i18n (I mean different day title for different country conventions).

For now I re-hardcoded my setting and solved my issue, but I know that it's the worst way to go.. :)

#3

Now that we have our new locale-friendly system for managing date formats we probably should use them in the titles, so I agree this is needed.

Unfortunately I don't really have time to work on it right now, but maybe some will make a patch to let you identify which format should be used for the titles (our new date format system will then automatically handle the locale-switching).

#4

KarenS: if you can point me to the "new locale-friendly system for managing date formats" I can try to provide a patch. I only managed to get the "long" format (that should be locale-safe), but I can't remove the "hour:minutes" parts.

Is in Date_API something usefull to remove a format sub-part?
Thank you

Regards

#5

subscribing

#6

tracking

#7

@ thePanz:

You can copy the code in your template.php & change the beginning of the function name: "theme_..." into "YOUR_THEME_NAME_...".

Drupal will use the function in template.php, so no changing needed in the module.

#8

hi,... it didn´t work to me.
my template´s name is CES, as you can see here:
; $Id: ces.info,v 1.5 2007/07/01 23:27:32 goba Exp $
name = CES

so, I copy the theme_date_nav_title from date module and past that into /themes/ces/template.php and renamed that to
CES_date_nav_title.

nothing happens. I try just to put some ECHO to display anything, but nothing happens. Could you help me?
My callendar displays a wrong month, so I want to fix that in that function.
thanks

#9

did you clear cache ?

#10

Subscribing

#11

cledman

(My themes name: xxx)
I copied the function theme_date_nav_title from the date/theme/theme.inc into sites/default/themes/xxx/template.php. I changed the name of the funtion to xxx_date_nav_title and modified the formats on the differant dates and saved. Worked like a charm!!!

I have been strugeling with this for a long time and this was so easy when you know what to do! Now I'm going to change the date strings from other modules like this as well, hope it works as easily!

#12

Subscribing - I have the same problem in Russian language.

#13

Also subscribing - same problem for Dutch language

#14

Subscribing.

I've applied a patch to template.php to get a french format for the date (as explained in #411828: Bad date format in Week and Day Calendar view in French ), but my problem is that my site is available in five languages (fr/en/de/it/es), so this solution only works for languages that share the same date format as french...

#15

Hi folks,

Just in case you are still having trouble using the theme override function, here is how to do it ... simple name the function phptemplate_date_nav_title instead of your_theme_name_date_nav_title.

Personally, I have hard-coded two if..else conditions and it did the trick.

<?php
/**
* Theme the calendar title
*/
function phptemplate_date_nav_title($granularity, $view, $link = FALSE, $format = NULL) {
  global
$language;
  switch (
$granularity) {
    case
'year':
     
$title = $view->date_info->year;
     
$date_arg = $view->date_info->year;
      break;
    case
'month':
     
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F Y' : 'F');
     
$title = date_format_date($view->date_info->min_date, 'custom', $format);
     
$date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month);
      break;
    case
'day':
      if(
$language->language == "fr"){
         
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'l, j F Y' : 'l, j F');
      } else {
       
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'l, F j Y' : 'l, F j');
      }
     
$title = "###" . date_format_date($view->date_info->min_date, 'custom', $format);
     
$date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day);
      break;
    case
'week':
      if(
$language->language == "fr"){
         
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'j F Y' : 'j F');
      } else {
       
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F j Y' : 'F j');
      }
     
     
$title = t('Week of @date', array('@date' => date_format_date($view->date_info->min_date, 'custom', $format)));
       
$date_arg = $view->date_info->year .'-W'. date_pad($view->date_info->week);
        break;
  }
  if (!empty(
$view->date_info->mini) || $link) {
     
// Month navigation titles are used as links in the mini view.
   
$attributes = array('title' => t('View full page month'));
     
$url = date_real_url($view, $granularity, $date_arg, TRUE);
    return
l($title, $url, array('attributes' => $attributes));
  }
  else {
    return
$title;
  } 
}
?>

#16

subscribing

#17

subscribing

#18

Instead of override the theme function theme_date_nav_title() you can also add a preprocess function in your module or template. An example for the date_navigation preprocess function:

<?php
/**
* Preprocess date navigation
* @param array $vars
* @return void
*/
function xxx_preprocess_date_navigation(&$vars) {
 
$view = $vars['view'];

 
$link = FALSE;
 
// Month navigation titles are used as links in the block view.
 
if (!empty($view->date_info->block) && $view->date_info->granularity == 'month') {
   
$link = TRUE;
  }

 
// Set Dutch format for days and weeks
 
$format = NULL;
  switch (
$view->date_info->granularity) {
    case
'day':
     
$format = 'l j F Y';
      break;
    case
'week':
     
$format = 'j F Y';
      break;
  }
 
$vars['nav_title'] = theme('date_nav_title', $view->date_info->granularity, $view, $link, $format);
}
?>

#19

Nice one, I knew there had to be an easier way :)

#20

Subscribing.

I would like to apply this solution to the new "Date pager" functionality... This is more a Views 3.x issue than a Date issue now. Not sure if I should move this thread.

See webchick comment here:
http://www.drupalgardens.com/content/date-browser-format-views

Date Browser was a way to page back and forth between results by date, rather than by page number. I say "was" because this feature was recently removed from the Date module at http://drupal.org/node/1357362 in favour of the new "Date pager" capabilities.

I know code in #18 is pretty close, but I can't make it work in Drupal 7.

nobody click here