Sets the timestamp from a human readable string.
public setTimestampFromString ( string $string ) : ExpressiveDate | ||
$string | string | |
return | ExpressiveDate |
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; }
function eme_meta_box_div_event_time($event) { global $eme_timezone; // check if the user wants AM/PM or 24 hour notation // make sure that escaped characters are filtered out first $time_format = preg_replace('/\\\\./', '', get_option('time_format')); $hours_locale = '24'; $eme_date_obj = new ExpressiveDate(null, $eme_timezone); if (preg_match("/g|h/", $time_format)) { $event_start_time = $eme_date_obj->setTimestampFromString($event['event_start_time'] . " " . $eme_timezone)->format('h:iA'); $event_end_time = $eme_date_obj->setTimestampFromString($event['event_end_time'] . " " . $eme_timezone)->format('h:iA'); } else { $event_start_time = $event['event_start_time']; $event_end_time = $event['event_end_time']; } ?> <input id="start-time" type="text" size="8" maxlength="8" name="event_start_time" value="<?php echo $event_start_time; ?> " /> - <input id="end-time" type="text" size="8" maxlength="8" name="event_end_time" value="<?php echo $event_end_time; ?> " /> <br /> <?php _e('The time of the event beginning and end', 'eme'); ?> . <?php }