Example #1
0
 /**
  * 以下の確認を行います.
  * 
  * - 比較が正常に出来る
  * - 対象オブジェクトが Timestamp 型でない場合でも比較が出来る
  * - 引数に時間オブジェクト以外の値を指定した場合は null を返す
  */
 public function testCompareTo()
 {
     $d = array(new Timestamp(2012, 3, 12, 23, 59, 59), new Timestamp(2012, 5, 21, 7, 30, 10), new Timestamp(2012, 5, 21, 7, 30, 30), new Timestamp(2012, 5, 21, 7, 30, 50), new Timestamp(2013, 1, 23, 1, 23, 45));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[0]));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[1]));
     $this->assertSame(0, $d[2]->compareTo($d[2]));
     $this->assertLessThan(0, $d[2]->compareTo($d[3]));
     $this->assertLessThan(0, $d[2]->compareTo($d[4]));
     $w1 = new TimeWrapper($d[2]);
     $w2 = $w1->add("sec", -15);
     $this->assertGreaterThan(0, $d[2]->compareTo($w2));
     $this->assertSame(0, $d[2]->compareTo($w1));
     $this->assertNull($d[1]->compareTo("foobar"));
 }
Example #2
0
 /**
  * 以下の確認を行います.
  * 
  * - 比較が正常に出来る
  * - 対象オブジェクトが Datetime を継承していない場合でも比較が出来る
  * - 引数に時間オブジェクト以外の値を指定した場合は null を返す
  * 
  * @covers Peach\DT\AbstractTime::compareTo
  * @covers Peach\DT\Date::compareFields
  */
 public function testCompareTo()
 {
     $d = array(new Date(2011, 8, 1), new Date(2012, 3, 12), new Date(2012, 5, 21), new Date(2012, 5, 30), new Date(2013, 1, 23));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[0]));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[1]));
     $this->assertSame(0, $d[2]->compareTo($d[2]));
     $this->assertLessThan(0, $d[2]->compareTo($d[3]));
     $this->assertLessThan(0, $d[2]->compareTo($d[4]));
     $w1 = new TimeWrapper($d[2]);
     $w2 = $w1->add("year", -1);
     $w3 = $w1->add("month", 5);
     $w4 = $w1->add("date", 3);
     $this->assertGreaterThan(0, $d[2]->compareTo($w2));
     $this->assertLessThan(0, $d[2]->compareTo($w3));
     $this->assertLessThan(0, $d[2]->compareTo($w4));
     $this->assertSame(0, $d[2]->compareTo($w1));
     $this->assertNull($d[2]->compareTo("foobar"));
 }
Example #3
0
 /**
  * 以下の確認を行います.
  * 
  * - 比較が正常に出来る
  * - 対象オブジェクトが Datetime を継承していない場合でも比較が出来る
  * - 引数に時間オブジェクト以外の値を指定した場合は null を返す
  * 
  * @covers Peach\DT\AbstractTime::compareTo
  * @covers Peach\DT\Datetime::compareFields
  */
 public function testCompareTo()
 {
     $d = array(new Datetime(2012, 3, 12, 23, 59), new Datetime(2012, 5, 21, 3, 15), new Datetime(2012, 5, 21, 7, 30), new Datetime(2012, 5, 21, 7, 45), new Datetime(2013, 1, 23, 1, 23));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[0]));
     $this->assertGreaterThan(0, $d[2]->compareTo($d[1]));
     $this->assertSame(0, $d[2]->compareTo($d[2]));
     $this->assertLessThan(0, $d[2]->compareTo($d[3]));
     $this->assertLessThan(0, $d[2]->compareTo($d[4]));
     $w1 = new TimeWrapper($d[2]);
     $w2 = $w1->add("hour", -3);
     $w3 = $w1->add("minute", 15);
     $this->assertGreaterThan(0, $d[2]->compareTo($w2));
     $this->assertLessThan(0, $d[2]->compareTo($w3));
     $this->assertSame(0, $d[2]->compareTo($w1));
     $this->assertNull($d[2]->compareTo("foobar"));
 }