Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4176686

java.util.TimeZone.getDisplayName(boolean, int, Locale) works wrong

    XMLWordPrintable

Details

    • beta
    • sparc
    • solaris_2.5

    Description



      Name: avC70361 Date: 09/28/98



        The java.util.TimeZone.getDisplayName(boolean, int, Locale) returns wrong result for SimpleTimeZone
      instances with DSTSavings not equal to 1 hour. When a time zone's display name is not available for the localeand the first parameter is true(returns daylight savings name) it returns a result considering DST offset
      always to be 1 hour whereas the right value can be different.

      Here is a test demonstrating the bug.
      --------------GetDisplayNameTest.java---------------
      import java.util.Locale;
      import java.util.SimpleTimeZone;
      import java.util.TimeZone;

      public class GetDisplayNameTest {
        public static void main(String args[]) {
          int offset = 3 * 60 * 60 * 1000 / 2; // 1.5 hour
          SimpleTimeZone stz = new SimpleTimeZone(offset, "My TZ");
          stz.setDSTSavings(60 * 60 * 1000 / 2); // DST offset 0.5 hour

          String name = stz.getDisplayName(true, TimeZone.SHORT, Locale.getDefault());
          String expected = "GMT+02:00"; // offset during DST 1.5 + 0.5 = 2 hour

          if (name.equals(expected)) {
            System.out.println("Passed");
          } else {
            System.out.println(
              "Failed. Name returned = " + name + ", expected name = " + expected
            );
          }
        }
      }
      -------------The test output----------
      > java GetDisplayNameTest
      Failed. Name returned = GMT+02:30, expected name = GMT+02:00


      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              aliusunw Alan Liu (Inactive)
              ovlasov Oleksandr Vlasov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: