/** * @param Time $time * @param bool $isEndTime * @return Date */ public function SetTime(Time $time, $isEndTime = false) { $date = Date::Create($this->Year(), $this->Month(), $this->Day(), $time->Hour(), $time->Minute(), $time->Second(), $this->Timezone()); if ($isEndTime) { if ($time->Hour() == 0 && $time->Minute() == 0 && $time->Second() == 0) { return $date->AddDays(1); } } return $date; }
/** * Compares this time to the one passed in * Returns: * -1 if this time is less than the passed in time * 0 if the times are equal * 1 if this time is greater than the passed in time * @param Time $time * @param Date|null $comparisonDate date to be used for time comparison * @return int comparison result */ public function Compare(Time $time, $comparisonDate = null) { if ($comparisonDate != null) { $myDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $this->Hour(), $this->Minute(), $this->Second(), $this->Timezone()); $otherDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $time->Hour(), $time->Minute(), $time->Second(), $time->Timezone()); return $myDate->Compare($otherDate); } return $this->GetDate()->Compare($time->GetDate()); }
public function testCanCreateTimeInServerTimezone() { $hour = 10; $min = 22; $sec = 21; $time = new Time($hour, $min, $sec); $this->assertEquals("{$hour}:{$min}:{$sec}", $time->ToString()); $this->assertEquals($hour, $time->Hour()); $this->assertEquals($min, $time->Minute()); $this->assertEquals($sec, $time->Second()); $time = new Time($hour, $min); $this->assertEquals("{$hour}:{$min}:00", $time->ToString()); $this->assertEquals($hour, $time->Hour()); $this->assertEquals($min, $time->Minute()); $this->assertEquals(0, $time->Second()); }