Class NamedTimeZone


  • public class NamedTimeZone
    extends java.lang.Object
    This class attempts to identify a timezone name, given the date (including the time zone offset) and the country. The process is heuristic: sometimes there is more than one timezone that matches this information, sometimes there is none, but the class simply does its best. This is in support of the XSLT format-date() function.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> idForCountry  
      (package private) static java.util.Set<java.lang.String> knownTimeZones  
      (package private) static java.util.List<java.lang.String> worldTimeZones  
    • Constructor Summary

      Constructors 
      Constructor Description
      NamedTimeZone()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int civilTimeOffset​(DateTimeValue date, java.lang.String olsenName)
      Get the civil time offset to be made to a given date/time in a given civil timezone.
      static java.lang.String formatTimeZoneOffset​(DateTimeValue timeValue)
      Format a timezone in numeric form for example +03:00 (or Z for +00:00)
      static java.util.TimeZone getNamedTimeZone​(java.lang.String olsonName)
      Get the TimeZone object for a given Olson timezone name
      static java.lang.String getOlsenTimeZoneName​(DateTimeValue date, java.lang.String country)
      Try to identify a timezone name corresponding to a given date (including time zone) and a given country.
      static java.lang.String getTimeZoneNameForDate​(DateTimeValue date, java.lang.String place)
      Try to identify a timezone name corresponding to a given date (including time zone) and a given country.
      static java.lang.Boolean inSummerTime​(DateTimeValue date, java.lang.String region)
      Determine whether a given date/time is in summer time (daylight savings time) in a given region.
      (package private) static void tz​(java.lang.String country, java.lang.String zoneId)
      Register a timezone in use in a particular country.
      (package private) static void tz​(java.lang.String country, java.lang.String zoneId, boolean major)
      Register a timezone in use in a particular country, and mark it as a major world timezone so it is also recognized in other countries.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • knownTimeZones

        static java.util.Set<java.lang.String> knownTimeZones
      • idForCountry

        static java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> idForCountry
      • worldTimeZones

        static java.util.List<java.lang.String> worldTimeZones
    • Constructor Detail

      • NamedTimeZone

        public NamedTimeZone()
    • Method Detail

      • tz

        static void tz​(java.lang.String country,
                       java.lang.String zoneId)
        Register a timezone in use in a particular country. Note that some countries use multiple time zones
        Parameters:
        country - the two-character code for the country
        zoneId - the Olsen timezone name for the timezone
      • tz

        static void tz​(java.lang.String country,
                       java.lang.String zoneId,
                       boolean major)
        Register a timezone in use in a particular country, and mark it as a major world timezone so it is also recognized in other countries. Note that some countries use multiple time zones
        Parameters:
        country - the two-character code for the country
        zoneId - the Olsen timezone name for the timezone
        major - true if this is a major world timezone, meaning that its name is recognized by people outside its own country
      • getTimeZoneNameForDate

        public static java.lang.String getTimeZoneNameForDate​(DateTimeValue date,
                                                              java.lang.String place)
        Try to identify a timezone name corresponding to a given date (including time zone) and a given country. Note that this takes account of Java's calendar of daylight savings time changes in different countries. The returned value is the convenional short timezone name, for example PDT for Pacific Daylight Time
        Parameters:
        date - the dateTimeValue, including timezone
        place - either a two-letter ISO country code or an Olson timezone name
        Returns:
        the short timezone name if a timezone with the given time displacement is in use in the country in question (on the appropriate date, if known). Otherwise, the formatted (numeric) timezone offset. If the dateTimeValue supplied has no timezone, return a zero-length string.
      • formatTimeZoneOffset

        public static java.lang.String formatTimeZoneOffset​(DateTimeValue timeValue)
        Format a timezone in numeric form for example +03:00 (or Z for +00:00)
        Parameters:
        timeValue - the value whose timezone is to be formatted
        Returns:
        the formatted timezone
      • getOlsenTimeZoneName

        public static java.lang.String getOlsenTimeZoneName​(DateTimeValue date,
                                                            java.lang.String country)
        Try to identify a timezone name corresponding to a given date (including time zone) and a given country. Note that this takes account of Java's calendar of daylight savings time changes in different countries. The returned value is the Olsen time zone name, for example "Pacific/Los_Angeles", followed by an asterisk (*) if the time is in daylight savings time in that timezone.
        Parameters:
        date - the dateTimeValue, including timezone
        country - the country, as a two-letter code
        Returns:
        the Olsen timezone name if a timezone with the given time displacement is in use in the country in question (on the appropriate date, if known). In this case an asterisk is appended to the result if the date/time is in daylight savings time. Otherwise, the formatted (numeric) timezone offset. If the dateTimeValue supplied has no timezone, return a zero-length string.
      • inSummerTime

        public static java.lang.Boolean inSummerTime​(DateTimeValue date,
                                                     java.lang.String region)
        Determine whether a given date/time is in summer time (daylight savings time) in a given region. This relies on the Java database of changes to daylight savings time. Since summer time changes are set by civil authorities the information is not necessarily reliable when applied to dates in the future.
        Parameters:
        date - the date/time in question
        region - either the two-letter ISO country code, or an Olsen timezone name such as "America/New_York" or "Europe/Lisbon". If the country code denotes a country spanning several timezones, such as the US, then one of them is chosen arbitrarily.
        Returns:
        true if the date/time is known to be in summer time in the relevant country; false if it is known not to be in summer time; null if there is no timezone or if no information is available for the specified region.
      • civilTimeOffset

        public static int civilTimeOffset​(DateTimeValue date,
                                          java.lang.String olsenName)
        Get the civil time offset to be made to a given date/time in a given civil timezone. For example, if the timezone is America/New_York, the civil time offset will be -5 hours (= 5 x 3600000 ms) during the winter and -4 hours (=4 x 3600000 ms) during the summer
        Parameters:
        date - the date/time in question. If this has no timezone, it is assumed to be in GMT.
        olsenName - the Olsen name of the timezone, for example Europe/Lisbon
        Returns:
        the civil time offset, in milliseconds, to be applied to the given date/time
      • getNamedTimeZone

        public static java.util.TimeZone getNamedTimeZone​(java.lang.String olsonName)
        Get the TimeZone object for a given Olson timezone name
        Parameters:
        olsonName - an Olson timezone name, for example "Europe/London"
        Returns:
        the corresponding TimeZone object, or null if not available