First, a caveat: My knowledge of PHP is minimal at best at the moment; I have bought a couple of books, which I am starting to read through, but I feel like I’m still in the “learning my ABCs” stage … definitely not fluent in PHP yet.
I am designing a test site in ProsePoint (Drupal), and I would like for times to display as a.m. and p.m. instead of the PHP default of am and pm.
I did some research online about this a few weeks ago, and I stumbled across some script or bit of freeware that someone had written for just such a purpose … but now I can’t find it again.
And even if I did … I’m not quite sure where in the ProsePoint/Drupal installation I might need to put it in order for it to work.
Any ideas or suggestions?
[code=php]$meridian = (date('a') == 'am') ? 'a.m.' : 'p.m.';[/code]
[code=php]echo date('g:i ') . $meridian;[/code]
[CODE]$final_date = array('hour' => 0, 'minute' => 0, 'second' => 0,
'month' => 0, 'day' => 0, 'year' => 0);
foreach ($letters as $i => $letter) {
$value = $values[$i];
switch ($letter) {
case 'd':
case 'j':
$final_date['day'] = intval($value);
break;
case 'n':
case 'm':
$final_date['month'] = intval($value);
break;
case 'F':
$array_month_long = array_flip(date_month_names());
$final_date['month'] = $array_month_long[$value];
break;
case 'M':
$array_month = array_flip(date_month_names_abbr());
$final_date['month'] = $array_month[$value];
break;
case 'Y':
case 'y':
$year = $value;
// if no century, we add the current one ("06" => "2006")
$final_date['year'] = str_pad($year, 4, substr(date("Y"), 0, 2), STR_PAD_LEFT);
break;
case 'a':
case 'A':
$ampm = strtolower($value);
break;
case 'g':
case 'h':
case 'G':
case 'H':
$final_date['hour'] = intval($value);
break;
case 'i':
$final_date['minute'] = intval($value);
break;
case 's':
$final_date['second'] = intval($value);
break;
case 'U':
return date_convert($value, DATE_UNIX, DATE_DATETIME);
break;
}
}
if (isset($ampm) && $ampm == 'pm' && $final_date['hour'] < 12) {
$final_date['hour'] += 12;
}
elseif (isset($ampm) && $ampm == 'am' && $final_date['hour'] == 12) {
$final_date['hour'] -= 12;
}[/CODE]
[code=php] if (isset($ampm) && $ampm == 'pm' && $final_date['hour'] < 12) {
$final_date['hour'] += 12;
$ampm = 'p.m.';
}
elseif (isset($ampm) && $ampm == 'am' && $final_date['hour'] == 12) {
$final_date['hour'] -= 12;
$ampm = 'a.m.';
}[/code]
[CODE]
/**
* An array of am and pm options.
* @param $required
* If not required, returned array will include a blank value.
* @return array an array of am pm options.
*/
function date_ampm($required = FALSE) {
$none = array('' => '');
$ampm = array('am' => date_t('am', 'ampm'), 'pm' => date_t('pm', 'ampm'));
return !$required ? $none + $ampm : $ampm;
}
[/CODE]
[CODE]
/**
* A function to translate ambiguous short date strings.
*
* Example: Pass in 'Monday', 'day_abbr' and get the translated
* abbreviation for Monday.
*
* @param string $string
* @param string $context
* @param int $langcode
* @return translated value of the string
*/
function date_t($string, $context, $langcode = NULL) {
//static $replace = array();
if (empty($replace[$langcode])) {
// The function to create the date string arrays is kept separate
// so those arrays can be directly accessed by other functions.
date_t_strings($replace, $langcode);
}
switch ($context) {
case 'day_name':
case 'day_abbr':
case 'day_abbr1':
case 'day_abbr2':
$untranslated = array_flip(date_week_days_untranslated());
break;
case 'month_name':
case 'month_abbr':
$untranslated = array_flip(date_month_names_untranslated());
break;
case 'ampm':
$untranslated = array_flip(array('am', 'pm', 'AM', 'PM'));
break;
case 'datetime':
$untranslated = array_flip(array('Year', 'Month', 'Day', 'Week', 'Hour', 'Minute', 'Second', 'All Day', 'All day'));
break;
case 'datetime_plural':
$untranslated = array_flip(array('Years', 'Months', 'Days', 'Weeks', 'Hours', 'Minutes', 'Seconds'));
break;
case 'date_order':
$untranslated = array_flip(array('Every', 'First', 'Second', 'Third', 'Fourth', 'Fifth'));
break;
case 'date_order_reverse':
$untranslated = array_flip(array('', 'Last', 'Next to last', 'Third from last', 'Fourth from last', 'Fifth from last'));
break;
case 'date_nav':
$untranslated = array_flip(array('Prev', 'Next', 'Today'));
break;
}
$pos = $untranslated[$string];
return $replace[$langcode][$context][$pos];
}
[/CODE]
[CODE]
/**
* Construct translation arrays from pipe-delimited strings.
*
* Combining these strings into a single t() gives them the context needed
* for better translation.
*/
function date_t_strings(&$replace, $langcode) {
$replace[$langcode]['day_name'] = explode('|', trim(t('!day-name Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday', array('!day-name' => ''), $langcode)));
$replace[$langcode]['day_abbr'] = explode('|', trim(t('!day-abbreviation Sun|Mon|Tue|Wed|Thu|Fri|Sat', array('!day-abbreviation' => ''), $langcode)));
$replace[$langcode]['day_abbr1'] = explode('|', trim(t('!day-abbreviation S|M|T|W|T|F|S', array('!day-abbreviation' => ''), $langcode)));
$replace[$langcode]['day_abbr2'] = explode('|', trim(t('!day-abbreviation SU|MO|TU|WE|TH|FR|SA', array('!day-abbreviation' => ''), $langcode)));
$replace[$langcode]['ampm'] = explode('|', trim(t('!ampm-abbreviation am|pm|AM|PM', array('!ampm-abbreviation' => ''), $langcode)));
$replace[$langcode]['datetime'] = explode('|', trim(t('!datetime Year|Month|Day|Week|Hour|Minute|Second|All Day|All day', array('!datetime' => ''), $langcode)));
$replace[$langcode]['datetime_plural'] = explode('|', trim(t('!datetime_plural Years|Months|Days|Weeks|Hours|Minutes|Seconds', array('!datetime_plural' => ''), $langcode)));
$replace[$langcode]['date_order'] = explode('|', trim(t('!date_order Every|First|Second|Third|Fourth|Fifth', array('!date_order' => ''), $langcode)));
$replace[$langcode]['date_order_reverse'] = explode('|', trim(t('!date_order |Last|Next to last|Third from last|Fourth from last|Fifth from last', array('!date_order' => ''), $langcode)));
$replace[$langcode]['date_nav'] = explode('|', trim(t('!date_nav Prev|Next|Today', array('!date_nav' => ''), $langcode)));
[/CODE]
[CODE]
$max = strlen($format);
$datestring = '';
for ($i = 0; $i < $max; $i++) {
$c = $format[$i];
switch ($c) {
// Use date_t() for ambiguous short strings that need translation.
// We send long day and month names to date_t(), along with context.
case 'l':
$datestring .= date_t(date_format($date, 'l'), 'day_name', $langcode);
break;
case 'D':
$datestring .= date_t(date_format($date, 'l'), 'day_abbr', $langcode);
break;
case 'F':
$datestring .= date_t(date_format($date, 'F'), 'month_name', $langcode);
break;
case 'M':
$datestring .= date_t(date_format($date, 'F'), 'month_abbr', $langcode);
break;
case 'A':
case 'a':
$datestring .= date_t(date_format($date, $c), 'ampm', $langcode);
break;
// The timezone name translations can use t().
[/CODE]
[CODE]
function date_convert($date, $from_type, $to_type, $tz = 'UTC') {
if (empty($date) && !$date === 0) return NULL;
if (empty($from_type) || empty($to_type) || $from_type == $to_type) return $date;
switch ($from_type) {
case DATE_ARRAY:
if (!is_array($date)) return NULL;
if (isset($date['ampm'])) {
if ($date['ampm'] == 'pm' && $date['hour'] < 12) $date['hour'] += 12;
if ($date['ampm'] == 'am' && $date['hour'] == 12) $date['hour'] -= 12;
}
[/CODE]
[CODE]
/**
* Implementation of hook_elements().
*/
function date_api_elements() {
require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_elements.inc');
return _date_api_elements();
}
function date_api_theme() {
$path = drupal_get_path('module', 'date_api');
$base = array(
'file' => 'theme.inc',
'path' => "$path/theme",
);
return array(
'date_nav_title' => $base + array('arguments' => array('type' => NULL, 'view' => NULL)),
'date_vcalendar' => $base + array('arguments' => array('events' => NULL, 'calname' => NULL)),
'date_vevent' => $base + array('arguments' => array('event' => NULL)),
'date_valarm' => $base + array('arguments' => array('alarm' => NULL)),
'date_timezone' => $base + array('arguments' => array('element' => NULL)),
'date_select' => $base + array('arguments' => array('element' => NULL)),
'date_text' => $base + array('arguments' => array('element' => NULL)),
'date_select_element' => $base + array('arguments' => array('element' => NULL)),
'date_textfield_element' => $base + array('arguments' => array('element' => NULL)),
'date_date_part_hour_prefix' => $base + array('arguments' => array('element' => NULL)),
'date_part_minsec_prefix' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_year' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_month' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_day' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_hour' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_minute' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_second' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_ampm' => $base + array('arguments' => array('element' => NULL)),
'date_part_label_timezone' => $base + array('arguments' => array('element' => NULL)),
'date_views_filter_form' => $base + array(
'template' => 'date-views-filter-form',
'arguments' => array('form' => NULL)),
'date_calendar_day' => $base + array('arguments' => array('date' => NULL)),
'date_time_ago' => $base + array('arguments' => array('start_date' => NULL, 'end_date' => NULL, 'interval' => NULL)));
}
[/CODE]
0.1.9 — BETA 5.27