I have site with drupal 4.5 and module flexinode. This module flexinode can create field datetime format. How I can change format of type flexinode field datetime to DAY/MONTH/YEAR?

Comments

jmcdaid’s picture

Hi...
Still a newbie to drupal, so apologies if this ignores best practice; tried searching for a solution & reading docs (the most nearly applicable, http://drupal.org/node/9700, didn't seem to be quite on point.)

This is my first modification to a module, so I'll warn in advance to use at your own risk, and invite both friendly corrections and irate "WTF are you doing" replies.

Tested with flexinode v 1.46.2.2 and drupal 4.6.3.

-john

Flexinode appears to default to the medium date format. If you can live with the same date format throughout drupal, you can make a few changes, first to define a new user format:

system.module, line 258

// Date settings: possible date formats
  $datemydate = array('Y-m-d','m/d/Y', 'd/m/Y', 'Y/m/d',
           'm/d/Y', 'd/m/Y', 'Y/m/d',
           'M j Y', 'j M Y', 'Y M j',
           'M j Y', 'j M Y', 'Y M j');

system.module, line 274
  // Date settings: construct choices for user
  foreach ($datemydate as $f) {
    $datemydatechoices[$f] = format_date(time(), 'custom', $f);
  }

and then, specify the formatting your addition as a function in common.inc

common.inc, line 852

function format_date($timestamp, $type = 'mydate', $format = '', $timezone = NULL) {

edit the switch block beginning at line 865 to reflect that 'medium' is no longer the default and provide a new case statement for your format

common.inc, line 875

	case 'medium':
      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
      break;
    case 'mydate':
    default:
      $format = variable_get('date_format_mydate', 'j F Y');

You should then be able to go to admin/settings and select your choice of m/d/y arrangements; these should then appear immediately on any timestamped flexinodes.

Now you need to make some changes in the flexinode's own timestamp functions to modfy how it displays edit boxes and concatenates them for conversion to a timestamp.

In field_timestamp.inc, locate the flexinode_form_date function, then make the following changes:

field_timestamp.inc comment out lines 74-76 (unneeded display formatting)

  //$hour = format_date($timestamp, 'custom', $hour_format);
  //$minute = format_date($timestamp, 'custom', 'i');
  //$am_pm = format_date($timestamp, 'custom', 'a');

field_timestamp.inc comment out lines 83-89 (suppress edit boxes)

  //$when .= '</div><div class="time">';
  //$when .= form_select('', $prefix .'hour', $hour, $hours);
  //$when .= ':';
  //$when .= form_select('', $prefix .'minute', $minute, $minutes);
  //if (variable_get('event_ampm', '0')) {
  //  $when .= form_select('', $prefix .'ampm', $am_pm, $am_pms);
 // }

field_timestamp.inc remove the hour/minute conditions from line 97

  if (isset($node->{$prefix . 'year'}) && isset($node->{$prefix . 'month'}) && isset($node->{$prefix . 'day'})) {

field_timestamp.inc hardcode 12 noon into the gmmktime function on line 107

    $result = gmmktime(12, 0, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}) - $GLOBALS['user']->timezone;
koyra’s picture

THANKS

Sverre’s picture

Thank you, this is just what I was looking for! :-)
--
Sverre Sverresonn
Group Scout Leader
21st Medway Scouts, Kent, UK
http://www.21stmedway.org.uk/