Пример #1
0
 /**
  * Extensive testing is done in LocalDate::until().
  */
 public function testBetween()
 {
     $period = Period::between(LocalDate::of(2010, 1, 15), LocalDate::of(2011, 3, 18));
     $this->assertPeriodIs(1, 2, 3, $period);
 }
Пример #2
0
 /**
  * @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);
 }
Пример #3
0
 /**
  * Combines this year-month with a day-of-month to create a LocalDate.
  *
  * @param integer $day The day-of-month to use, valid for the year-month.
  *
  * @return LocalDate The date formed from this year-month and the specified day.
  *
  * @throws DateTimeException If the day is not valid for this year-month.
  */
 public function atDay($day)
 {
     return LocalDate::of($this->year, $this->month, $day);
 }
Пример #4
0
 /**
  * Returns the maximum supported LocalDate.
  *
  * This can be used by an application as a "far future" date.
  *
  * @return LocalDate
  */
 public static function max()
 {
     return LocalDate::of(self::MAX_YEAR, 12, 31);
 }
Пример #5
0
 public function testMinMaxOf()
 {
     $a = LocalDate::of(2015, 9, 30);
     $b = LocalDate::of(2016, 7, 31);
     $c = LocalDate::of(2017, 2, 1);
     $this->assertSame($a, LocalDate::minOf($a, $b, $c));
     $this->assertSame($c, LocalDate::maxOf($a, $b, $c));
 }
Пример #6
0
 /**
  * Combines this month-day with a year to create a LocalDate.
  *
  * This returns a LocalDate formed from this month-day and the specified year.
  *
  * A month-day of February 29th will be adjusted to February 28th
  * in the resulting date if the year is not a leap year.
  *
  * @param integer $year
  *
  * @return LocalDate
  *
  * @throws DateTimeException If the year is invalid.
  */
 public function atYear($year)
 {
     return LocalDate::of($year, $this->month, $this->isValidYear($year) ? $this->day : 28);
 }
Пример #7
0
 public function testAtDate()
 {
     $time = LocalTime::of(12, 34, 56, 789);
     $date = LocalDate::of(2014, 11, 30);
     $this->assertLocalDateTimeIs(2014, 11, 30, 12, 34, 56, 789, $time->atDate($date));
 }
Пример #8
0
 /**
  * @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));
 }
Пример #9
0
 public function testToString()
 {
     $this->assertSame('2008-12-31/2011-01-01', (string) LocalDateRange::of(LocalDate::of(2008, 12, 31), LocalDate::of(2011, 1, 1)));
 }