/**
  * @covers DateUtils::makeDateFromTimestamp
  */
 public function testMakeDateFromTimestampNoTimeZone()
 {
     $time = 1430469263;
     $date = \DateUtils::makeDateFromTimestamp($time);
     $this->assertInstanceOf("DateTime", $date);
     $actual = $date->getTimestamp();
     $excepted = 1430469263;
     $this->assertSame($excepted, $actual);
 }
Beispiel #2
0
 /**
  * Get a unix timestamp representing 12AM of the first day of the week of the
  * given date in the the given timezone.
  * Assumes that the first day of the week is Monday.
  * Note: Requires (PHP 5 >= 5.1.0)
  *
  * @param long $date unix timestamp.
  * @param String $timezone time zone code.
  * @return long unix timestamp
  */
 public static function getBeginningOfWeek($timestamp, $timezone)
 {
     $dt = DateUtils::makeDateFromTimestamp($timestamp, $timezone);
     // 1=Monday,... 7=Sunday
     $dayOfWeek = intval($dt->format('N'));
     // (PHP 5 >= 5.1.0)
     $daysDiff = $dayOfWeek - 1;
     $dt->modify("-{$daysDiff} day");
     $dt->setTime(0, 0, 0);
     return self::dateTimeToTimestamp($dt);
 }