PHP Classes

File: Timestamp.php

Recommend this page to a friend!
  Classes of Eugene Panin   Timestamp   Timestamp.php   Download  
File: Timestamp.php
Role: Class source
Content type: text/plain
Description: Library
Class: Timestamp
Formats timestamps
Author: By
Last change: Documentation changed
Date: 21 years ago
Size: 2,403 bytes
 

Contents

Class file image Download
<?php
/**
 * Timestamp class.
 * Intended to handle timestamp and calculate it for different GMT shifts
 *
 * @author Eugene Panin <varenich@yahoo.com>
 * @home http://www.tortuga.pp.ru
 * @package Timestamp
 * @version 1.0
 * @access public
 */
class Timestamp {

 
/**
   * Timestamp value
   *
   * @var string Unix timestamp
   * @access private
   */
 
var $_val = '';

 
/**
   * Local place GMT shift
   *
   * @var int
   * @access private
   */
 
var $_ls = 0;

 
/**
   * Remote place GMT shift
   *
   * @var int
   * @access private
   */
 
var $_rs = 0;

 
/**
   * Constructor
   *
   * @param string $val Unix timestamp
   * @return object Timestamp
   * @access public
   */
 
function Timestamp($val='') {
    if (
$val) {
     
$this->_val = $val;
    }
    else {
     
$this->_val = time();
    }
  }

 
/**
   * Sets timestamp
   *
   * @param string $val Unix timestamp
   * @return void
   * @access public
   */
 
function setValue($val) {
   
$this->_val = $val;
  }

 
/**
   * Returns timestamp
   *
   * @param string $format Format (see strftime)
   * @param int $tps This place GMT shift
   * @param int $rps Remote place GMT shift
   * @return string Unix timestamp
   * @access public
   */
 
function getValue($format='') {
   
$res = $this->_val;
    if (
$this->_ls && $this->_rs) {
     
$lsSeconds = $this->_ls*60*60;
     
$rsSeconds = $this->_rs*60*60;
     
$res = $res + ($rsSeconds-$lsSeconds);
    }
    if (
$format) {
     
$res = strftime($format,$res);
    }
    return
$res;
  }

 
/**
   * Sets local place timestamp
   *
   * @param string $val Unix timestamp
   * @return void
   * @access public
   */
 
function setLocalGMTShift($val) {
   
$this->_ls = $val;
  }

 
/**
   * Returns local place GTM shift
   *
   * @return int GMT shift
   * @access public
   */
 
function getLocalGMTShift() {
    return
$this->_ls;
  }

 
/**
   * Sets remote place timestamp
   *
   * @param string $val Unix timestamp
   * @return void
   * @access public
   */
 
function setRemoteGMTShift($val) {
   
$this->_rs = $val;
  }

 
/**
   * Returns remote place GTM shift
   *
   * @return int GMT shift
   * @access public
   */
 
function getRemoteGMTShift() {
    return
$this->_rs;
  }


}
// class
?>