PHP Classes

File: timeclass.php

Recommend this page to a friend!
  Classes of seun makinde   PHP Time Class   timeclass.php   Download  
File: timeclass.php
Role: Class source
Content type: text/plain
Description: the main class
Class: PHP Time Class
Manipulate times and dates
Author: By
Last change: created double version for 3 upward and 5
Date: 12 years ago
Size: 10,732 bytes
 

Contents

Class file image Download
<?php /** * @author seun makinde williams (seuntech) * @copyright 2011 * @version 1.0 * @tutorial for help or more script visit www.1plusalltutor.com * @link http://www.1plusalltutor.com * @license * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * */ class timekeeper { function check($current_time) { $this->current_time = trim($current_time); if (!filter_var($this->current_time, FILTER_VALIDATE_INT) || strlen($this-> current_time) < 9) { $this->current_time = strtotime($this->current_time); } else { $this->current_time = $this->current_time; } return (int)$this->current_time; } function time_stamp($current_time) { $this->current_time = timekeeper::check($current_time); $this->difference = time() - $this->current_time; $this->seconds = $this->difference; $this->minutes = round($this->difference / 60); $this->hours = round($this->difference / 3600); $this->days = round($this->difference / 86400); $this->weeks = round($this->difference / 604800); $this->months = round($this->difference / 2419200); $this->years = round($this->difference / 29030400); // Seconds if ($this->seconds <= 60) { return $this->seconds . " Second ago"; } //Minutes if ($this->minutes <= 60) { if ($this->minutes == 1) { return "1 Minute ago"; } else { return $this->minutes . " Minutes ago"; } } //Hours if ($this->hours <= 24) { if ($this->hours == 1) { return "1 hour ago"; } else { return $this->hours . " hours ago"; } } //Yesterday if ($this->days <= 3) { return "yesterday"; } //Days if ($this->days <= 7) { if ($this->days == 1) { return "24 Hours ago"; } else { return $this->days . " days ago"; } } //Weeks if ($this->weeks <= 4) { if ($this->weeks == 1) { return "7 days ago"; } else { return $this->weeks . " weeks ago"; } } //Months if ($this->months <= 12) { if ($this->months == 1) { return "4 weeks ago"; } else { return $this->months . " months ago"; } } //Years if ($this->years == 1) { return "12 months ago"; } else { return $this->years . " years ago"; } } #llllllllllllllllllllllllllllllllllllllllllllllllllllll function Weekdays($start, $end, $day, $include_start_end = false) { $this->start = $start; $this->end = $end; $this->day = $day; $this->days = 0; $this->include_start_end = $include_start_end; $this->start = timekeeper::check($this->start); $this->end = timekeeper::check($this->end); $this->day = strtolower($this->day); $current_ts = $this->start; // loop next $this->day until timestamp past $this->end while ($current_ts < $this->end) { if (($current_ts = strtotime('next ' . $this->day, $current_ts)) < $this->end) { $this->days++; } } // include start/end days if ($this->include_start_end) { if (strtolower(date('l', $this->start)) == $this->day) { $this->days++; } if (strtolower(date('0', $this->end)) == $this->day) { $this->days++; } } return (int)$this->days; } #future time function time_past($case, $time) { $this->case = ucwords($case) . substr($time, 0, 1); $this->time = substr($time, 1, 50); switch ($this->case) { case "H-": $this->tomorrow = mktime(date("H") - $this->time, date("i"), date("s"), date("m"), date("d"), date("y")); break; case "H+": $this->tomorrow = mktime(date("H") + $this->time, date("i"), date("s"), date("m"), date("d"), date("y")); break; case "I-": $this->tomorrow = mktime(date("H"), date("i") - $this->time, date("s"), date("m"), date("d"), date("y")); break; case "I+": $this->tomorrow = mktime(date("H"), date("i") + $this->time, date("s"), date("m"), date("d"), date("y")); break; case "S-": $this->tomorrow = mktime(date("H"), date("i"), date("s") - $this->time, date("m"), date("d"), date("y")); break; case "S+": $this->tomorrow = mktime(date("H"), date("i"), date("s") + $this->time, date("m"), date("d"), date("y")); break; case "M-": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m") - $this-> time, date("d"), date("y")); break; case "M+": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m") + $this-> time, date("d"), date("y")); break; case "D-": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $this->time, date("y")); break; case "D+": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $this->time, date("y")); break; case "Y-": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("y") - $this->time); break; case "Y+": $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("y") + $this->time); break; default: $this->tomorrow = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("y")); break; } return date("Y-m-d H:i:s", $this->tomorrow); } #days deference function time_deffernce($date2, $date1, $format = "D") { $this->case = ucwords($format); $this->start_date = timekeeper::check($date1); $this->end_date = timekeeper::check($date2); $this->new_date = $this->start_date - $this->end_date; switch ($this->case) { case "S": $this->date = $this->new_date; break; case "I": $this->date = round($this->new_date / 60); break; case "H": $this->date = round($this->new_date / 3600); break; case "D": $this->date = round($this->new_date / 86400); break; case "W": $this->date = round($this->new_date / 604800); break; case "M": $this->date = round($this->new_date / 2419200); break; case "Y": $this->date = round($this->new_date / 29030400); break; default: $this->date = round($this->new_date / 86400); break; } return $this->date; } #sesionnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn function season() { $this->seasons = array("Winter", "Spring", "Summer", "Autumn"); return $this->seasons[(int)((date("n") % 12) / 3)]; } #drop down year function drop_year($period) { $this->time = substr($period, 1, 50); $this->case = substr($period, 0, 1); switch ($this->case) { case "-": $this->end = date('Y') - $this->time; break; case "+": $this->end = date('Y') + $this->time; break; default: $this->end = date('Y') - 18; break; } $this->start = "1910"; $this->year = array(); for ($i = $this->start; $i <= $this->end; $i++) { $this->year[] = $i; } return $this->year; } #time coversion function convert_time($time, $output = "Y-m-d H:i:s") { $this->time = $time; $this->output = $output; return date($this->output, $this->time); } #calendar function calendar($month, $year) { $this->month = $month; $this->year = $year; $this->timestamp = mktime(0, 0, 0, $this->month, 1, $this->year); #timestamp $this->maxday = date("t", $this->timestamp); #finds length of given month $this->startday = date("N", $this->timestamp); #this month day 1, day of the week, numeric $this->calendar = ""; for ($i = 0; $i < ($this->maxday + $this->startday); $i++) { if (($i % 7) == 0) { $this->calendar .= "<tr>"; } if ($i < $this->startday) { $this->calendar .= "<td></td>"; } else { if ($i - $this->startday + 1 == date('j')) { $this->calendar .= "<td align='center' style='background-color:#cccccc; color:white; height:20px;'>" . ($i - $this->startday + 1) . "</td>"; } else { $this->calendar .= "<td align='center' height='20px'>" . ($i - $this->startday + 1) . "</td>"; } } if (($i % 7) == 6) $this->calendar .= "</tr>"; } return $this->calendar; } function number_month($month) { return date('F', mktime(0, 0, 0, $month)); } } ?>