Class DateTimeFormatUtil

java.lang.Object
dev.metaschema.core.metapath.function.library.DateTimeFormatUtil

public final class DateTimeFormatUtil extends Object
Utility class for parsing and formatting date/time picture strings as defined in XPath Functions 3.1 Section 9.8.
  • Method Details

    • parsePictureString

      @NonNull public static List<DateTimeFormatUtil.FormatComponent> parsePictureString(@NonNull String picture)
      Parse a picture string into a list of format components.

      The picture string consists of literal substrings and variable markers enclosed in square brackets. Doubled brackets [[ and ]] are treated as escaped literal brackets.

      Parameters:
      picture - the picture string to parse
      Returns:
      an unmodifiable list of format components
      Throws:
      FormatDateTimeFunctionException - with FormatDateTimeFunctionException.INVALID_PICTURE_STRING if the picture string syntax is invalid
      See Also:
    • formatDateTime

      @NonNull public static String formatDateTime(@NonNull ITemporalItem value, @NonNull String picture, @Nullable String language, @Nullable String calendar, @Nullable String place, @NonNull Set<Character> allowedMarkers)
      Format a temporal value according to a picture string.

      This method implements the formatting algorithm defined in XPath Functions 3.1 Section 9.8. The picture string is parsed into literal and variable marker components, and each variable marker is formatted according to its component specifier, presentation modifier, and width modifier.

      Parameters:
      value - the temporal value to format
      picture - the picture string
      language - the language for names, or null for English
      calendar - the calendar system, or null for Gregorian
      place - the place for timezone, or null
      allowedMarkers - the set of allowed component specifiers
      Returns:
      the formatted string
      Throws:
      FormatDateTimeFunctionException - if formatting fails