Skip to content

Commit

Permalink
reverse conversion of winzones
Browse files Browse the repository at this point in the history
see issue #756
  • Loading branch information
MenoData committed Mar 16, 2018
1 parent 3110b17 commit 73e1313
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
32 changes: 31 additions & 1 deletion misc/src/main/java/net/time4j/tz/other/WindowsZone.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2017 Meno Hochschild, <http://www.menodata.de/>
* Copyright © 2013-2018 Meno Hochschild, <http://www.menodata.de/>
* -----------------------------------------------------------------------
* This file (WindowsZone.java) is part of project Time4J.
*
Expand All @@ -22,7 +22,10 @@
package net.time4j.tz.other;

import net.time4j.format.internal.FormatUtils;
import net.time4j.tz.NameStyle;
import net.time4j.tz.TZID;
import net.time4j.tz.Timezone;
import net.time4j.tz.ZoneNameProvider;
import net.time4j.tz.spi.WinZoneProviderSPI;

import java.io.IOException;
Expand Down Expand Up @@ -171,6 +174,33 @@ public String toString() {

}

/**
* <p>Deduces the windows name of given timezone reference and region. </p>
*
* @param tzid timezone identifier
* @param locale regional setting referring to a country
* @return name of windows zone, maybe empty if resolving fails
* @since 3.41/4.36
*/
/*[deutsch]
* <p>Leitet den Windows-Namen aus der angegebenen Zeitzonenreferenz in der jeweiligen Region ab. </p>
*
* @param tzid timezone identifier
* @param locale regional setting referring to a country
* @return name of windows zone, maybe empty if resolving fails
* @since 3.41/4.36
*/
public static String toString(
String tzid,
Locale locale
) {

String zoneID = Timezone.normalize(tzid).canonical();
ZoneNameProvider znp = new WinZoneProviderSPI();
return znp.getDisplayName(zoneID, NameStyle.LONG_GENERIC_TIME, locale);

}

/**
* <p>The natural order is based on the lexicographical order of the
* underlying names of windows zones. </p>
Expand Down
Binary file modified misc/src/main/resources/data/winzone.ser
Binary file not shown.
11 changes: 11 additions & 0 deletions misc/src/test/java/net/time4j/tz/other/WindowsZoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ public void normalize() {
is("America/New_York"));
}

@Test
public void toStringStatic() {
assertThat(
WindowsZone.toString("America/New_York", Locale.US),
is("Eastern Standard Time"));
assertThat(
WindowsZone.toString("Asia/Kolkata", new Locale("en", "IN")),
is("India Standard Time"));
// CLDR uses "Asia/Calcutta", but Time4J adjusts it during compiling of winzone-data
}

private static Object roundtrip(Object obj)
throws IOException, ClassNotFoundException {

Expand Down

0 comments on commit 73e1313

Please sign in to comment.