示例#1
0
 /**
  * Obtains an instance of {@code Year} from a text string using a specific formatter.
  * <p>
  * The text is parsed using the formatter, returning a year.
  *
  * @param string $text the text to parse, not null
  * @param DateTimeFormatter $formatter the formatter to use, not null
  * @return Year the parsed year, not null
  * @throws DateTimeParseException if the text cannot be parsed
  */
 public static function parseWith($text, DateTimeFormatter $formatter)
 {
     if (!is_string($text)) {
         throw new \InvalidArgumentException();
     }
     return $formatter->parseQuery($text, TemporalQueries::fromCallable([self::class, 'from']));
 }
示例#2
0
 /**
  * Obtains an instance of {@code OffsetDateTime} from a text string using a specific formatter.
  * <p>
  * The text is parsed using the formatter, returning a date-time.
  *
  * @param string $text the text to parse, not null
  * @param DateTimeFormatter $formatter the formatter to use, not null
  * @return OffsetDateTime the parsed offset date-time, not null
  * @throws DateTimeParseException if the text cannot be parsed
  */
 public static function parseWith($text, DateTimeFormatter $formatter)
 {
     return $formatter->parseQuery($text, TemporalQueries::fromCallable([OffsetDateTime::class, 'from']));
 }
 private function parse(DateTimeFormatter $fmt, $zid, $expected, $text, Locale $locale, TextStyle $style, $ci)
 {
     if ($ci) {
         $text = $text->toUpperCase();
     }
     /** @var ZoneId $ret */
     $ret = $fmt->parseQuery($text, TemporalQueries::zone())->getId();
     // TBD: need an excluding list
     // assertEquals(...);
     if ($ret->equals($expected) || $ret->equals($zid) || $ret->equals(ZoneName::toZid($zid)) || $ret->equals($expected->replace("UTC", "UCT"))) {
         return;
     }
     echo printf("[%-5s %s %s %16s] %24s -> %s(%s)%n", $locale->__toString(), $ci ? "ci" : "  ", $style == TextStyle::FULL() ? " full" : "short", $zid, $text, $ret, $expected);
 }