/** * Test converting methods * */ function test_converting() { $time = Time::withHourMinuteSecond(15, 25, 10); // asDate () $temp = $time->asDate(); $this->assertTrue($temp->isEqualTo(Date::today())); $this->assertEqual(strtolower(get_class($temp)), 'date'); // asDateAndTime () $temp = $time->asDateAndTime(); $comparison = DateAndTime::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'dateandtime'); // asDuration () $temp = $time->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510))); $this->assertEqual(strtolower(get_class($temp)), 'duration'); // asMonth () $temp = $time->asMonth(); $this->assertTrue($temp->isEqualTo(Month::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'month'); // asSeconds () $this->assertEqual($time->asSeconds(), 55510); // asTime () $temp = $time->asTime(); $this->assertTrue($temp->isEqualTo($time)); $this->assertEqual(strtolower(get_class($temp)), 'time'); // asTimeStamp () $temp = $time->asTimeStamp(); $comparison = TimeStamp::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'timestamp'); // asWeek () $temp = $time->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'week'); // asYear () $temp = $time->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'year'); // to () $today = DateAndTime::today(); $tomorrow = DateAndTime::tomorrow(); $result = $time->to($tomorrow); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50)))); $result = $time->to(Time::withHourMinuteSecond(23, 25, 10)); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0)))); }
/** * Answer the month that represents this date's month * * @return object Month * @access public * @since 5/5/05 */ function asMonth() { $obj = Month::starting($this); return $obj; }
/** * Test aritmatic operations * */ function test_operations_next_prev() { // Operations // next() // previous() // 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 0 0 0 // 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 // // A |- - - - - - - - - -| // B |-| // C |- - - - - - - - -| // D |- - - -| $timespanA = Month::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10)); $timespanB = Month::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1)); $timespanC = Month::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 20), DateAndTime::withYearMonthDay(2005, 5, 29)); $timespanD = Month::startingEnding(DateAndTime::withYearMonthDay(2005, 6, 1), DateAndTime::withYearMonthDay(2005, 6, 6)); $temp = Month::starting(DateAndTime::withYearMonthDay(2005, 6, 1)); $this->assertTrue($temp->isEqualTo($timespanA->next())); $temp = Month::starting(DateAndTime::withYearMonthDay(2005, 4, 1)); $this->assertTrue($temp->isEqualTo($timespanA->previous())); }