/** * @param integer $year The year, from MIN_YEAR to MAX_YEAR. * @param integer $month The month-of-year, from 1 (January) to 12 (December). * @param integer $day The day-of-month, from 1 to 31. * @param integer $hour The hour-of-day, from 0 to 23. * @param integer $minute The minute-of-hour, from 0 to 59. * @param integer $second The second-of-minute, from 0 to 59. * @param integer $nano The nano-of-second, from 0 to 999,999,999. * * @return LocalDateTime * * @throws DateTimeException If the date or time is not valid. */ public static function of($year, $month, $day, $hour = 0, $minute = 0, $second = 0, $nano = 0) { $date = LocalDate::of($year, $month, $day); $time = LocalTime::of($hour, $minute, $second, $nano); return new LocalDateTime($date, $time); }
public function testAtTime() { $localDateTime = LocalDate::of(1, 2, 3)->atTime(LocalTime::of(4, 5, 6, 7)); $this->assertLocalDateTimeIs(1, 2, 3, 4, 5, 6, 7, $localDateTime); }
public function testMinMaxOf() { $a = LocalTime::of(11, 45); $b = LocalTime::of(14, 30); $c = LocalTime::of(17, 15); $this->assertSame($a, LocalTime::minOf($a, $b, $c)); $this->assertSame($c, LocalTime::maxOf($a, $b, $c)); }
/** * @param DateTimeParseResult $result * * @return LocalTime * * @throws DateTimeException If the time is not valid. * @throws DateTimeParseException If required fields are missing from the result. */ public static function from(DateTimeParseResult $result) { $hour = $result->getField(HourOfDay::NAME); $minute = $result->getField(MinuteOfHour::NAME); $second = $result->getOptionalField(SecondOfMinute::NAME); $fraction = $result->getOptionalField(Field\FractionOfSecond::NAME); $nano = substr($fraction . '000000000', 0, 9); return LocalTime::of((int) $hour, (int) $minute, (int) $second, (int) $nano); }
/** * @dataProvider providerDuration * * @param integer $ds The seconds of the duration. * @param integer $dn The nano adjustment of the duration. * @param integer $y The expected year. * @param integer $m The expected month. * @param integer $d The expected day. * @param integer $h The exepected hour. * @param integer $i The expected minute. * @param integer $s The expected second. * @param integer $n The expected nano. */ public function testMinusDuration($ds, $dn, $y, $m, $d, $h, $i, $s, $n) { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 123456789)); $duration = Duration::ofSeconds(-$ds, -$dn); $this->assertLocalDateTimeIs($y, $m, $d, $h, $i, $s, $n, $localDateTime->minusDuration($duration)); }