Changeset 440

Show
Ignore:
Timestamp:
05/18/07 10:20:59 (2 years ago)
Author:
bballizlife
Message:

changes in jDateTime according ticket+patch #176

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/utils/jDateTime.class.php

    r386 r440  
    55* @author      Gérald Croes, Laurent Jouanneau 
    66* @contributor Laurent Jouanneau 
     7* @contributor Loic Mathaud 
    78* @copyright   2001-2005 CopixTeam 2005-2006 Laurent Jouanneau 
     9* @copyright   2007 Loic Mathaud 
    810* @link        http://www.jelix.org 
    911* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     
    246248    /** 
    247249     * add a duration to the date 
    248      * @param jDateTime $dt the duration value 
    249      */ 
    250     public function add($dt){ 
    251  
     250     * @param jDateTime/int $year the duration value or a year with 4 digits 
     251     * @param int $month month with 2 digits 
     252     * @param int $day day with 2 digits 
     253     * @param int $hour hour with 2 digits 
     254     * @param int $minute minute with 2 digits 
     255     * @param int $second second with 2 digits 
     256     */ 
     257    public function add($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 
     258        if ($year instanceof jDateTime) { 
     259            $dt = $year; 
     260        } else { 
     261            $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 
     262        } 
    252263        $t = mktime ( $this->hour +  $dt->hour, $this->minute + $dt->minute, $this->second + $dt->second , 
    253264             $this->month + $dt->month, $this->day + $dt->day, $this->year + $dt->year); 
     
    264275    /** 
    265276     * substract a duration to the date 
    266      * @param jDateTime $dt the duration value 
    267      */ 
    268     public function sub($dt){ 
     277     * @param jDateTime/int $year the duration value or a year with 4 digits 
     278     * @param int $month month with 2 digits 
     279     * @param int $day day with 2 digits 
     280     * @param int $hour hour with 2 digits 
     281     * @param int $minute minute with 2 digits 
     282     * @param int $second second with 2 digits 
     283     */ 
     284    public function sub($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 
     285        if ($year instanceof jDateTime) { 
     286            $dt = $year; 
     287        } else { 
     288            $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 
     289        } 
    269290        $t = mktime ( $this->hour -  $dt->hour, $this->minute - $dt->minute, $this->second - $dt->second , 
    270291             $this->month - $dt->month, $this->day - $dt->day, $this->year - $dt->year); 
     
    305326    } 
    306327 
     328    /** 
     329    * set date to current datetime 
     330    */ 
     331    public function now() { 
     332        $this->year = date('Y'); 
     333        $this->month = date('m'); 
     334        $this->day = date('d'); 
     335        $this->hour = date('H'); 
     336        $this->minute = date('i'); 
     337        $this->second = date('s'); 
     338    } 
    307339} 
    308340 
Download in other formats: Unified Diff Zip Archive