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")); }
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; }; }
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; }; }
public function testPreviousMonday() { $refDate = new RhubarbDate("2014-03-31"); $newDate = RhubarbDateTime::PreviousMonday($refDate); $this->assertEquals($refDate->format("Ymd"), $newDate->format("Ymd")); $refDate = new RhubarbDate("2014-04-02"); $newDate = RhubarbDateTime::PreviousMonday($refDate); $this->assertEquals("20140331", $newDate->format("Ymd")); $refDate = new RhubarbDate("2014-03-30"); $newDate = RhubarbDateTime::PreviousMonday($refDate); $this->assertEquals("20140324", $newDate->format("Ymd")); }
/** * We never want to do comparisons on date - therefore we always force the date time to have the same date * @param int $year * @param int $month * @param int $day * * @return \DateTime */ public function setDate($year, $month, $day) { return parent::setDate(self::$yearMustAlwaysBe, self::$monthMustAlwaysBe, self::$dayMustAlwaysBe); }
/** * 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; }
public static function createFromFormat($format, $time, $timezone = null) { $date = parent::createFromFormat($format, $time, $timezone); return new RhubarbDate($date); }
public function setTime($hour, $minute, $second = 0) { return parent::setTime(0, 0, 0); }