Class FastTimeZone

java.lang.Object
org.apache.commons.lang3.time.FastTimeZone

public class FastTimeZone extends Object
Faster methods to produce custom time zones.
Since:
3.7
  • Field Details

    • GMT_PATTERN

      private static final Pattern GMT_PATTERN
    • GREENWICH

      private static final TimeZone GREENWICH
  • Constructor Details

    • FastTimeZone

      private FastTimeZone()
  • Method Details

    • getGmtTimeZone

      public static TimeZone getGmtTimeZone()
      Gets the GMT TimeZone.
      Returns:
      A TimeZone with a raw offset of zero.
    • getGmtTimeZone

      public static TimeZone getGmtTimeZone(String pattern)
      Gets a TimeZone with GMT offsets. A GMT offset must be either 'Z', or 'UTC', or match (GMT)? hh?(:?mm?)?, where h and m are digits representing hours and minutes.

      Note: the underlying regex is lenient — every capture group (sign, hours, minutes, and the GMT prefix) is optional. Inputs that lack any digit group, such as the empty string, "+", "-", or "GMT" alone, still match and the method returns the GMT TimeZone with a raw offset of zero (mirroring TimeZone.getTimeZone(String) JDK-parity for unrecognized ids). Inputs that fail the regex outright, or that match but specify an out-of-range offset (24 hours or 60 minutes and above), return null.

      Parameters:
      pattern - The GMT offset.
      Returns:
      A TimeZone matching the (possibly partial or empty) GMT offset pattern, defaulting to GMT for an unrecognized but parseable input, or null if the pattern fails the regex or specifies an out-of-range offset.
    • getTimeZone

      public static TimeZone getTimeZone(String id)
      Gets a TimeZone, looking first for GMT custom ids, then falling back to Olson ids. A GMT custom id can be 'Z', or 'UTC', or has an optional prefix of GMT, followed by sign, hours digit(s), optional colon(':'), and optional minutes digits. i.e. [GMT] (+|-) Hours [[:] Minutes]
      Parameters:
      id - A GMT custom id or Olson id.
      Returns:
      A time zone.
    • parseInt

      private static int parseInt(String s)
    • parseSign

      private static boolean parseSign(String group)