function partial_date_format_component in Partial Date 7
1 call to partial_date_format_component()
- partial_date_format in ./partial_date.module
File
- ./partial_date.module, line 1659
- Defines a date element that allows for any combination of date granularity
settings.
Code
function partial_date_format_component($value, $format, &$date, $additional = array()) {
$additional += array(
'year_designation' => 'ce',
);
if ($format == 'h' || $format == 'g') {
if ($value > 12) {
$value -= 12;
}
elseif ($value == 0) {
$value = '12';
}
if (empty($additional['meridiem'])) {
$additional['meridiem'] = 'a';
}
}
else {
$additional['meridiem'] = '';
}
$suffix = '';
switch ($format) {
case 'd-S':
case 'j-S':
$suffix = partial_date_day_ordinal_suffix($value);
break;
case 'y-ce':
case 'Y-ce':
$suffix = partial_date_year_designation_decorator($value, $additional['year_designation']);
if (!empty($suffix) && !empty($value)) {
$value = abs($value);
}
break;
}
switch ($format) {
case 'y-ce':
case 'y':
return (strlen($value) > 2 ? substr($value, -2) : $value) . $suffix;
case 'F':
return partial_date_month_names($value) . $suffix;
case 'M':
return partial_date_month_abbreviations($value) . $suffix;
case 'w':
if (!empty($date['year']) && !empty($date['month'])) {
return partial_date_day_of_week($date['year'], $date['month'], $value) . $suffix;
}
return '';
case 'l':
case 'D':
if (!empty($date['year']) && !empty($date['month'])) {
$day = partial_date_day_of_week($date['year'], $date['month'], $value);
if ($format == 'D') {
return partial_date_weekday_name_abbreviations($day, 3) . $suffix;
}
else {
return partial_date_weekday_names($day) . $suffix;
}
}
return '';
case 'n':
case 'j':
case 'j-S':
case 'g':
case 'G':
return intval($value) . $suffix;
case 'd-S':
case 'd':
case 'h':
case 'H':
case 'i':
case 's':
case 'm':
return sprintf('%02s', $value) . $suffix;
case 'Y-ce':
case 'Y':
case 'e':
return $value . $suffix;
case 'T':
try {
$tz = new DateTimeZone($value);
$transitions = $tz
->getTransitions();
return $transitions[0]['abbr'] . $suffix;
} catch (Exception $e) {
}
return '';
case 'o':
case 'z':
case 'N':
case 'I':
case 'O':
case 'P':
case 'Z':
default:
return '';
}
}