Beispiel #1
0
 public function testToString()
 {
     $date = new Date(new Year(2013), Month::DECEMBER(), new MonthDay(3));
     $time = new Time(new Hour(20), new Minute(50), new Second(10));
     $dateTime = new DateTime($date, $time);
     $this->assertEquals('2013-12-3 20:50:10', $dateTime->__toString());
 }
 public function testGetDateTime()
 {
     $date = new Date(new Year(2013), Month::DECEMBER(), new MonthDay(3));
     $time = new Time(new Hour(20), new Minute(50), new Second(10));
     $dateTime = new DateTime($date, $time);
     $timeZone = new TimeZone(new StringLiteral('Europe/Madrid'));
     $dateTimeWithTz = new DateTimeWithTimeZone($dateTime, $timeZone);
     $this->assertTrue($dateTime->sameValueAs($dateTimeWithTz->getDateTime()));
 }
Beispiel #3
0
 /**
  * Returns a native PHP \DateTime version of the current Time.
  * Date is set to current.
  *
  * @return \DateTime
  */
 public function toNativeDateTime()
 {
     $hour = $this->getHour()->toNative();
     $minute = $this->getMinute()->toNative();
     $second = $this->getSecond()->toNative();
     $time = new \DateTime('now');
     $time->setTime($hour, $minute, $second);
     return $time;
 }
Beispiel #4
0
 /**
  * Returns Month from a native PHP \DateTime
  *
  * @param  \DateTime $date
  * @return Month
  */
 public static function fromNativeDateTime(\DateTime $date)
 {
     $month = \strtoupper($date->format('F'));
     return static::getByName($month);
 }
Beispiel #5
0
 /**
  * Returns the current minute.
  *
  * @return Minute
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $minute = \intval($now->format('i'));
     return new static($minute);
 }
Beispiel #6
0
 /**
  * Returns the current hour.
  *
  * @return Hour
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $hour = \intval($now->format('G'));
     return new static($hour);
 }
Beispiel #7
0
 /**
  * Returns the current month day.
  *
  * @return MonthDay
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $monthDay = \intval($now->format('j'));
     return new static($monthDay);
 }
 /**
  * Returns a native PHP \DateTime version of the current DateTimeWithTimeZone
  *
  * @return \DateTime
  */
 public function toNativeDateTime()
 {
     $date = $this->getDateTime()->getDate();
     $time = $this->getDateTime()->getTime();
     $year = $date->getYear()->toNative();
     $month = $date->getMonth()->getNumericValue();
     $day = $date->getDay()->toNative();
     $hour = $time->getHour()->toNative();
     $minute = $time->getMinute()->toNative();
     $second = $time->getSecond()->toNative();
     $timezone = $this->getTimeZone()->toNativeDateTimeZone();
     $dateTime = new \DateTime();
     $dateTime->setTimezone($timezone);
     $dateTime->setDate($year, $month, $day);
     $dateTime->setTime($hour, $minute, $second);
     return $dateTime;
 }
Beispiel #9
0
 /**
  * Returns a native PHP \DateTime version of the current Date
  *
  * @return \DateTime
  */
 public function toNativeDateTime()
 {
     $year = $this->getYear()->toNative();
     $month = $this->getMonth()->getNumericValue();
     $day = $this->getDay()->toNative();
     $date = new \DateTime();
     $date->setDate($year, $month, $day);
     $date->setTime(0, 0, 0);
     return $date;
 }
Beispiel #10
0
 /**
  * Returns a WeekDay from a PHP native \DateTime
  *
  * @param  \DateTime $date
  * @return WeekDay
  */
 public static function fromNativeDateTime(\DateTime $date)
 {
     $weekDay = \strtoupper($date->format('l'));
     return static::getByName($weekDay);
 }
Beispiel #11
0
 /**
  * Returns the current second.
  *
  * @return Second
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $second = \intval($now->format('s'));
     return new static($second);
 }