[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/datetime/tests/cases/ -> lmbDatePeriodTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/datetime/src/lmbDatePeriod.class.php');
  10  
  11  class lmbDatePeriodTest extends UnitTestCase
  12  {
  13    function testInvalidPeriod()
  14    {
  15      try
  16      {
  17        $period = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:45:10');
  18        $this->assertTrue(false);
  19      }
  20      catch(lmbException $e){}
  21    }
  22  
  23    function testToString()
  24    {
  25      $p = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
  26      $this->assertEqual($p->toString(), '2005-12-01 13:45:12 - 2005-12-01 13:46:00');
  27    }
  28  
  29    function testGetDuration()
  30    {
  31      $p = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
  32      $this->assertEqual($p->getDuration(), 48);
  33    }
  34  
  35    function testIsEqual()
  36    {
  37      $p1 = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
  38      $p2 = new lmbDatePeriod('2006-12-01 13:45:12', '2006-12-01 13:46:00');
  39  
  40      $this->assertTrue($p1->isEqual($p1));
  41      $this->assertFalse($p1->isEqual($p2));
  42    }
  43  
  44    function testIsInside()
  45    {
  46      $child = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
  47      $parent = new lmbDatePeriod('2005-12-01 10:00:00', '2005-12-01 14:01:00');
  48      $intersect = new lmbDatePeriod('2005-12-01 11:00:00', '2005-12-01 15:01:00');
  49  
  50      $this->assertTrue($child->isInside($parent));
  51      $this->assertTrue($parent->includes($child));
  52      $this->assertFalse($parent->includes($intersect));
  53    }
  54  
  55    function testIntersects()
  56    {
  57      $period1 = new lmbDatePeriod("2005-09-05 14:40:00", "2005-09-05 14:41:50");
  58      $period2 = new lmbDatePeriod("2005-09-05 14:39:00", "2005-09-05 14:41:00");
  59      $period3 = new lmbDatePeriod("2006-09-05 14:39:00", "2006-09-05 14:41:00");
  60  
  61      $this->assertTrue($period1->intersects($period1));
  62  
  63      $this->assertTrue($period1->intersects($period2));
  64      $this->assertTrue($period2->intersects($period1));
  65  
  66      $this->assertFalse($period1->intersects($period3));
  67      $this->assertFalse($period3->intersects($period1));
  68    }
  69  }
  70  
  71  ?>


Generated: Tue Oct 7 05:02:03 2008 Cross-referenced by PHPXref 0.7