Changeset 876
- Timestamp:
- 04/12/08 08:29:07 (8 months ago)
- Files:
-
- trunk/build/manifests/jelix-lib.mn (modified) (1 diff)
- trunk/build/manifests/jelix-lib.mn (modified) (1 diff)
- trunk/build/manifests/jelix-lib.mn (modified) (1 diff)
- trunk/build/manifests/jelix-lib.mn (modified) (1 diff)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/utils/jDateTime.class.php (modified) (9 diffs)
- trunk/lib/jelix/utils/jDateTime.class.php (modified) (9 diffs)
- trunk/lib/jelix/utils/jDateTime.class.php (modified) (9 diffs)
- trunk/lib/jelix/utils/jDateTime.class.php (modified) (9 diffs)
- trunk/lib/jelix/utils/jDuration.class.php (added)
- trunk/lib/jelix/utils/jDuration.class.php (added)
- trunk/lib/jelix/utils/jDuration.class.php (added)
- trunk/lib/jelix/utils/jDuration.class.php (added)
- trunk/testapp/modules/jelix_tests/tests/utils.jduration.html_cli.php (added)
- trunk/testapp/modules/jelix_tests/tests/utils.jduration.html_cli.php (added)
- trunk/testapp/modules/jelix_tests/tests/utils.jduration.html_cli.php (added)
- trunk/testapp/modules/jelix_tests/tests/utils.jduration.html_cli.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/jelix-lib.mn
r873 r876 301 301 jDatatype.class.php 302 302 jDateTime.class.php 303 jDuration.class.php 303 304 jFile.class.php 304 305 * jFilter.class.php trunk/build/manifests/jelix-lib.mn
r873 r876 301 301 jDatatype.class.php 302 302 jDateTime.class.php 303 jDuration.class.php 303 304 jFile.class.php 304 305 * jFilter.class.php trunk/build/manifests/jelix-lib.mn
r873 r876 301 301 jDatatype.class.php 302 302 jDateTime.class.php 303 jDuration.class.php 303 304 jFile.class.php 304 305 * jFilter.class.php trunk/build/manifests/jelix-lib.mn
r873 r876 301 301 jDatatype.class.php 302 302 jDateTime.class.php 303 jDuration.class.php 303 304 jFile.class.php 304 305 * jFilter.class.php trunk/build/manifests/testapp.mn
r864 r876 163 163 jtpl.plugins.html.php 164 164 utils.jdatatype.html_cli.php 165 utils.jduration.html_cli.php 165 166 utils.jfilter.html_cli.php 166 167 utils.jlog.html_cli.php trunk/build/manifests/testapp.mn
r864 r876 163 163 jtpl.plugins.html.php 164 164 utils.jdatatype.html_cli.php 165 utils.jduration.html_cli.php 165 166 utils.jfilter.html_cli.php 166 167 utils.jlog.html_cli.php trunk/build/manifests/testapp.mn
r864 r876 163 163 jtpl.plugins.html.php 164 164 utils.jdatatype.html_cli.php 165 utils.jduration.html_cli.php 165 166 utils.jfilter.html_cli.php 166 167 utils.jlog.html_cli.php trunk/build/manifests/testapp.mn
r864 r876 163 163 jtpl.plugins.html.php 164 164 utils.jdatatype.html_cli.php 165 utils.jduration.html_cli.php 165 166 utils.jfilter.html_cli.php 166 167 utils.jlog.html_cli.php trunk/lib/jelix/CREDITS
r868 r876 99 99 Florian Hatat (aka flh) 100 100 - improvements on jDateTime + RFC2822 support (#379) 101 - Fix bugs on duration calculation + new jDuration class (#425, #453) 101 102 102 103 Nicolas Jeudy (aka njeudy) trunk/lib/jelix/CREDITS
r868 r876 99 99 Florian Hatat (aka flh) 100 100 - improvements on jDateTime + RFC2822 support (#379) 101 - Fix bugs on duration calculation + new jDuration class (#425, #453) 101 102 102 103 Nicolas Jeudy (aka njeudy) trunk/lib/jelix/CREDITS
r868 r876 99 99 Florian Hatat (aka flh) 100 100 - improvements on jDateTime + RFC2822 support (#379) 101 - Fix bugs on duration calculation + new jDuration class (#425, #453) 101 102 102 103 Nicolas Jeudy (aka njeudy) trunk/lib/jelix/CREDITS
r868 r876 99 99 Florian Hatat (aka flh) 100 100 - improvements on jDateTime + RFC2822 support (#379) 101 - Fix bugs on duration calculation + new jDuration class (#425, #453) 101 102 102 103 Nicolas Jeudy (aka njeudy) trunk/lib/jelix/utils/jDateTime.class.php
r739 r876 7 7 * @contributor Loic Mathaud 8 8 * @contributor Florian Hatat 9 * @copyright 2005-200 6Laurent Jouanneau9 * @copyright 2005-2008 Laurent Jouanneau 10 10 * @copyright 2007 Loic Mathaud 11 * @copyright 2007 Florian Hatat11 * @copyright 2007-2008 Florian Hatat 12 12 * @copyright 2001-2005 CopixTeam, GeraldCroes, Laurent Jouanneau 13 13 * … … 283 283 if($match[6] != '') $this->second = $match[6]; 284 284 if($match[8] != 'Z'){ 285 $d = new jD ateTime(0,0,0,$match[10],$match[11]);285 $d = new jDuration(array('hour'=>$match[10],'minute'=>$match[11])); 286 286 if($match[9] == '+') 287 287 $this->add($d); … … 331 331 # Adjust according to the timezone, so that the stored time 332 332 # corresponds to UTC. 333 $tz = new jD ateTime(0, 0, 0,intval($match['tzhour']),334 intval($match['tzminute']), 0);333 $tz = new jDuration(array('hour'=>intval($match['tzhour']), 334 'minute'=>intval($match['tzminute']))); 335 335 if($match['tzsign'] == '+'){ 336 336 $this->sub($tz); … … 348 348 /** 349 349 * Add a duration to the date. 350 * You can specify the duration in a jD ateTime object (which then is not a date/time)351 * or give each value of the duration352 * @param jD ateTime/int $year the duration value or a year with 4 digits350 * You can specify the duration in a jDuration object or give each value of 351 * the duration. 352 * @param jDuration/int $year the duration value or a year with 4 digits 353 353 * @param int $month month with 2 digits 354 354 * @param int $day day with 2 digits … … 358 358 */ 359 359 public function add($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 360 if ($year instanceof jD ateTime) {360 if ($year instanceof jDuration) { 361 361 $dt = $year; 362 362 } else { 363 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 364 } 365 $t = mktime ( $this->hour + $dt->hour, $this->minute + $dt->minute, $this->second + $dt->second , 366 $this->month + $dt->month, $this->day + $dt->day, $this->year + $dt->year); 363 $dt = new jDuration(array("year" => $year, "month" => $month, 364 "day" => $day, "hour" => $hour, "minute" => $minute, 365 "second" => $second)); 366 } 367 $t = mktime($this->hour, $this->minute, $this->second + $dt->seconds, 368 $this->month + $dt->months, $this->day + $dt->days, $this->year); 367 369 368 370 $t = getdate ($t); … … 377 379 /** 378 380 * substract a <b>duration</b> to the date 379 * You can specify the duration in a jD ateTime object (which then is not a date/time)380 * or give each value of the duration381 * @param jD ateTime/int $year the duration value or a year with 4 digits381 * You can specify the duration in a jDuration object or give each value of 382 * the duration. 383 * @param jDuration/int $year the duration value or a year with 4 digits 382 384 * @param int $month month with 2 digits 383 385 * @param int $day day with 2 digits … … 387 389 */ 388 390 public function sub($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 389 if ($year instanceof jD ateTime) {391 if ($year instanceof jDuration) { 390 392 $dt = $year; 391 393 } else { 392 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 393 } 394 $t = mktime ( $this->hour - $dt->hour, $this->minute - $dt->minute, $this->second - $dt->second , 395 $this->month - $dt->month, $this->day - $dt->day, $this->year - $dt->year); 396 397 $t = getdate ($t); 398 $this->year = $t['year']; 399 $this->month = $t['mon']; 400 $this->day = $t['mday']; 401 $this->hour = $t['hours']; 402 $this->minute = $t['minutes']; 403 $this->second = $t['seconds']; 394 $dt = new jDuration(array("year" => $year, "month" => $month, 395 "day" => $day, "hour" => $hour, "minute" => $minute, 396 "second" => $second)); 397 } 398 $dt->mult(-1); 399 $this->add($dt); 404 400 } 405 401 … … 407 403 * to know the duration between two dates. 408 404 * @param jDateTime $dt the date on which a sub will be made with the date on the current object 409 * @return jDateTime a jDateTime object which will contains <b>a duration</b> (not a date) 410 */ 411 public function durationTo($dt){ 412 $t = mktime ( $dt->hour, $dt->minute,$dt->second , $dt->month, $dt->day, $dt->year ) 413 - mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year ); 414 $t = getdate ($t); 415 return new jDateTime( $t['year']-1970,$t['mon']-1, $t['mday']-1, $t['hours']-1, $t['minutes'], $t['seconds']); 405 * @param bool $absolute 406 * @return jDuration a jDuration object 407 */ 408 public function durationTo($dt, $absolute=true){ 409 if($absolute){ 410 $t = mktime($dt->hour, $dt->minute, $dt->second, 411 $dt->month, $dt->day, $dt->year) 412 - mktime($this->hour, $this->minute, $this->second, 413 $this->month, $this->day, $this->year); 414 return new jDuration($t); 415 } 416 else{ 417 return new jDuration(array( 418 "year" => $dt->year - $this->year, 419 "month" => $dt->month - $this->month, 420 "day" => $dt->day - $this-> day, 421 "hour" => $dt->hour - $this->hour, 422 "minute" => $dt->minute - $this->minute, 423 "second" => $dt->second - $this->second 424 )); 425 } 416 426 } 417 427 … … 444 454 } 445 455 } 446 447 ?>trunk/lib/jelix/utils/jDateTime.class.php
r739 r876 7 7 * @contributor Loic Mathaud 8 8 * @contributor Florian Hatat 9 * @copyright 2005-200 6Laurent Jouanneau9 * @copyright 2005-2008 Laurent Jouanneau 10 10 * @copyright 2007 Loic Mathaud 11 * @copyright 2007 Florian Hatat11 * @copyright 2007-2008 Florian Hatat 12 12 * @copyright 2001-2005 CopixTeam, GeraldCroes, Laurent Jouanneau 13 13 * … … 283 283 if($match[6] != '') $this->second = $match[6]; 284 284 if($match[8] != 'Z'){ 285 $d = new jD ateTime(0,0,0,$match[10],$match[11]);285 $d = new jDuration(array('hour'=>$match[10],'minute'=>$match[11])); 286 286 if($match[9] == '+') 287 287 $this->add($d); … … 331 331 # Adjust according to the timezone, so that the stored time 332 332 # corresponds to UTC. 333 $tz = new jD ateTime(0, 0, 0,intval($match['tzhour']),334 intval($match['tzminute']), 0);333 $tz = new jDuration(array('hour'=>intval($match['tzhour']), 334 'minute'=>intval($match['tzminute']))); 335 335 if($match['tzsign'] == '+'){ 336 336 $this->sub($tz); … … 348 348 /** 349 349 * Add a duration to the date. 350 * You can specify the duration in a jD ateTime object (which then is not a date/time)351 * or give each value of the duration352 * @param jD ateTime/int $year the duration value or a year with 4 digits350 * You can specify the duration in a jDuration object or give each value of 351 * the duration. 352 * @param jDuration/int $year the duration value or a year with 4 digits 353 353 * @param int $month month with 2 digits 354 354 * @param int $day day with 2 digits … … 358 358 */ 359 359 public function add($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 360 if ($year instanceof jD ateTime) {360 if ($year instanceof jDuration) { 361 361 $dt = $year; 362 362 } else { 363 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 364 } 365 $t = mktime ( $this->hour + $dt->hour, $this->minute + $dt->minute, $this->second + $dt->second , 366 $this->month + $dt->month, $this->day + $dt->day, $this->year + $dt->year); 363 $dt = new jDuration(array("year" => $year, "month" => $month, 364 "day" => $day, "hour" => $hour, "minute" => $minute, 365 "second" => $second)); 366 } 367 $t = mktime($this->hour, $this->minute, $this->second + $dt->seconds, 368 $this->month + $dt->months, $this->day + $dt->days, $this->year); 367 369 368 370 $t = getdate ($t); … … 377 379 /** 378 380 * substract a <b>duration</b> to the date 379 * You can specify the duration in a jD ateTime object (which then is not a date/time)380 * or give each value of the duration381 * @param jD ateTime/int $year the duration value or a year with 4 digits381 * You can specify the duration in a jDuration object or give each value of 382 * the duration. 383 * @param jDuration/int $year the duration value or a year with 4 digits 382 384 * @param int $month month with 2 digits 383 385 * @param int $day day with 2 digits … … 387 389 */ 388 390 public function sub($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 389 if ($year instanceof jD ateTime) {391 if ($year instanceof jDuration) { 390 392 $dt = $year; 391 393 } else { 392 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 393 } 394 $t = mktime ( $this->hour - $dt->hour, $this->minute - $dt->minute, $this->second - $dt->second , 395 $this->month - $dt->month, $this->day - $dt->day, $this->year - $dt->year); 396 397 $t = getdate ($t); 398 $this->year = $t['year']; 399 $this->month = $t['mon']; 400 $this->day = $t['mday']; 401 $this->hour = $t['hours']; 402 $this->minute = $t['minutes']; 403 $this->second = $t['seconds']; 394 $dt = new jDuration(array("year" => $year, "month" => $month, 395 "day" => $day, "hour" => $hour, "minute" => $minute, 396 "second" => $second)); 397 } 398 $dt->mult(-1); 399 $this->add($dt); 404 400 } 405 401 … … 407 403 * to know the duration between two dates. 408 404 * @param jDateTime $dt the date on which a sub will be made with the date on the current object 409 * @return jDateTime a jDateTime object which will contains <b>a duration</b> (not a date) 410 */ 411 public function durationTo($dt){ 412 $t = mktime ( $dt->hour, $dt->minute,$dt->second , $dt->month, $dt->day, $dt->year ) 413 - mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year ); 414 $t = getdate ($t); 415 return new jDateTime( $t['year']-1970,$t['mon']-1, $t['mday']-1, $t['hours']-1, $t['minutes'], $t['seconds']); 405 * @param bool $absolute 406 * @return jDuration a jDuration object 407 */ 408 public function durationTo($dt, $absolute=true){ 409 if($absolute){ 410 $t = mktime($dt->hour, $dt->minute, $dt->second, 411 $dt->month, $dt->day, $dt->year) 412 - mktime($this->hour, $this->minute, $this->second, 413 $this->month, $this->day, $this->year); 414 return new jDuration($t); 415 } 416 else{ 417 return new jDuration(array( 418 "year" => $dt->year - $this->year, 419 "month" => $dt->month - $this->month, 420 "day" => $dt->day - $this-> day, 421 "hour" => $dt->hour - $this->hour, 422 "minute" => $dt->minute - $this->minute, 423 "second" => $dt->second - $this->second 424 )); 425 } 416 426 } 417 427 … … 444 454 } 445 455 } 446 447 ?>trunk/lib/jelix/utils/jDateTime.class.php
r739 r876 7 7 * @contributor Loic Mathaud 8 8 * @contributor Florian Hatat 9 * @copyright 2005-200 6Laurent Jouanneau9 * @copyright 2005-2008 Laurent Jouanneau 10 10 * @copyright 2007 Loic Mathaud 11 * @copyright 2007 Florian Hatat11 * @copyright 2007-2008 Florian Hatat 12 12 * @copyright 2001-2005 CopixTeam, GeraldCroes, Laurent Jouanneau 13 13 * … … 283 283 if($match[6] != '') $this->second = $match[6]; 284 284 if($match[8] != 'Z'){ 285 $d = new jD ateTime(0,0,0,$match[10],$match[11]);285 $d = new jDuration(array('hour'=>$match[10],'minute'=>$match[11])); 286 286 if($match[9] == '+') 287 287 $this->add($d); … … 331 331 # Adjust according to the timezone, so that the stored time 332 332 # corresponds to UTC. 333 $tz = new jD ateTime(0, 0, 0,intval($match['tzhour']),334 intval($match['tzminute']), 0);333 $tz = new jDuration(array('hour'=>intval($match['tzhour']), 334 'minute'=>intval($match['tzminute']))); 335 335 if($match['tzsign'] == '+'){ 336 336 $this->sub($tz); … … 348 348 /** 349 349 * Add a duration to the date. 350 * You can specify the duration in a jD ateTime object (which then is not a date/time)351 * or give each value of the duration352 * @param jD ateTime/int $year the duration value or a year with 4 digits350 * You can specify the duration in a jDuration object or give each value of 351 * the duration. 352 * @param jDuration/int $year the duration value or a year with 4 digits 353 353 * @param int $month month with 2 digits 354 354 * @param int $day day with 2 digits … … 358 358 */ 359 359 public function add($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 360 if ($year instanceof jD ateTime) {360 if ($year instanceof jDuration) { 361 361 $dt = $year; 362 362 } else { 363 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 364 } 365 $t = mktime ( $this->hour + $dt->hour, $this->minute + $dt->minute, $this->second + $dt->second , 366 $this->month + $dt->month, $this->day + $dt->day, $this->year + $dt->year); 363 $dt = new jDuration(array("year" => $year, "month" => $month, 364 "day" => $day, "hour" => $hour, "minute" => $minute, 365 "second" => $second)); 366 } 367 $t = mktime($this->hour, $this->minute, $this->second + $dt->seconds, 368 $this->month + $dt->months, $this->day + $dt->days, $this->year); 367 369 368 370 $t = getdate ($t); … … 377 379 /** 378 380 * substract a <b>duration</b> to the date 379 * You can specify the duration in a jD ateTime object (which then is not a date/time)380 * or give each value of the duration381 * @param jD ateTime/int $year the duration value or a year with 4 digits381 * You can specify the duration in a jDuration object or give each value of 382 * the duration. 383 * @param jDuration/int $year the duration value or a year with 4 digits 382 384 * @param int $month month with 2 digits 383 385 * @param int $day day with 2 digits … … 387 389 */ 388 390 public function sub($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 389 if ($year instanceof jD ateTime) {391 if ($year instanceof jDuration) { 390 392 $dt = $year; 391 393 } else { 392 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 393 } 394 $t = mktime ( $this->hour - $dt->hour, $this->minute - $dt->minute, $this->second - $dt->second , 395 $this->month - $dt->month, $this->day - $dt->day, $this->year - $dt->year); 396 397 $t = getdate ($t); 398 $this->year = $t['year']; 399 $this->month = $t['mon']; 400 $this->day = $t['mday']; 401 $this->hour = $t['hours']; 402 $this->minute = $t['minutes']; 403 $this->second = $t['seconds']; 394 $dt = new jDuration(array("year" => $year, "month" => $month, 395 "day" => $day, "hour" => $hour, "minute" => $minute, 396 "second" => $second)); 397 } 398 $dt->mult(-1); 399 $this->add($dt); 404 400 } 405 401 … … 407 403 * to know the duration between two dates. 408 404 * @param jDateTime $dt the date on which a sub will be made with the date on the current object 409 * @return jDateTime a jDateTime object which will contains <b>a duration</b> (not a date) 410 */ 411 public function durationTo($dt){ 412 $t = mktime ( $dt->hour, $dt->minute,$dt->second , $dt->month, $dt->day, $dt->year ) 413 - mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year ); 414 $t = getdate ($t); 415 return new jDateTime( $t['year']-1970,$t['mon']-1, $t['mday']-1, $t['hours']-1, $t['minutes'], $t['seconds']); 405 * @param bool $absolute 406 * @return jDuration a jDuration object 407 */ 408 public function durationTo($dt, $absolute=true){ 409 if($absolute){ 410 $t = mktime($dt->hour, $dt->minute, $dt->second, 411 $dt->month, $dt->day, $dt->year) 412 - mktime($this->hour, $this->minute, $this->second, 413 $this->month, $this->day, $this->year); 414 return new jDuration($t); 415 } 416 else{ 417 return new jDuration(array( 418 "year" => $dt->year - $this->year, 419 "month" => $dt->month - $this->month, 420 "day" => $dt->day - $this-> day, 421 "hour" => $dt->hour - $this->hour, 422 "minute" => $dt->minute - $this->minute, 423 "second" => $dt->second - $this->second 424 )); 425 } 416 426 } 417 427 … … 444 454 } 445 455 } 446 447 ?>trunk/lib/jelix/utils/jDateTime.class.php
r739 r876 7 7 * @contributor Loic Mathaud 8 8 * @contributor Florian Hatat 9 * @copyright 2005-200 6Laurent Jouanneau9 * @copyright 2005-2008 Laurent Jouanneau 10 10 * @copyright 2007 Loic Mathaud 11 * @copyright 2007 Florian Hatat11 * @copyright 2007-2008 Florian Hatat 12 12 * @copyright 2001-2005 CopixTeam, GeraldCroes, Laurent Jouanneau 13 13 * … … 283 283 if($match[6] != '') $this->second = $match[6]; 284 284 if($match[8] != 'Z'){ 285 $d = new jD ateTime(0,0,0,$match[10],$match[11]);285 $d = new jDuration(array('hour'=>$match[10],'minute'=>$match[11])); 286 286 if($match[9] == '+') 287 287 $this->add($d); … … 331 331 # Adjust according to the timezone, so that the stored time 332 332 # corresponds to UTC. 333 $tz = new jD ateTime(0, 0, 0,intval($match['tzhour']),334 intval($match['tzminute']), 0);333 $tz = new jDuration(array('hour'=>intval($match['tzhour']), 334 'minute'=>intval($match['tzminute']))); 335 335 if($match['tzsign'] == '+'){ 336 336 $this->sub($tz); … … 348 348 /** 349 349 * Add a duration to the date. 350 * You can specify the duration in a jD ateTime object (which then is not a date/time)351 * or give each value of the duration352 * @param jD ateTime/int $year the duration value or a year with 4 digits350 * You can specify the duration in a jDuration object or give each value of 351 * the duration. 352 * @param jDuration/int $year the duration value or a year with 4 digits 353 353 * @param int $month month with 2 digits 354 354 * @param int $day day with 2 digits … … 358 358 */ 359 359 public function add($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 360 if ($year instanceof jD ateTime) {360 if ($year instanceof jDuration) { 361 361 $dt = $year; 362 362 } else { 363 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 364 } 365 $t = mktime ( $this->hour + $dt->hour, $this->minute + $dt->minute, $this->second + $dt->second , 366 $this->month + $dt->month, $this->day + $dt->day, $this->year + $dt->year); 363 $dt = new jDuration(array("year" => $year, "month" => $month, 364 "day" => $day, "hour" => $hour, "minute" => $minute, 365 "second" => $second)); 366 } 367 $t = mktime($this->hour, $this->minute, $this->second + $dt->seconds, 368 $this->month + $dt->months, $this->day + $dt->days, $this->year); 367 369 368 370 $t = getdate ($t); … … 377 379 /** 378 380 * substract a <b>duration</b> to the date 379 * You can specify the duration in a jD ateTime object (which then is not a date/time)380 * or give each value of the duration381 * @param jD ateTime/int $year the duration value or a year with 4 digits381 * You can specify the duration in a jDuration object or give each value of 382 * the duration. 383 * @param jDuration/int $year the duration value or a year with 4 digits 382 384 * @param int $month month with 2 digits 383 385 * @param int $day day with 2 digits … … 387 389 */ 388 390 public function sub($year, $month=0, $day=0, $hour=0, $minute=0, $second=0) { 389 if ($year instanceof jD ateTime) {391 if ($year instanceof jDuration) { 390 392 $dt = $year; 391 393 } else { 392 $dt = new jDateTime($year, $month, $day, $hour, $minute, $second); 393 } 394 $t = mktime ( $this->hour - $dt->hour, $this->minute - $dt->minute, $this->second - $dt->second , 395 $this->month - $dt->month, $this->day - $dt->day, $this->year - $dt->year); 396 397 $t = getdate ($t); 398 $this->year = $t['year']; 399 $this->month = $t['mon']; 400 $this->day = $t['mday']; 401 $this->hour = $t['hours']; 402 $this->minute = $t['minutes']; 403 $this->second = $t['seconds']; 394 $dt = new jDuration(array("year" => $year, "month" => $month, 395 "day" => $day, "hour" => $hour, "minute" => $minute, 396 "second" => $second)); 397 } 398 $dt->mult(-1); 399 $this->add($dt); 404 400 } 405 401 … … 407 403 * to know the duration between two dates. 408 404 * @param jDateTime $dt the date on which a sub will be made with the date on the current object 409 * @return jDateTime a jDateTime object which will contains <b>a duration</b> (not a date) 410 */ 411 public function durationTo($dt){ 412 $t = mktime ( $dt->hour, $dt->minute,$dt->second , $dt->month, $dt->day, $dt->year ) 413 - mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year ); 414 $t = getdate ($t); 415 return new jDateTime( $t['year']-1970,$t['mon']-1, $t['mday']-1, $t['hours']-1, $t['minutes'], $t['seconds']); 405 * @param bool $absolute 406 * @return jDuration a jDuration object 407 */ 408 public function durationTo($dt, $absolute=true){ 409 if($absolute){ 410 $t = mktime($dt->hour, $dt->minute, $dt->second, 411 $dt->month, $dt->day, $dt->year) 412 - mktime($this->hour, $this->minute, $this->second, 413 $this->month, $this->day, $this->year); 414 return new jDuration($t); 415 } 416 else{ 417 return new jDuration(array( 418 "year" => $dt->year - $this->year, 419 "month" => $dt->month - $this->month, 420 "day" => $dt->day - $this-> day, 421 "hour" => $dt->hour - $this->hour, 422 "minute" => $dt->minute - $this->minute, 423 "second" => $dt->second - $this->second 424 )); 425 } 416 426 } 417 427 … … 444 454 } 445 455 } 446 447 ?>
