Example #1
0
 /**
  * Obtains an instance of `LocalDateRange` from a set of date-time fields.
  *
  * This method is only useful to parsers.
  *
  * @param DateTimeParseResult $result
  *
  * @return LocalDateRange
  *
  * @throws DateTimeException      If the date range is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $startDate = LocalDate::from($result);
     if ($result->hasField(Field\MonthOfYear::NAME)) {
         if ($result->hasField(Field\Year::NAME)) {
             $endDate = LocalDate::from($result);
         } else {
             $endDate = MonthDay::from($result)->atYear($startDate->getYear());
         }
     } else {
         $endDate = $startDate->withDay((int) $result->getField(Field\DayOfMonth::NAME));
     }
     return LocalDateRange::of($startDate, $endDate);
 }
Example #2
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)));
 }