Пример #1
0
 /**
  * Answer the number of hours the receiver represents.
  * 
  * @return integer
  * @access public
  * @since 5/3/05
  */
 function hours()
 {
     // Above 2^31 seconds, (amost exactly 100 years), PHP converts the
     // variable from an integer to a float to allow it to grow larger.
     // While addition and subraction work fine with floats, float modulos
     // and divisions loose precision. This precision loss does not affect
     // the proper value of days up to the maximum duration tested, 50billion
     // years.
     if (abs($this->seconds) > pow(2, 31)) {
         $remainderDuration = $this->minus(Duration::withDays($this->days()));
         return $remainderDuration->hours();
     } else {
         if (!$this->isNegative()) {
             return floor($this->seconds % ChronologyConstants::SecondsInDay() / ChronologyConstants::SecondsInHour());
         } else {
             return 0 - floor(abs($this->seconds) % ChronologyConstants::SecondsInDay() / ChronologyConstants::SecondsInHour());
         }
     }
 }
Пример #2
0
 /**
  * Answer a Time from midnight
  * 
  * @param integer $anIntSeconds
  * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  *		This parameter is used to get around the limitations of not being
  *		able to find the class of the object that recieved the initial 
  *		method call.
  * @return object Time
  * @access public
  * @static
  * @since 5/5/05
  */
 static function withSeconds($anIntSeconds, $class = 'Time')
 {
     // Lop off any seconds beyond those in a day
     $duration = Duration::withSeconds($anIntSeconds);
     $ticks = $duration->ticks();
     $seconds = $ticks[1];
     // Make sure that we have a positive time since midnight
     if ($seconds < 0) {
         $seconds = ChronologyConstants::SecondsInDay() + $seconds;
     }
     // Validate our passed class name.
     if (!(strtolower($class) == strtolower('Time') || is_subclass_of(new $class(), 'Time'))) {
         die("Class, '{$class}', is not a subclass of 'Time'.");
     }
     $time = new $class();
     $time->setSeconds($seconds);
     return $time;
 }
Пример #3
0
 /**
  * Subtract a Duration or DateAndTime.
  * 
  * @param object $operand
  * @return object
  * @access public
  * @since 5/3/05
  */
 function minus($operand)
 {
     $methods = get_class_methods($operand);
     // If this conforms to the DateAndTimeProtocal
     if (in_array('asdateandtime', $methods) | in_array('asDateAndTime', $methods)) {
         $meLocal = $this->asLocal();
         $lticks = $meLocal->ticks();
         $opDAndT = $operand->asDateAndTime();
         $opLocal = $opDAndT->asLocal();
         $rticks = $opLocal->ticks();
         $obj = Duration::withSeconds(($lticks[0] - $rticks[0]) * ChronologyConstants::SecondsInDay() + ($lticks[1] - $rticks[1]));
         return $obj;
     } else {
         $obj = $this->plus($operand->negated());
         return $obj;
     }
 }