Package org.apache.groovy.json.internal

# Class Dates

java.lang.Object
org.apache.groovy.json.internal.Dates

public class Dates extends Object
Date helpers used by the JSON parser for supported timestamp formats.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `JSON_TIME_LENGTH`
  Length of a JSON timestamp with millisecond precision.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Dates()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Date`
  `fromISO8601(char[] charArray, int from, int to)`
  `static Date`
  `fromJsonDate(char[] charArray, int from, int to)`
  Parses a supported JSON timestamp with millisecond precision.
  `static boolean`
  `isISO8601(char[] charArray, int start, int to)`
  Checks whether a slice matches the parser's supported ISO-8601 layouts.
  `static boolean`
  `isISO8601QuickCheck(char[] charArray, int start, int to)`
  Performs a quick length and separator check for ISO-8601-like values.
  `static boolean`
  `isJsonDate(char[] charArray, int start, int to)`
  Checks whether a slice matches the parser's JSON date layout.
  `static OffsetDateTime`
  `offsetDateTimeFromISO8601(char[] charArray, int from, int to)`
  Reads an ISO-8601 form as an offset date-time, keeping the offset the text carried.
  `static OffsetDateTime`
  `offsetDateTimeFromJsonDate(char[] charArray, int from, int to)`
  Reads a JSON-date form as an offset date-time.
  `static Date`
  `toDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second)`
  Creates a `Date` from date-time fields in the supplied time zone.
  `static Date`
  `toDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int milliseconds)`
  Creates a `Date` from date-time fields including milliseconds.
  `static long`
  `utc(long time)`
  Returns the epoch milliseconds for the supplied instant using a UTC-based calendar.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### JSON_TIME_LENGTH

    public static final int JSON_TIME_LENGTH
    Length of a JSON timestamp with millisecond precision.

- ## Constructor Details

  - ### Dates

    public Dates()

- ## Method Details

  - ### utc

    public static long utc(long time)
    Returns the epoch milliseconds for the supplied instant using a UTC-based calendar.
    Parameters:
      `time` - epoch milliseconds
    Returns:
      UTC-normalized epoch milliseconds

  - ### toDate

    public static Date toDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second)
    Creates a `Date` from date-time fields in the supplied time zone.
    Parameters:
      `tz` - time zone to apply
      `year` - year value
      `month` - month value from `1` to `12`
      `day` - day of month
      `hour` - hour of day
      `minute` - minute of hour
      `second` - second of minute
    Returns:
      created date

  - ### toDate

    public static Date toDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int milliseconds)
    Creates a `Date` from date-time fields including milliseconds.
    Parameters:
      `tz` - time zone to apply
      `year` - year value
      `month` - month value from `1` to `12`
      `day` - day of month
      `hour` - hour of day
      `minute` - minute of hour
      `second` - second of minute
      `milliseconds` - millisecond value
    Returns:
      created date

  - ### offsetDateTimeFromISO8601

    public static OffsetDateTime offsetDateTimeFromISO8601(char[] charArray, int from, int to)
    Reads an ISO-8601 form as an offset date-time, keeping the offset the text carried. Reads the same fields as `fromISO8601(char[], int, int)` rather than handing the text to a formatter, so that the scan stays as cheap as the one the parsers already do.
    Parameters:
      `charArray` - buffer holding the token
      `from` - start index, inclusive
      `to` - end index, exclusive
    Returns:
      the value, or `null` if the text is not in this form

  - ### offsetDateTimeFromJsonDate

    public static OffsetDateTime offsetDateTimeFromJsonDate(char[] charArray, int from, int to)
    Reads a JSON-date form as an offset date-time. That form carries no offset of its own and is read as UTC, as `fromJsonDate(char[], int, int)` reads it.
    Parameters:
      `charArray` - buffer holding the token
      `from` - start index, inclusive
      `to` - end index, exclusive
    Returns:
      the value, or `null` if the text is not in this form

  - ### fromISO8601

    public static Date fromISO8601(char[] charArray, int from, int to)

  - ### fromJsonDate

    public static Date fromJsonDate(char[] charArray, int from, int to)
    Parses a supported JSON timestamp with millisecond precision.
    Parameters:
      `charArray` - source character buffer
      `from` - inclusive start index
      `to` - exclusive end index
    Returns:
      parsed date, or `null` when the slice is not a supported JSON date value

  - ### isISO8601

    public static boolean isISO8601(char[] charArray, int start, int to)
    Checks whether a slice matches the parser's supported ISO-8601 layouts.
    Parameters:
      `charArray` - source character buffer
      `start` - inclusive start index
      `to` - exclusive end index
    Returns:
      `true` when the slice matches a supported ISO-8601 layout

  - ### isISO8601QuickCheck

    public static boolean isISO8601QuickCheck(char[] charArray, int start, int to)
    Performs a quick length and separator check for ISO-8601-like values.
    Parameters:
      `charArray` - source character buffer
      `start` - inclusive start index
      `to` - exclusive end index
    Returns:
      `true` when the slice looks like an ISO-8601 value

  - ### isJsonDate

    public static boolean isJsonDate(char[] charArray, int start, int to)
    Checks whether a slice matches the parser's JSON date layout.
    Parameters:
      `charArray` - source character buffer
      `start` - inclusive start index
      `to` - exclusive end index
    Returns:
      `true` when the slice matches the JSON date layout