Skip to content

Instantly share code, notes, and snippets.

@marcusx
Created January 13, 2014 14:04
Show Gist options
  • Save marcusx/8400834 to your computer and use it in GitHub Desktop.
Save marcusx/8400834 to your computer and use it in GitHub Desktop.
How to define date formats in a Drupal modules as a features export is only exporting half of the information.
<?php
/**
* Implements hook_date_formats().
*
*/
function my_module_date_formats() {
return array(
array(
'type' => 'my_module_year_only',
'format' => 'Y',
// This format is used for german and english.
// You need to separate this in most real life cases.
// The same format for two languages makes sense if to countries use the same format.
// e.g.: Austria and Germany; or Germany and Swiss
'locales' => array('de', 'en'),
),
array(
'type' => 'my_module_short',
'format' => 'd.m.Y',
'locales' => array('de', 'en'),
),
array(
'type' => 'my_module_medium',
'format' => 'D, d.m.Y',
'locales' => array('de', 'en'),
),
array(
'type' => 'my_module_month_only_long',
'format' => 'F',
'locales' => array('de', 'en'),
),
);
}
/**
* Implements hook_date_format_types().
*
* Setting up some additional date types.
*/
function my_module_date_format_types() {
// Define the date format types.
return array(
'my_module_year_only' => t('My Module year only'),
'my_module_short' => t('My Module short'),
'my_module_medium' => t('My Module medium'),
'my_module_month_only_long' => t('My Module month only long'),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment