Beispiel #1
0
/**
 * Returns 
 *
 * @param int $pn_start_timestamp Start of date range, as Unix timestamp
 * @param array $pa_options All options supported by TimeExpressionParser::getText() are supported
 *
 * @return string Localized date range expression
 */
function caGetDateRangeForTimelineJS($pa_historic_timestamps, $pa_options = null)
{
    $o_tep = new TimeExpressionParser();
    $va_start = $o_tep->getHistoricDateParts($pa_historic_timestamps[0]);
    $va_end = $o_tep->getHistoricDateParts($pa_historic_timestamps[1]);
    return array('start' => $va_start['year'] . ',' . $va_start['month'] . ',' . $va_start['day'], 'end' => $va_end['year'] . ',' . $va_end['month'] . ',' . $va_end['day']);
}
Beispiel #2
0
/**
 * Returns date range for calendar display
 *
 * @param int $pn_start_timestamp Start of date range, as Unix timestamp
 * @param array $pa_options All options supported by TimeExpressionParser::getText() are supported
 *
 * @return string Localized date range expression
 */
function caGetDateRangeForCalendar($pa_historic_timestamps, $pa_options = null)
{
    $o_tep = new TimeExpressionParser();
    $va_start = $o_tep->getHistoricDateParts($pa_historic_timestamps[0]);
    $va_end = $o_tep->getHistoricDateParts($pa_historic_timestamps[1]);
    if ($va_start['year'] < 0) {
        $va_start['year'] = 1900;
    }
    if ($va_end['year'] >= 2000000) {
        $va_end['year'] = date("Y");
    }
    return array('start' => $va_start, 'end' => $va_end, 'start_iso' => $o_tep->getISODateTime($va_start, 'FULL'), 'end_iso' => $o_tep->getISODateTime($va_end, 'FULL'));
}
function caCalculateDateRangeAvgInDays()
{
    $va_date_ranges = func_get_args();
    $o_tep = new TimeExpressionParser();
    $va_days = array();
    foreach ($va_date_ranges as $vs_date_range) {
        if (!$o_tep->parse($vs_date_range)) {
            print "no parse {$vs_date_range}";
            return false;
        }
        $va_arg_historic_stamps = $o_tep->getHistoricTimestamps();
        $va_start_parts = $o_tep->getHistoricDateParts($va_arg_historic_stamps['start']);
        $va_end_parts = $o_tep->getHistoricDateParts($va_arg_historic_stamps['end']);
        $vs_start = $o_tep->getISODateTime($va_start_parts);
        $vs_end = $o_tep->getISODateTime($va_end_parts);
        $o_start = new DateTime($vs_start);
        $o_end = new DateTime($vs_end);
        $va_days[] = $o_start->diff($o_end)->days;
    }
    if (sizeof($va_days)) {
        return array_sum($va_days) / sizeof($va_days);
    } else {
        return false;
    }
}