Class WindowsZone

java.lang.Object
net.time4j.tz.other.WindowsZone
All Implemented Interfaces:
Serializable, Comparable<WindowsZone>

public final class WindowsZone extends Object implements Comparable<WindowsZone>, Serializable

Represents a windows timezone name which can be mapped to an IANA/Olson-ID using a territory information.

Example:

  WindowsZone wzn = WindowsZone.of("Eastern Standard Time");
  TZID winzone = wzn.resolveSmart(Locale.US);
  System.out.println(winzone.canonical());
  // output: WINDOWS~America/New_York
 

The reverse way:

  String winzone = WindowsZone.toString("America/New_York", Locale.US);
  System.out.println(winzone);
  // output: Eastern Standard Time
 

Note: A perfect roundtrip is often not possible because there are many more IANA-zone identifiers than windows zones. For best results, it is recommended to use the tzdata-module and not the standard timezone data of the underlying platform.

Since:
2.2
Author:
Meno Hochschild
See Also:
Serialized Form
  • Method Details

    • getAvailableNames

      public static Set<String> getAvailableNames()

      Yields all available names of windows zones.

      Returns:
      unmodifiable set of zone names for Windows
      Since:
      2.3
    • of

      public static WindowsZone of(String name)

      Creates a name reference to a windows zone.

      Parameters:
      name - standardized windows zone name
      Returns:
      new instance of WindowsZone
      Throws:
      IllegalArgumentException - if given name is not supported
      Since:
      2.2
      See Also:
      getAvailableNames(), toString()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()

      Returns the name of this windows zone reference.

      Overrides:
      toString in class Object
      Returns:
      name of windows zone
    • toString

      public static String toString(TZID tzid, Locale locale)

      Deduces the windows name of given timezone reference and region.

      Parameters:
      tzid - timezone identifier (usually a IANA/Olson-ID like "America/New_York")
      locale - regional setting referring to a country
      Returns:
      name of windows zone, maybe empty if resolving fails
      Since:
      3.41/4.36
      See Also:
      toString(String, Locale)
    • toString

      public static String toString(String tzid, Locale locale)

      Deduces the windows name of given timezone reference and region.

      This method first tries all to automatically normalize given timezone identifier before resolving to the windows name. Normalizing works best if the tzdata-module is present.

      Parameters:
      tzid - timezone identifier (usually a IANA/Olson-ID like "America/New_York")
      locale - regional setting referring to a country
      Returns:
      name of windows zone, maybe empty if resolving fails
      Since:
      3.41/4.36
      See Also:
      Timezone.normalize(String)
    • compareTo

      public int compareTo(WindowsZone other)

      The natural order is based on the lexicographical order of the underlying names of windows zones.

      Specified by:
      compareTo in interface Comparable<WindowsZone>
      Parameters:
      other - another windows zone name reference
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
    • resolve

      public Set<TZID> resolve(Locale country)

      Resolves this name reference to a set of various zone ids for given country.

      Parameters:
      country - country reference
      Returns:
      set of ids belonging to this windows zone
      Since:
      2.2
    • resolveSmart

      public Optional<TZID> resolveSmart(Locale country)

      Resolves this name reference to at most one zone id for given country.

      Normally windows zones cannot be resolved to one single zone id, but there is usually one preferred zone id based on the fact that the daylight saving rules for this name and given country are often the same for all belonging zone ids in the recent past. This method tries its best to yield a result but applications have to check if a result is available.

      Important: The country reference must be given, that is, country.getCountry() must not be empty otherwise this method will not return any result.

      Parameters:
      country - country reference
      Returns:
      preferred zone id belonging to this windows zone or not present if given country is not related to this name
      Since:
      5.0