Example #1
0
 /**
  * @inheritdoc
  */
 public function __get($property)
 {
     if (strpos($property, 'as_') === 0) {
         return $this->{'format_' . $property}();
     }
     switch ($property) {
         case 'timestamp':
             return $this->getTimestamp();
         case 'year':
             return (int) $this->format('Y');
         case 'quarter':
             return floor(($this->month - 1) / 3) + 1;
         case 'month':
             return (int) $this->format('m');
         case 'week':
             return (int) $this->format('W');
         case 'year_day':
             return (int) $this->format('z') + 1;
         case 'weekday':
             return (int) $this->format('w') ?: 7;
         case 'day':
             return (int) $this->format('d');
         case 'hour':
             return (int) $this->format('H');
         case 'minute':
             return (int) $this->format('i');
         case 'second':
             return (int) $this->format('s');
         case 'is_monday':
             return $this->weekday == 1;
         case 'is_tuesday':
             return $this->weekday == 2;
         case 'is_wednesday':
             return $this->weekday == 3;
         case 'is_thursday':
             return $this->weekday == 4;
         case 'is_friday':
             return $this->weekday == 5;
         case 'is_saturday':
             return $this->weekday == 6;
         case 'is_sunday':
             return $this->weekday == 7;
         case 'is_today':
             $now = new static('now', $this->zone);
             return $this->as_date === $now->as_date;
         case 'is_past':
             return $this < new static('now', $this->zone);
         case 'is_future':
             return $this > new static('now', $this->zone);
         case 'is_empty':
             return $this->year == -1 && $this->month == 11 && $this->day == 30;
         case 'tomorrow':
             $time = clone $this;
             $time->modify('+1 day');
             $time->setTime(0, 0, 0);
             return $time;
         case 'yesterday':
             $time = clone $this;
             $time->modify('-1 day');
             $time->setTime(0, 0, 0);
             return $time;
             /*
              * days
              */
         /*
          * days
          */
         case 'monday':
         case 'tuesday':
         case 'wednesday':
         case 'thursday':
         case 'friday':
         case 'saturday':
         case 'sunday':
             return $this->{'get_' . $property}();
         case 'zone':
             return TimeZone::from($this->getTimezone());
         case 'utc':
         case 'local':
             $time = clone $this;
             $time->setTimezone($property);
             return $time;
         case 'is_utc':
             return $this->zone->name == 'UTC';
         case 'is_local':
             return $this->zone->name == date_default_timezone_get();
         case 'is_dst':
             $timestamp = $this->timestamp;
             $transitions = $this->zone->getTransitions($timestamp, $timestamp);
             return $transitions[0]['isdst'];
     }
     if (class_exists('ICanBoogie\\PropertyNotDefined')) {
         throw new PropertyNotDefined([$property, $this]);
     } else {
         throw new \RuntimeException("Property is not defined: {$property}.");
     }
 }