Exemplo n.º 1
0
 public function testJsonEncode()
 {
     $date = new RhubarbDateTime("2013-09-03");
     $encoded = json_encode($date);
     $this->assertEquals('"' . $date->format(\DateTime::ISO8601) . '"', $encoded);
     $date = new RhubarbDateTime(str_replace('"', "", $encoded));
     $this->assertEquals("2013-09-03", $date->format("Y-m-d"));
 }
Exemplo n.º 2
0
 public function testDateIsConsistentNoMatterWhatTimezone()
 {
     date_default_timezone_set("Europe/Berlin");
     $date = new RhubarbDate("2013-12-12");
     $this->assertEquals("2013-12-12", $date->format("Y-m-d"));
     $newDate = new RhubarbDateTime($date);
     $this->assertEquals("2013-12-12", $newDate->format("Y-m-d"));
     date_default_timezone_set("Europe/London");
     // This is a date in BST
     $date = new RhubarbDate("2013-09-24");
     $this->assertEquals("2013-09-24", $date->format("Y-m-d"));
 }
Exemplo n.º 3
0
 public function getTransformIntoRepository()
 {
     return function ($data) {
         $data = new RhubarbDateTime($data);
         if ($data->isValidDateTime()) {
             $date = $data->format("Y-m-d");
         } else {
             $date = "0000-00-00";
         }
         return $date;
     };
 }
Exemplo n.º 4
0
 public function getTransformIntoRepository()
 {
     return function ($data) {
         $data = new RhubarbDateTime($data[$this->columnName]);
         if ($data->IsValidDateTime()) {
             $date = $data->format("Y-m-d H:i:s");
         } else {
             $date = "0000-00-00 00:00:00";
         }
         return $date;
     };
 }
Exemplo n.º 5
0
 /**
  * Returns the date of the Monday of this week.
  *
  * This is often used as a handle on the week commencing date
  *
  * @param RhubarbDateTime $referenceDate The date to find the previous Monday of. Today if null.
  * @return RhubarbDate
  */
 public static function previousMonday($referenceDate = null)
 {
     if ($referenceDate == null) {
         $referenceDate = new RhubarbDateTime("today");
     }
     $dow = $referenceDate->format("N");
     $dow--;
     $dow = -$dow;
     $referenceDate->modify($dow . " days");
     return $referenceDate;
 }