Versions
Look up a class, method, property or event

CTimestamp

Package system.utils
Inheritance class CTimestamp
Since 1.0
Version $Id: CTimestamp.php 1571 2009-12-11 02:39:21Z qiang.xue $
CTimestamp represents a timestamp.

This class was adapted from the ADOdb Date Library, as part of the ADOdb abstraction library. The original source code was released under both BSD and GNU Lesser GPL library license, with the following copyright notice: Copyright (c) 2000, 2001, 2002, 2003, 2004 John Lim All rights reserved.

PHP native date static functions use integer timestamps for computations. Because of this, dates are restricted to the years 1901-2038 on Unix and 1970-2038 on Windows due to integer overflow for dates beyond those years. This library overcomes these limitations by replacing the native static function's signed integers (normally 32-bits) with PHP floating point numbers (normally 64-bits).

Dates from 100 A.D. to 3000 A.D. and later have been tested. The minimum is 100 A.D. as <100 will invoke the 2 => 4 digit year conversion. The maximum is billions of years in the future, but this is a theoretical limit as the computation of that year would take too long with the current implementation of getTimestamp.

PERFORMANCE For high speed, this library uses the native date static functions where possible, and only switches to PHP code when the dates fall outside the 32-bit signed integer range.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
formatDate() Formats a timestamp to a date string. CTimestamp
get4DigitYear() Returns 4-digit representation of the year. CTimestamp
getDate() Returns the getdate() array. CTimestamp
getDayofWeek() Gets day of week, 0 = Sunday,... 6=Saturday. CTimestamp
getGMTDiff() CTimestamp
getTimestamp() Generates a timestamp. CTimestamp
isLeapYear() Checks for leap year, returns true if it is. No 2-digit year check. Also CTimestamp
isValidDate() Checks to see if the year, month, day are valid combination. CTimestamp
isValidTime() Checks to see if the hour, minute and second are valid. CTimestamp

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
digitCheck() Fix 2-digit years. Works for any century. CTimestamp

Method Details

digitCheck() method
protected static integer digitCheck(integer $y)
$y integer year
{return} integer change two digit year into multiple digits

Fix 2-digit years. Works for any century. Assumes that if 2-digit is more than 30 years in future, then previous century.

formatDate() method
public static string formatDate(string $fmt, integer $d=false, boolean $is_gmt=false)
$fmt string format pattern
$d integer timestamp
$is_gmt boolean whether this is a GMT timestamp
{return} string formatted date based on timestamp $d

Formats a timestamp to a date string.

get4DigitYear() method
public static integer get4DigitYear(integer $y)
$y integer year
{return} integer 4-digit representation of the year

Returns 4-digit representation of the year.

getDate() method
public static array getDate(integer $d=false, boolean $fast=false, boolean $gmt=false)
$d integer original date timestamp. False to use the current timestamp.
$fast boolean false to compute the day of the week, default is true
$gmt boolean true to calculate the GMT dates
{return} array an array with date info.

Returns the getdate() array.

getDayofWeek() method
public static integer getDayofWeek(integer $year, integer $month, integer $day)
$year integer year
$month integer month
$day integer day
{return} integer day of week

Gets day of week, 0 = Sunday,... 6=Saturday. Algorithm from PEAR::Date_Calc

getGMTDiff() method
public static integer getGMTDiff()
{return} integer get local time zone offset from GMT

getTimestamp() method
public static integer|float getTimestamp(integer $hr, integer $min, integer $sec, integer $mon=false, integer $day=false, integer $year=false, boolean $is_gmt=false)
$hr integer hour
$min integer minute
$sec integer second
$mon integer month
$day integer day
$year integer year
$is_gmt boolean whether this is GMT time
{return} integer|float a timestamp given a local time. Originally by jackbbs.

Generates a timestamp. Not a very fast algorithm - O(n) operation. Could be optimized to O(1).

isLeapYear() method
public static boolean isLeapYear(integer $year)
$year integer year to check
{return} boolean true if is leap year

Checks for leap year, returns true if it is. No 2-digit year check. Also handles julian calendar correctly.

isValidDate() method
public static boolean isValidDate(integer $y, integer $m, integer $d)
$y integer year
$m integer month
$d integer day
{return} boolean true if valid date, semantic check only.

Checks to see if the year, month, day are valid combination.

isValidTime() method (available since v1.0.5)
public static boolean isValidTime(integer $h, integer $m, integer $s, boolean $hs24=true)
$h integer hour
$m integer minute
$s integer second
$hs24 boolean whether the hours should be 0 through 23 (default) or 1 through 12.
{return} boolean true if valid date, semantic check only.

Checks to see if the hour, minute and second are valid.

Be the first person to leave a comment

Please to leave your comment.