function _datex_fix_missing_granularity in Datex 7.3
Helper function.
In case some granularity is missing from a field configuration some fix is needed.
2 calls to _datex_fix_missing_granularity()
- datex_date_formatter_dates_alter in ./
datex_date.inc - Implements hook_date_formatter_dates_alter().
- datex_date_select_process_alter in ./
datex_date.inc - Implements hook_date_select_process_alter().
File
- ./
datex_date.inc, line 157 - Provides support for date module.
Code
function _datex_fix_missing_granularity(DateObject $date, array $element, $calendar) {
if ($calendar !== 'persian') {
return;
}
if (_datex_date_field_has_granularity($element, 'month') && !_datex_date_field_has_granularity($element, 'day')) {
// There are maximum of 23 days difference in Persian calendar and
// Gregorian, that is, April-1st is 22 days behind Farvardin-1st.
// We take 24 days to be sure. For leap years included.
$offset = 24 * (24 * 3600);
$date
->setTimestamp($date
->getTimestamp() + $offset);
}
if (!_datex_date_field_has_granularity($element, 'month')) {
// There are 3 months difference in Persian calendar and
// Gregorian, that is, Jan-1st is 3 months behind Farvardin-1st.
// We take 4 days to be sure. For leap years included.
$offset = 4 * 30 * (24 * 3600);
$date
->setTimestamp($date
->getTimestamp() + $offset);
}
}