Ejemplo n.º 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()));
 }
Ejemplo n.º 3
0
 /**
  * Returns the current second.
  *
  * @return Second
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $second = \intval($now->format('s'));
     return new static($second);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 5
0
 /**
  * Returns the current year.
  *
  * @return Year
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $year = \intval($now->format('Y'));
     return new static($year);
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
 /**
  * Returns the current minute.
  *
  * @return Minute
  */
 public static function now()
 {
     $now = new \DateTime('now');
     $minute = \intval($now->format('i'));
     return new static($minute);
 }
Ejemplo n.º 9
0
 /**
  * Returns a native PHP \DateTime version of the current DateTime.
  *
  * @return \DateTime
  */
 public function toNativeDateTime()
 {
     $year = $this->getDate()->getYear()->toNative();
     $month = $this->getDate()->getMonth()->getNumericValue();
     $day = $this->getDate()->getDay()->toNative();
     $hour = $this->getTime()->getHour()->toNative();
     $minute = $this->getTime()->getMinute()->toNative();
     $second = $this->getTime()->getSecond()->toNative();
     $dateTime = new \DateTime();
     $dateTime->setDate($year, $month, $day);
     $dateTime->setTime($hour, $minute, $second);
     return $dateTime;
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
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);
 }