/** * Compares this {@code OffsetDateTime} to another date-time. * The comparison is based on the instant. * * @param $datetime1 OffsetDateTime the first date-time to compare, not null * @param $datetime2 OffsetDateTime the other date-time to compare to, not null * @return int the comparator value, negative if less, positive if greater */ public static function compareInstant(OffsetDateTime $datetime1, OffsetDateTime $datetime2) { if ($datetime1->getOffset()->equals($datetime2->getOffset())) { return $datetime1->toLocalDateTime()->compareTo($datetime2->toLocalDateTime()); } $cmp = Long::compare($datetime1->toEpochSecond(), $datetime2->toEpochSecond()); if ($cmp === 0) { $cmp = $datetime1->toLocalTime()->getNano() - $datetime2->toLocalTime()->getNano(); } return $cmp; }
private function check(OffsetDateTime $test, $y, $mo, $d, $h, $m, $s, $n, ZoneOffset $offset) { $this->assertEquals($test->getYear(), $y); $this->assertEquals($test->getMonth()->getValue(), $mo); $this->assertEquals($test->getDayOfMonth(), $d); $this->assertEquals($test->getHour(), $h); $this->assertEquals($test->getMinute(), $m); $this->assertEquals($test->getSecond(), $s); $this->assertEquals($test->getNano(), $n); $this->assertEquals($test->getOffset(), $offset); $this->assertEquals($test, $test); $this->assertEquals(OffsetDateTime::ofDateTime(LocalDateTime::of($y, $mo, $d, $h, $m, $s, $n), $offset), $test); }