ExpressiveDate::setTimestampFromString PHP Method

setTimestampFromString() public method

Sets the timestamp from a human readable string.
public setTimestampFromString ( string $string ) : ExpressiveDate
$string string
return ExpressiveDate
    public function setTimestampFromString($string)
    {
        $this->setTimestamp(strtotime($string));
        return $this;
    }

Usage Example

function eme_get_recurrence_days($recurrence)
{
    global $eme_timezone;
    $matching_days = array();
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    if ($recurrence['recurrence_freq'] == 'specific') {
        $specific_days = explode(",", $recurrence['recurrence_specific_days']);
        foreach ($specific_days as $day) {
            $eme_date_obj->setTimestampFromString($day);
            array_push($matching_days, $eme_date_obj->format('U'));
        }
        return $matching_days;
    }
    $start_date_obj = new ExpressiveDate($recurrence['recurrence_start_date'], $eme_timezone);
    $end_date_obj = new ExpressiveDate($recurrence['recurrence_end_date'], $eme_timezone);
    $last_week_start = array(25, 22, 25, 24, 25, 24, 25, 25, 24, 25, 24, 25);
    $weekdays = explode(",", $recurrence['recurrence_byday']);
    $counter = 0;
    $daycounter = 0;
    $weekcounter = 0;
    $monthcounter = 0;
    $start_monthday = $start_date_obj->format('j');
    $cycle_date_obj = $start_date_obj->copy();
    while ($cycle_date_obj->lessOrEqualTo($end_date_obj)) {
        $cycle_date = $cycle_date_obj->format('U');
        $style = "";
        $monthweek = floor(($cycle_date_obj->format('d') - 1) / 7) + 1;
        if ($recurrence['recurrence_freq'] == 'daily') {
            if ($daycounter % $recurrence['recurrence_interval'] == 0) {
                array_push($matching_days, $cycle_date);
            }
        }
        if ($recurrence['recurrence_freq'] == 'weekly') {
            if (!$recurrence['recurrence_byday'] && eme_iso_N_date_value($cycle_date_obj) == eme_iso_N_date_value($start_date_obj)) {
                // no specific days given, so we use 7 days as interval
                //if($daycounter % 7*$recurrence['recurrence_interval'] == 0 ) {
                if ($weekcounter % $recurrence['recurrence_interval'] == 0) {
                    array_push($matching_days, $cycle_date);
                }
            } elseif (in_array(eme_iso_N_date_value($cycle_date_obj), $weekdays)) {
                // specific days, so we only check for those days
                if ($weekcounter % $recurrence['recurrence_interval'] == 0) {
                    array_push($matching_days, $cycle_date);
                }
            }
        }
        if ($recurrence['recurrence_freq'] == 'monthly') {
            $monthday = $cycle_date_obj->format('j');
            $month = $cycle_date_obj->format('n');
            // if recurrence_byweekno=0 ==> means to use the startday as repeating day
            if ($recurrence['recurrence_byweekno'] == 0) {
                if ($monthday == $start_monthday) {
                    if ($monthcounter % $recurrence['recurrence_interval'] == 0) {
                        array_push($matching_days, $cycle_date);
                    }
                    $counter++;
                }
            } elseif (in_array(eme_iso_N_date_value($cycle_date_obj), $weekdays)) {
                if ($recurrence['recurrence_byweekno'] == -1 && $monthday >= $last_week_start[$month - 1]) {
                    if ($monthcounter % $recurrence['recurrence_interval'] == 0) {
                        array_push($matching_days, $cycle_date);
                    }
                } elseif ($recurrence['recurrence_byweekno'] == $monthweek) {
                    if ($monthcounter % $recurrence['recurrence_interval'] == 0) {
                        array_push($matching_days, $cycle_date);
                    }
                }
                $counter++;
            }
        }
        $cycle_date_obj->addOneDay();
        $daycounter++;
        if ($daycounter % 7 == 0) {
            $weekcounter++;
        }
        if ($cycle_date_obj->format('j') == 1) {
            $monthcounter++;
        }
    }
    return $matching_days;
}
All Usage Examples Of ExpressiveDate::setTimestampFromString