Package com.ibm.icu.text.TimeZoneNames

Examples of com.ibm.icu.text.TimeZoneNames.NameType


      assert (style == LONG || style == SHORT || style == SHORT_COMMONLY_USED);

      // Gets the name directly from TimeZoneNames
      long date = System.currentTimeMillis();
      TimeZoneNames tznames = TimeZoneNames.getInstance(locale);
      NameType nameType = null;
      switch (style) {
      case LONG:
        nameType = daylight ? NameType.LONG_DAYLIGHT : NameType.LONG_STANDARD;
        break;
      case SHORT:
View Full Code Here


    if (tzID == null) {
      return null;
    }

    // Try to get a name from time zone first
    NameType nameType = (type == GenericNameType.LONG) ? NameType.LONG_GENERIC : NameType.SHORT_GENERIC;
    String name = _tznames.getTimeZoneDisplayName(tzID, nameType);

    if (name != null) {
      return name;
    }

    // Try meta zone
    String mzID = _tznames.getMetaZoneID(tzID, date);
    if (mzID != null) {
      boolean useStandard = false;
      int[] offsets = { 0, 0 };
      tz.getOffset(date, false, offsets);

      if (offsets[1] == 0) {
        useStandard = true;
        // Check if the zone actually uses daylight saving time around the time
        if (tz instanceof BasicTimeZone) {
          BasicTimeZone btz = (BasicTimeZone) tz;
          TimeZoneTransition before = btz.getPreviousTransition(date, true);
          if (before != null && (date - before.getTime() < DST_CHECK_RANGE) && before.getFrom().getDSTSavings() != 0) {
            useStandard = false;
          } else {
            TimeZoneTransition after = btz.getNextTransition(date, false);
            if (after != null && (after.getTime() - date < DST_CHECK_RANGE) && after.getTo().getDSTSavings() != 0) {
              useStandard = false;
            }
          }
        } else {
          // If not BasicTimeZone... only if the instance is not an ICU's implementation.
          // We may get a wrong answer in edge case, but it should practically work OK.
          int[] tmpOffsets = new int[2];
          tz.getOffset(date - DST_CHECK_RANGE, false, tmpOffsets);
          if (tmpOffsets[1] != 0) {
            useStandard = false;
          } else {
            tz.getOffset(date + DST_CHECK_RANGE, false, tmpOffsets);
            if (tmpOffsets[1] != 0) {
              useStandard = false;
            }
          }
        }
      }
      if (useStandard) {
        NameType stdNameType = (nameType == NameType.LONG_GENERIC) ? NameType.LONG_STANDARD : NameType.SHORT_STANDARD;
        String stdName = _tznames.getDisplayName(tzID, stdNameType, date);
        if (stdName != null) {
          name = stdName;

          // TODO: revisit this issue later
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.TimeZoneNames.NameType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.