function day_time($time = false) { if ($time === false) { $time = time(); } return mktime(0, 0, 0, idate('m', $time), idate('d', $time), idate('Y', $time)); }
public static function word($from, $now = null) { if (null === $now) { $now = time(); } $between = $now - $from; if ($between > 0 && $between < 86400 && idate('d', $from) == idate('d', $now)) { if ($between < 3600 && idate('H', $from) == idate('H', $now)) { if ($between < 60 && idate('i', $from) == idate('i', $now)) { $second = idate('s', $now) - idate('s', $from); if (0 == $second) { return '刚刚'; } else { return sprintf('%d秒前', $second); } } $min = idate('i', $now) - idate('i', $from); return sprintf('%d分钟前', $min); } $hour = idate('H', $now) - idate('H', $from); return sprintf('%d小时前', $hour); } if ($between > 0 && $between < 172800 && (idate('z', $from) + 1 == idate('z', $now) || idate('z', $from) > 2 + idate('z', $now))) { return sprintf('昨天 %s', date('H:i', $from)); } if ($between > 0 && $between < 604800 && idate('W', $from) == idate('W', $now)) { $day = intval($between / (3600 * 24)); return sprintf('%d天前', $day); } if ($between > 0 && $between < 31622400 && idate('Y', $from) == idate('Y', $now)) { return date('n月j日', $from); } return date('Y年m月d日', $from); }
/** * 有消息时触发该方法 * @param int $client_id 发消息的client_id * @param string $message 消息 * @return void */ public static function onMessage($client_id, $message) { $db = \Lib\Db::instance('tc504'); $nowtime = idate("U"); $ok = "right"; $error = "error"; $sqlok = "sql right!"; $sqlerror = "sql error!"; if ($message[0] == '{') { $message = JsonProtocol::decode($message); $sqldidian = $message['ID']; $sqlshidu = $message['humidity']; $sqlwendu = $message['temperature']; $insert_id = $db->insert('wenshidu')->cols(array('didian' => $sqldidian, 'shidu' => $sqlshidu, 'wendu' => $sqlwendu, 'time' => $nowtime))->query(); GateWay::sendToClient($client_id, TextProtocol::encode($insert_id)); } else { $message = TextProtocol::decode($message); $commend = trim($message); $ret = $db->select('ui_cardid')->from('tbl_user')->where("ui_cardid = '{$commend}' ")->single(); if ($commend === $ret) { $insert_id = $db->insert('tbl_log')->cols(array('log_card' => $commend, 'log_time' => $nowtime))->query(); if ($insert_id === 1) { GateWay::sendToClient($client_id, TextProtocol::encode($sqlok)); } else { GateWay::sendToClient($client_id, TextProtocol::encode($sqlerror)); } } else { GateWay::sendToClient($client_id, TextProtocol::encode($error)); } } }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); // TODO: These should be user-based and navigable in the interface. $year = idate('Y'); $month = idate('m'); $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere('day BETWEEN %s AND %s', "{$year}-{$month}-01", "{$year}-{$month}-31"); $statuses = id(new PhabricatorUserStatus())->loadAllWhere('dateTo >= %d AND dateFrom <= %d', strtotime("{$year}-{$month}-01"), strtotime("{$year}-{$month}-01 next month")); $month_view = new AphrontCalendarMonthView($month, $year); $month_view->setUser($user); $month_view->setHolidays($holidays); $phids = mpull($statuses, 'getUserPHID'); $handles = $this->loadViewerHandles($phids); foreach ($statuses as $status) { $event = new AphrontCalendarEventView(); $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); $name_text = $handles[$status->getUserPHID()]->getName(); $status_text = $status->getTextStatus(); $event->setUserPHID($status->getUserPHID()); $event->setName("{$name_text} ({$status_text})"); $event->setDescription($status->getStatusDescription($user)); $month_view->addEvent($event); } return $this->buildStandardPageResponse(array('<div style="padding: 2em;">', $month_view, '</div>'), array('title' => 'Calendar')); }
public function __construct($email_id) { $this->_email_id = $email_id; //ISO Week number of the current year $week_number = idate("W"); $year = idate("Y"); $month = idate("m"); $last_day_of_month = idate('t'); $today = new \DateTime(); $start_of_month = clone $today; $start_of_month->setDate($year, $month, 1); $start_of_month->setTime(0, 0, 1); $end_of_month = clone $today; $end_of_month->setDate($year, $month, $last_day_of_month); $end_of_month->setTime(23, 59, 59); $start_of_week = clone $today; $start_of_week->setISODate($year, $week_number); $start_of_week->setTime(0, 0, 0); $end_of_week = clone $start_of_week; $date_interval = new \DateInterval("P6D"); $end_of_week->add($date_interval); $end_of_week->setTime(23, 59, 59); $this->_today = $today; $this->_start_of_month = $start_of_month; $this->_end_of_month = $end_of_month; $this->_start_of_week = $start_of_week; $this->_end_of_week = $end_of_week; }
function __construct() { require_once 'Date.php'; global $pref; $this->time = new Date(); // Convert this original time to UTC so we can get an accurate conversion $localtimeOffset = idate('Z'); // Subtract or add the perfect amount of hours $s = $localtimeOffset / 3600; $hour = $this->time->hour - $s; $this->time->setHour($hour); $this->time->convertTZbyID($pref->prefs['timezone']); $this->timeZone = $this->time->tz; $this->offset = $this->timeZone->offset / 1000; // Set available time zones $this->availableZones = $this->timeZone->getAvailableIDs(); // Set now $this->now['second'] = $this->time->getSecond(); $this->now['minute'] = $this->time->getMinute(); $this->now['hour'] = $this->time->getHour(); $this->now['day'] = $this->time->getDay(); $this->now['month'] = $this->time->getMonth(); $this->now['year'] = $this->time->getYear(); // Set current GMT timestamp $this->timestamp = $this->make($this->now['second'], $this->now['minute'], $this->now['hour'], $this->now['day'], $this->now['month'], $this->now['year']); }
function mysql_to_json($connection_name, $table_name, $file_name) { // Verifies that table name and connection to MySQL exist. if (!$connection_name || !$table_name) { return false; } // If the user did not enter a desired file name, a unique one will be initiated. if (!$file_name) { $file_name = "new_json_file" . idate("U"); } // Type casts input variables to strings in the case that the user entered a different variable type. $table_name = string($table_name); $file_name = string($file_name); // Query data from MySQL server. $data_query = "SELECT * FROM {$table_name}"; $data_request = @mysqli_query($connection_name, $data_query); // Insert queried data into an array. $data_saved[] = array(); while ($entry = mysqli_fetch_assoc($data_request)) { $data_saved[] = $entry; } // Copy array data to file. $file_wrtie = fopen($file_name, 'w'); fwrite($file_write, json_encode($data_saved)); fclose($file_write); // Return true to let the user know that everything ran successfully. return true; }
protected function getDST($timestamp) { if (idate('I', $timestamp)) { return 3600; } return 0; }
public function add() { //checks if data posted by user is valid; helps prevent SQL Injection $valid = true; //16 digit number needed for card if (preg_match("/^(\\d{16})+\$/", $_POST["card"]) === 0) { $_SESSION["cardBorder"] = "1px solid #aa0000"; $_SESSION["cardWarn"] = true; $valid = false; } //checks if expiry date hasn't already passed if ($_POST["expYear"] == idate("y")) { if ($_POST["expMonth"] <= idate("m")) { $_SESSION["expBorder"] = "1px solid #aa0000"; $_SESSION["expWarn"] = true; $valid = false; } } //3 digit number needed for card security number if (preg_match("/^(\\d{3})+\$/", $_POST["secNo"]) === 0) { $_SESSION["secBorder"] = "1px solid #aa0000"; $_SESSION["secWarn"] = true; $valid = false; } if ($valid == false) { $this->view("vwNewCard"); } else { $add = $this->model("Cart"); $add->addCard($_POST["card"], $_POST["expMonth"] . "/" . $_POST["expYear"], $_POST["secNo"], $_SESSION["email"]); $this->view($add->view, $add->message); } }
/** * Run method with main page logic * * Reads in events for a given month or current month if no parameters are passed. * Allow filtering by platform id. Populate template and display event data in a calendar view on the page. * @access public */ public function run() { $PAGINATION_LIMIT = 10; $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $platformDAO = PlatformDAO::getInstance(); //$page = (isset ($_GET["page"]) && is_numeric ($_GET["page"])) ? intval ($_GET["page"]) : 1; $platform_id = isset($_GET["platform"]) && is_numeric($_GET["platform"]) ? intval($_GET["platform"]) : 0; $month = isset($_GET["month"]) && is_numeric($_GET["month"]) ? intval($_GET["month"]) : 0; $year = isset($_GET["year"]) && is_numeric($_GET["year"]) ? intval($_GET["year"]) : 0; //if ($page < 1) { // $page = 1; //} $count = $paginator = $paginator_page = $event_array = $next_eventday = $prev_eventday = $current_platform = null; if ($platform_id > 0 && checkdate($month, 1, $year)) { $start = mktime(0, 0, 0, $month, 1, $year); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countPlatformStatusAndRange ($platform, Event::APPROVED_STATUS, $start, $end); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { if ($platform_id > 0) { $start = mktime(0, 0, 0, idate("m"), 1, idate("Y")); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countPlatformStatusAndRange ($platform, Event::APPROVED_STATUS, $start, $end); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByPlatformStatusAndRange($platform_id, Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { if (checkdate($month, 1, $year)) { $start = mktime(0, 0, 0, $month, 1, $year); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countStatus (Event::APPROVED_STATUS); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } else { $start = mktime(0, 0, 0, idate("m"), 1, idate("Y")); $end = strtotime("+1 month", $start) - 1; //$count = $eventDAO->countStatus (Event::APPROVED_STATUS); //$paginator = new Paginator ($count, 3); //$paginator_page = $paginator->getPage ($page); $event_array = $eventDAO->allByStatusAndRange(Event::APPROVED_STATUS, $start, $end, array("order" => "{$eventDAO->getTableName()}.date DESC, {$eventDAO->getTableName()}.id DESC", "joins" => true)); } } } $next_eventday = $eventDAO->loadByNextDay($end, Event::APPROVED_STATUS); $prev_eventday = $eventDAO->loadByPreviousDay($start, Event::APPROVED_STATUS); if ($platform_id > 0) { $current_platform = $platformDAO->load($platform_id); } $platform_array = $platformDAO->all(); //print_r ($event_array); $this->template->render(array("title" => "Event Month Calendar - " . date("F", $start) . " " . date("Y", $start), "main_page" => "events_month_tpl.php", "event_array" => $event_array, "session" => $session, "start" => $start, "end" => $end, "next_eventday" => $next_eventday, "prev_eventday" => $prev_eventday, "sidebar_extra" => joinPath("fragments", "event_sidebar_tpl.php"), "platform_array" => $platform_array, "current_platform" => $current_platform)); }
private function CalculatePaydays($year, PaydayCalc $calc) { $months = new MonthsCollection(); $months->Slice(idate("m")); while ($months->HasNext()) { $this->_paydays->Add(new Payday($calc->GetSalaryDay($year, $months->Current()))); $this->_paydays->Add(new Payday($calc->GetBonusDay($year, $months->Current()))); $months->Next(); } }
function isHourForAlerts() { date_default_timezone_set('UTC'); $hour = idate("H"); if ($hour != 7) { return true; } else { return false; } }
/** * Constructor. * * @param string $year Year 2014 or * for all (optional) * * @throws \InvalidArgumentException When year value is invalid */ public function __construct($year = '*') { if ($year !== '*' && (strlen($year) !== 4 || !ctype_digit($year))) { throw new \InvalidArgumentException(sprintf('Year value must be like 2014 or "*", "%s" given.', $year)); } if ($year === '*') { $year = idate('Y'); } $this->year = $year; }
function GetNextMeeting() { $time = idate("H") * 100 + idate("i"); // Format time as HHMM (12:34 -> 1234) foreach ($this->meetings as $key => $current) { if ($current->StartTime > $time) { return array($current); } } return array($this->meetings[0]); }
/** * 生成SN编号 * 分为四段 共12位: * 第一段 一位 保留字段 默认为0 * 第二段 三位:生成日期,第一位表示年、第二位表示月、第三位表示日。用字每顺序表示数字,A代表1、B代表2、C代表3,Z代表26以此类推,1代表27、2代表28、3代表29、4代表30、5代表31。 * 第三段 五位随机数: 从00000-99999 (后续可用来扩展流水号等) * 第四段 三位随机数:000-ZZZ * 例如:2015年5月13日生成的一条条形码:0PFN93151DQV * @return string */ public static function getSN() { $a = '0'; $dicArray = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $b = $dicArray[intval(idate('y'))] . $dicArray[intval(idate('m'))] . $dicArray[intval(idate('d'))]; $c = sprintf("%05d", rand(0, 99999)); $d = ''; for ($i = 0; $i < 3; $i++) { $d .= $dicArray[rand(0, 35)]; } return $a . $b . $c . $d; }
public function __construct($args) { if (isset($args['yearRange'][0])) { $this->yearRange[0] = $args['yearRange'][0]; } else { $this->yearRange[0] = intval(date("Y")) - 100; } if (isset($args['yearRange'][1])) { $this->yearRange[1] = $args['yearRange'][1]; } else { $this->yearRange[1] = idate("Y"); } }
function weekdaysInMonth($year, $month) { $date = mktime(0, 0, 0, $month, 1, $year); $daysInMonth = idate("t", $date); $weekdays = 0; for ($d = 1; $d <= $daysInMonth; $d++) { $date = mktime(0, 0, 0, $month, $d, $year); $dayOfWeek = idate("w", $date); if ($dayOfWeek != 0 && $dayOfWeek != 6) { $weekdays++; } } return $weekdays; }
function viewsFirstSixMonthsByYear($dbAdapter) { $gate = new WebsiteVisitsTableGateway($dbAdapter); $result = $gate->getFirstSixMonthsByYear(idate('Y')); $geoTable = "[\n\t\t\t['Country', 'Total Views'],"; $last = end($result); foreach ($result as $country) { $geoTable .= "['" . $country['CountryName'] . "'," . $country['visits'] . "]"; if ($country != $last) { $geoTable .= ","; } } $geoTable .= "]"; return $geoTable; }
/** * Process submission of the default page and do the analysis */ private function processDefaultPage() { list($manuscript_urls, $manuscript_titles, $collection_urls_data, $collection_titles) = $this->request_processor->getDefaultPageData(); $page_titles = $this->getPageTitlesCorrespondingToPostedUrls($manuscript_urls, $manuscript_titles, $collection_urls_data, $collection_titles); $page_texts = $this->getTextsFromWikiPages($manuscript_urls, $collection_urls_data); $collatex_converter = $this->getCollatexConverter(); $collatex_output = $collatex_converter->execute($page_texts); $imploded_page_titles = $this->createImplodedPageTitles($page_titles); $new_url = $this->makeUrlForNewPage($imploded_page_titles); $time = idate('U'); //time format (Unix Timestamp). This timestamp is used to see how old tempcollate values are $this->updateDatabase($page_titles, $imploded_page_titles, $new_url, $time, $collatex_output); $this->viewer->showCollatexOutput($page_titles, $collatex_output, $time); return true; }
function set_timestamp($time) { $this->_jahr = date("Y", $time); $this->_monat = date("n", $time); $this->_tag = date("j", $time); $this->_stunde = date("H", $time); $this->_minute = date("i", $time); $this->_sekunde = 0; if (date("s", $time) == '59' and date("i", $time) == '59') { $this->_minute = '00'; $this->_stunde = $this->_stunde + 1; } $this->_timestamp = $time; $this->_letzterTag = idate('d', mktime(0, 0, 0, $this->_monat + 1, 0, $this->_jahr)); }
public function __construct($name = null, $email = null) { $name = trim($name); if (empty($name)) { $this->name = "Anonymous User"; } else { $this->name = $name; } if (empty($email)) { $this->email = "anonymous@" . (isset($_SERVER) && isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "unknown"); } else { $this->email = $email; } $this->time = time(); $this->offset = idate('Z', $this->time); }
private function ViewCalendar() { $day_one = mktime(0, 0, 0, $this->month, 1, $this->year); //number of spaces on the first line of the calendar: $space = idate('w', $day_one); //total number of days in the month: $total_day = idate('t', $day_one); //other info about the month: $wantday = getdate($day_one); $dayint = 0; $this->linkurl = 'index.php?Action=ViewPost&blogID=' . $this->blogID . '&year=' . $this->year . '&month=' . $this->month . '&date='; if ($this->month != $this->today['mon'] || $this->year != $this->today['year']) { $lookingAtOtherMonth = true; } //top row - static $cal .= "\n" . '<table border="0" cellpadding="0" cellspacing="0" id="calendar_table">' . "\n" . '<tr id="calendar_week_row">' . "\n" . '<td id="calendar_week">Sun</td>' . "\n" . '<td id="calendar_week">Mon</td>' . "\n" . '<td id="calendar_week">Tue</td>' . "\n" . '<td id="calendar_week">Wed</td>' . "\n" . '<td id="calendar_week">Thu</td>' . "\n" . '<td id="calendar_week">Fri</td>' . "\n" . '<td id="calendar_week">Sat</td>' . "\n" . '</tr><tr>' . "\n"; //1st row, skipping spaces until we hit the 1st of the month for ($count = 0; $count < 7; ++$count) { if ($count >= $space) { $dayint++; $daystr = $this->getDayString($lookingAtOtherMonth, $dayint); } else { $daystr = '<td></td>'; } $cal .= $daystr . "\n"; } $cal .= "</tr>\n"; //after 1st row //for each row: while (!$done) { $cal .= "<tr>\n"; //for each day in a row: for ($count = 0; $count < 7; ++$count) { $dayint++; if (!($dayint <= $total_day)) { $daystr = ''; $done = true; } else { $daystr = $this->getDayString($lookingAtOtherMonth, $dayint); } $cal .= $daystr . "\n"; } $cal .= "</tr>\n"; } return $cal . "</table>\n"; }
/** * Sets variables for view of "Default" page */ public function renderDefault() { $template = $this->template; $template->title = "Kronika"; $vp = new \VisualPaginator($this, 'vp'); $vp->short = FALSE; //output the whole list $vp->setTemplate('template-schoolyear.phtml'); $paginator = $vp->getPaginator(); $year = idate("m") < 8 ? idate("Y") - 1 : idate("Y"); //school year start in August $paginator->setBase($this->context->parameters['baseChronicleYear']); $page = $vp->page ? $vp->page : $year; $paginator->setItemCount($year - $paginator->getBase() + 1); $paginator->setItemsPerPage(1); $paginator->setPage($page); $template->chronicles = $this->events->getEventsForChronicle($page); }
/** * 格式化日期 */ public static function formatDate2($timestamp = '', $noSecond = false) { if (empty($timestamp)) { return '1分钟内'; } $_timestamp = idate('U'); $_lang_day = '天'; $_lang_hour = '小时'; $_lang_minute = '分钟'; $_lang_minute2 = '分'; $_lang_second = '秒钟'; $_lang_now = '现在'; $result = ''; $time = $timestamp; if ($time > 24 * 3600) { $result = floor($time / (24 * 3600)) . $_lang_day; if ($time - floor($time / (24 * 3600)) * 24 * 3600 > 3600) { $result .= floor(($time - floor($time / (24 * 3600)) * 24 * 3600) / 3600) . $_lang_hour; } } elseif ($time >= 3600) { $result = floor($time / 3600) . $_lang_hour; if ($time - floor($time / 3600) * 3600 > 0) { $result .= floor(($time - floor($time / 3600) * 3600) / 60) . $_lang_minute2; } if ($noSecond) { $result .= '前'; } } elseif ($time >= 60) { $result = intval($time / 60) . $_lang_minute; if ($noSecond) { $result .= '前'; } } elseif ($time > 0) { if (!$noSecond) { $result = $time . $_lang_second; } else { $result = '1分钟前'; } } else { $result = $_lang_now; } return $result; }
function birthday_check($birthday) { $current_year = idate('Y'); $current_yday = idate('z'); $dateTime = new DateTime($birthday); $year = $dateTime->format('Y'); $month = $dateTime->format('m'); $day = $dateTime->format('d'); $check = ($current_year - $year - 1) * 365; $yday = 365 - ($month - 1) * 30 - $day; $check += $yday + $current_yday; $check /= 365; if ($check >= 18) { return TRUE; } else { $this->form_validation->set_message('birthday_check', 'The %s should be at 18 years old'); return FALSE; } }
function get_timelineauction($pubtime) { $time = time(); /** 如果不是同一年 */ if (idate('Y', $time) != idate('Y', $pubtime)) { return date('Y-m-d', $pubtime); } /** 以下操作同一年的日期 */ $seconds = $time - $pubtime; $days = idate('z', $time) - idate('z', $pubtime); /** 如果是同一天 */ if ($days == 0) { /** 如果是一小时内 */ if ($seconds < 3600) { /** 如果是一分钟内 */ if ($seconds < 60) { if (3 > $seconds) { return '刚刚'; } else { return $seconds . '秒前'; } } return intval($seconds / 60) . '分钟前'; } return idate('H', $time) - idate('H', $pubtime) . '小时前'; } /** 如果是昨天 */ if ($days == 1) { return '昨天 ' . date('H:i', $pubtime); } /** 如果是前天 */ if ($days == 2) { return '前天 ' . date('H:i', $pubtime); } /** 如果是7天内 */ if ($days < 7) { return $days . '天前'; } /** 超过7天 */ return date('n-j H:i', $pubtime); }
private static function idate($format, $timestamp) { switch ($format) { case "D": $value = self::getShortWeekdayName(idate("j", $timestamp) - 1); break; case "l": $value = self::getWeekdayName(idate("j", $timestamp) - 1); break; case "M": $value = self::getShortMonthName(idate("n", $timestamp) - 1); break; case "F": $value = self::getMonthName(idate("n", $timestamp) - 1); break; default: $value = date($format, $timestamp); // using date() because idate() chokes on unknown chars and trims leading zeroes break; } return $value; }
/** * Get a list of intervals for a given period * @param string $step Interval descriptor as defined in BsDiagram * @param string $offset Date string * @param string $limit Date string * @param string $modLabel Date format item, e.g. "M" for "Jan, Feb" * @return Interval */ public static function getIntervals($step = "W", $offset = '05/01/2007', $limit = '01/31/2009', $modLabel = false) { $intervals = array(); $starttime = strtotime($offset); $endtime = strtotime($limit); $interval = new Interval(); $interval->setStartTS($starttime); $old = idate($step, $starttime); if ($modLabel) { $interval->setLabel(date($modLabel, $starttime)); } else { $interval->setLabel($old); } $oldts = $starttime; for ($ts = $starttime; $ts <= $endtime; $ts += 86400) { $oldts = $ts - 1; $cur = idate($step, $ts); if ($old != $cur) { $interval->setEndTS($oldts); $intervals[] = $interval; $interval = new Interval(); $interval->setStartTS($ts); if ($modLabel) { $interval->setLabel(date($modLabel, $ts)); } else { $interval->setLabel($cur); } //echo "<br/>-----------------------"; } $old = $cur; //echo "<br/>".$oldts." :: ".date("d.m.YHis", $oldts-1); } $oldts = $oldts + 86400; $interval->setEndTS($oldts); $intervals[] = $interval; //var_dump($intervals); return $intervals; }
function smarty_modifier_date_familiar($datetime) { $date_secs = strtotime($datetime); $days_since = idate("z") - idate("z", $date_secs); if ($days_since < 7) { if ($days_since == 0) { return "This " . Log::evaluateTime($datetime); } elseif ($days_since == 1) { return "Yesterday " . Log::evaluateTime($datetime); } else { return date("l", $date_secs) . " " . Log::evaluateTime($datetime); } } $weeks_since = idate("W") - idate("W", $date_secs); $months_since = idate("m") - idate("m", $date_secs); if ($months_since == 0) { switch ($weeks_since) { case 1: return "Last week"; break; case 2: return "Two weeks ago"; break; case 3: return "Three weeks ago"; break; case 4: return "Four weeks ago"; break; } } elseif ($months_since == 1) { return "Last month"; } elseif ($months_since > 1) { return date("F Y", $date_secs); } }
function getToIsoWeek(DateTime $date) { $iso_week = idate('W', $date->getTimestamp()); return intval($iso_week); }