예제 #1
0
파일: time.php 프로젝트: AlexanderGrom/knee
 /**
  * Время из строки
  *
  * @param string $format
  * @param string $timezone
  * @return int
  */
 public static function relative($format, $timezone = null)
 {
     $time = 0;
     if (preg_match('#^(?<sign>[+-]{1})?(?<number>\\d+)[ ]*(?<value>sec|min|hour|day|month|year)$#is', trim($format), $match) != 0) {
         switch ($match['value']) {
             case 'sec':
                 $time = Time::sec($match['number']);
                 break;
             case 'min':
                 $time = Time::min($match['number']);
                 break;
             case 'hour':
                 $time = Time::hour($match['number']);
                 break;
             case 'day':
                 $time = Time::day($match['number']);
                 break;
             case 'month':
                 $time = Time::month($match['number'], $timezone);
                 break;
             case 'year':
                 $time = Time::year($match['number'], $timezone);
                 break;
         }
         if (isset($match['sign']) and $match['sign'] == '-') {
             $time *= -1;
         }
     }
     return $time;
 }
예제 #2
0
파일: Angle.php 프로젝트: marando/units
 /**
  * Converts this instance to a proportion of time passed within a specified
  * time interval where 360 degrees is equal to the interval.
  *
  * @param Time $interval
  *
  * @return Time
  */
 public function toTime(Time $interval = null)
 {
     $secInDay = Time::days(1)->sec;
     $interval = $interval ? $interval->sec : $secInDay;
     return Time::sec($this->deg / 360 * $interval);
 }
예제 #3
0
파일: Time.php 프로젝트: marando/units
 /**
  * Returns a new time with the negation of this instance.
  *
  * @return static
  */
 public function neg()
 {
     return Time::sec($this->sec * -1);
 }