当前位置: 首页>>代码示例>>PHP>>正文


PHP functions::date_diff_workaround方法代码示例

本文整理汇总了PHP中functions::date_diff_workaround方法的典型用法代码示例。如果您正苦于以下问题:PHP functions::date_diff_workaround方法的具体用法?PHP functions::date_diff_workaround怎么用?PHP functions::date_diff_workaround使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在functions的用法示例。


在下文中一共展示了functions::date_diff_workaround方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEventsBarchart

 function getEventsBarchart($confid, $treatLocalsSeparately = 0)
 {
     $cidcode = "";
     if (is_array($confid)) {
         foreach ($confid as $cid) {
             $cidcode[] = "(E.e_code='" . $cid . "')";
         }
     } else {
         $cidcode[] = "(E.e_code='" . $confid . "')";
     }
     // ------------------------------------------------------
     // Query database
     // ------------------------------------------------------
     //TODO: if multiple $confids same day, add people without duplocation
     $sql = "\n      SELECT\n        E.e_name,\n        A.av_institute,\n        A.av_email,\n        A.av_city,\n        FROM_UNIXTIME(V.v_start,'%Y-%m-%d') AS 'd0',\n        FROM_UNIXTIME(V.v_end,'%Y-%m-%d') AS 'd1'\n      FROM\n        abs_visits AS V\n        LEFT JOIN zzz_avatars AS A ON A.av_id=V.v_avid\n        LEFT JOIN abs_events AS E ON E.e_code=SUBSTRING(V.v_code,1,4)\n      WHERE\n        (" . implode(" OR ", $cidcode) . ") AND (V.v_status <> 'STATUS_NO')\n      ORDER BY\n        V.v_start";
     $res = $this->query($sql, IS_TESTSERVER);
     // includes a call to connect
     // ------------------------------------------------------
     // Assemble $visit[] from resultset
     // ------------------------------------------------------
     $GLOBALS["eventTitle"] = "";
     $visit = array();
     if ($this->num_rows($res)) {
         while ($cell = $this->next_record_assoc($res)) {
             $isLocal = strpos(strtolower($cell["av_city"]), "stockholm") !== false || strpos(strtolower($cell["av_email"]), "kth.se") !== false || strpos(strtolower($cell["av_email"]), "su.se") !== false || strpos(strtolower($cell["av_email"]), "nordita.org") !== false ? 1 : 0;
             $visit[$cell["av_email"]][] = array($cell["d0"], $cell["d1"], $isLocal);
             $GLOBALS["eventTitle"] = $cell["e_name"];
         }
         // end while
     }
     $modvisit = array();
     foreach ($visit as $email => $data) {
         foreach ($data as $b) {
             $b0 = min($b[1], $b[0]);
             for ($i = 0; $i <= functions::date_diff_workaround($b[1], $b[0]); $i++) {
                 $adate = date("Y-m-d", strtotime($b0 . " + " . $i . " day"));
                 $vtype = "any";
                 if ($treatLocalsSeparately) {
                     $vtype = $b[2] ? "local" : "visitor";
                 }
                 $modvisit[$email][$vtype][$adate] = 1;
             }
         }
     }
     // ------------------------------------------------------
     // Assemble $barchart[]
     // ------------------------------------------------------
     $barchart = array();
     foreach ($modvisit as $email => $array) {
         foreach ($array as $vtype => $days) {
             foreach ($days as $adate => $data) {
                 $barchart[$adate][$vtype] = isset($barchart[$adate][$vtype]) ? $barchart[$adate][$vtype] + 1 : 1;
             }
         }
     }
     ksort($barchart);
     /*
         // ------------------------------------------------------
         // Assemble $barchart[]
         // ------------------------------------------------------
     
         $barchart = array();
         foreach ($visit as $b) {
           $b0 = min($b[1],$b[0]);
           for ($i=0; $i<=functions::date_diff_workaround($b[1],$b[0]); $i++) {
             $adate = date("Y-m-d",strtotime($b0 . " + " . $i . " day"));
             if ($treatLocalsSeparately) {
               if ($b[2]) {
                 $barchart[$adate]["local"] = (isset($barchart[$adate]["local"])) ? $barchart[$adate]["local"]+1 : 1;
               } else {
                 $barchart[$adate]["visitor"] = (isset($barchart[$adate]["visitor"])) ? $barchart[$adate]["visitor"]+1 : 1;
               }
             } else {
               $barchart[$adate] = (isset($barchart[$adate])) ? $barchart[$adate]+1 : 1;
             }
           }
         }
         ksort($barchart);
     */
     return $barchart;
 }
开发者ID:,项目名称:,代码行数:81,代码来源:

示例2: calculateVisitors

 private static function calculateVisitors($personData, $yearfrom = VM_START_YEAR, $yearto = "", $mindays = 1)
 {
     if (empty($yearto)) {
         $yearto = date("Y");
     }
     if ($yearfrom > $yearto) {
         $yearfrom = VM_START_YEAR;
         $yearto = date("Y");
     }
     $visits = array();
     foreach ($personData as $data) {
         $yearVisitStart = date("Y", $data["visit_start"]);
         $yearVisitEnd = date("Y", $data["visit_end"]);
         if ($yearVisitStart <= $yearto && $yearfrom <= $yearVisitEnd) {
             if ($yearVisitStart < $yearfrom) {
                 $yearVisitStart = $yearfrom;
                 $data["visit_start"] = mktime(0, 0, 0, 1, 1, $yearfrom);
             }
             if ($yearto < $yearVisitEnd) {
                 $yearVisitEnd = $yearto;
                 $data["visit_end"] = mktime(0, 0, 0, 12, 31, $yearto);
             }
             $thisApp = array();
             // some ad hoc exclusions
             if ($data["firstname"] . " " . $data["lastname"] == 'Larus Thorlacius') {
                 continue;
             }
             if ($data["firstname"] . " " . $data["lastname"] == 'Troels Harmark') {
                 continue;
             }
             if ($data["firstname"] . " " . $data["lastname"] == 'John Hertz') {
                 continue;
             }
             if ($data["firstname"] . " " . $data["lastname"] == 'Dhrubaditya Mitra') {
                 if (date("Y", $data["visit_start"]) > 2008) {
                     continue;
                 }
                 $data["res"] = 'in';
                 $data["nordic"] = 0;
             }
             $name = $data["firstname"] . " " . $data["lastname"];
             if (!isset($visits[$name])) {
                 $visits[$name]["country"] = !empty($data["res"]) ? strtolower($data["res"]) : "";
                 $visits[$name]["totdays"] = 0;
                 $visits[$name]["institute"] = $data["institute"];
             }
             $visits[$name]["interval"][] = functions::readableDateInterval(date("Y-m-d", $data["visit_start"]), date("Y-m-d", $data["visit_end"]), true);
             $days = functions::date_diff_workaround(date("Y-m-d", $data["visit_start"]), date("Y-m-d", $data["visit_end"]));
             if (!$days) {
                 $days = 1;
             }
             // count only nights, but if visitors arrives and leaves the same day, count as one:
             $visits[$name]["totdays"] = $visits[$name]["totdays"] + $days;
             $visits[$name]["days"][] = $days;
         }
     }
     // end foreach
     foreach ($visits as $name => $data) {
         if ($data["totdays"] < $mindays) {
             unset($visits[$name]);
         }
     }
     return $visits;
 }
开发者ID:,项目名称:,代码行数:64,代码来源:


注:本文中的functions::date_diff_workaround方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。