Beispiel #1
0
 /**
  * Answer the days in this month on a given year.
  * 
  * @param string $indexOrNameString
  * @param ingteger $yearInteger
  * @return integer
  * @access public
  * @since 5/5/05
  * @static
  */
 static function daysInMonthForYear($indexOrNameString, $yearInteger)
 {
     if (is_numeric($indexOrNameString)) {
         $index = $indexOrNameString;
     } else {
         $index = Month::indexOfMonth($indexOrNameString);
     }
     if ($index < 1 | $index > 12) {
         $errorString = $index . " is not a valid month index.";
         if (function_exists('throwError')) {
             throwError(new Error($errorString));
         } else {
             die($errorString);
         }
     }
     $monthDays = ChronologyConstants::DaysInMonth();
     $days = $monthDays[$index];
     if ($index == 2 && Year::isYearLeapYear($yearInteger)) {
         return $days + 1;
     } else {
         return $days;
     }
 }
Beispiel #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;
 }
 /**
  * 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;
     }
 }
Beispiel #4
0
 /**
  * Answer the number of seconds the receiver represents.
  * 
  * @return integer
  * @access public
  * @since 5/3/05
  */
 function seconds()
 {
     // 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->seconds();
     } else {
         if ($this->isPositive()) {
             return floor($this->seconds % ChronologyConstants::SecondsInMinute());
         } else {
             return 0 - floor(abs($this->seconds) % ChronologyConstants::SecondsInMinute());
         }
     }
 }
Beispiel #5
0
 /**
  * Create a new object starting now, with a given duration. 
  * Override - as each Week has a defined duration
  * 
  * @param object DateAndTime $aDateAndTime
  * @param object Duration $aDuration
  * @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 Week
  * @access public
  * @since 5/5/05
  * @static
  */
 static function startingDuration($aDateAndTime, $aDuration, $class = 'Week')
 {
     // Validate our passed class name.
     if (!(strtolower($class) == strtolower('Week') || is_subclass_of(new $class(), 'Week'))) {
         die("Class, '{$class}', is not a subclass of 'Week'.");
     }
     $asDateAndTime = $aDateAndTime->asDateAndTime();
     $midnight = $asDateAndTime->atMidnight();
     $dayNames = ChronologyConstants::DayNames();
     $temp = $midnight->dayOfWeek() + 7 - array_search(Week::startDay(), $dayNames);
     $delta = abs($temp - intval($temp / 7) * 7);
     $adjusted = $midnight->minus(Duration::withDays($delta));
     $obj = parent::startingDuration($adjusted, Duration::withWeeks(1), $class);
     return $obj;
 }