function activityBeginTime($begin, $end) { $beginOnlyDate = date_create(dateObjToStr(date_create($begin))); $endOnlyDate = date_create(dateObjToStr(date_create($end))); if (!isLegalDate($begin) || !isLegalDate($begin)) { return; } $tipsArray = array("beginTimeTips" => "", "suffix" => "天后开始", "tomorow" => "明天开始", "opening" => "正在进行", "nearly" => "即将开始", "ending" => "刚刚结束", "invalid" => "已结束"); $test = date_diff($beginOnlyDate, $endOnlyDate)->format("%a"); $isBeginEqualsEnd = intval(date_diff($beginOnlyDate, $endOnlyDate)->format("%a")); if ($isBeginEqualsEnd == 0) { //开始日期=结束日期 $diff = intval(date_diff(date_create(dateObjToStr(date_create())), $endOnlyDate)->format("%r%a")); if ($diff == 0) { } else { if ($diff == 1) { $tipsArray["beginTimeTips"] = $tipsArray["tomorow"]; } else { if ($diff > 1) { $tipsArray["beginTimeTips"] = $diff . $tipsArray["suffix"]; } else { if ($diff < 0) { $tipsArray["beginTimeTips"] = $tipsArray["invalid"]; } } } } } else { $parseRes = dateObjToStr(date_create()); $todayToBegin = date_diff(date_create($parseRes), $beginOnlyDate)->format("%r%a"); $todayToEnd = date_diff(date_create($parseRes), $endOnlyDate)->format("%r%a"); if ($todayToBegin > 0) { //未开始 if (intval($todayToBegin) == 1) { $tipsArray["beginTimeTips"] = $tipsArray["tomorow"]; } else { if (intval($todayToBegin) > 1) { $tipsArray["beginTimeTips"] = $todayToBegin . $tipsArray["suffix"]; } } } else { if ($todayToBegin <= 0 && $todayToEnd >= 0) { //进行中 $tipsArray["beginTimeTips"] = $tipsArray["opening"]; } else { if ($todayToEnd < 0) { $tipsArray["beginTimeTips"] = $tipsArray["invalid"]; } } } } return $tipsArray["beginTimeTips"]; }
/** * palauttaa false jos tyyppi on virheellinen */ function tarkistaTyyppi(&$arvo, $tyyppi) { switch ($tyyppi) { case 'NUMBER': return is_numeric($arvo); case 'PVM': return isLegalDate($arvo); case 'TIME_HH_MM': return isLegalTimeHHMM($arvo); case 'TIME_MM_SS': return isLegalTimeMMSS($arvo); /* $format = '%H:%M'; if (strptime($arvo, $format) == FALSE) { $format = '%H.%M'; return (strptime($arvo, $format) != FALSE); // jos on array niin OK }*/ /* $format = '%H:%M'; if (strptime($arvo, $format) == FALSE) { $format = '%H.%M'; return (strptime($arvo, $format) != FALSE); // jos on array niin OK }*/ case 'PICTURE': return TRUE; case 'TEXT': case 'HIDDEN': case 'PASSWORD': case 'EMAIL': case 'CHECKBOX': case 'RADIO': case 'TEXTAREA': case 'SELECT': case 'SELECTLISAA': case 'LABEL': case 'FILEUPLOAD': return TRUE; break; default: D("<br>ERROR in lisättävä tyypi tarkistus<br>"); D($tyyppi); break; } return FALSE; }