Package com.ibm.icu.text

Examples of com.ibm.icu.text.TimeZoneFormat$GMTOffsetField


    String result = null;

    if (style == GENERIC_LOCATION || style == LONG_GENERIC || style == SHORT_GENERIC) {
      // Generic format
      TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(locale);
      long date = System.currentTimeMillis();
      Output<TimeType> timeType = new Output<TimeType>(TimeType.UNKNOWN);

      switch (style) {
      case GENERIC_LOCATION:
        result = tzfmt.format(Style.GENERIC_LOCATION, this, date, timeType);
        break;
      case LONG_GENERIC:
        result = tzfmt.format(Style.GENERIC_LONG, this, date, timeType);
        break;
      case SHORT_GENERIC:
        result = tzfmt.format(Style.GENERIC_SHORT, this, date, timeType);
        break;
      }

      // Generic format many use Localized GMT as the final fallback.
      // When Localized GMT format is used, the result might not be
      // appropriate for the requested daylight value.
      if (daylight && timeType.value == TimeType.STANDARD || !daylight && timeType.value == TimeType.DAYLIGHT) {
        int offset = daylight ? getRawOffset() + getDSTSavings() : getRawOffset();
        result = (style == SHORT_GENERIC) ? tzfmt.formatOffsetShortLocalizedGMT(offset) : tzfmt.formatOffsetLocalizedGMT(offset);
      }

    } else if (style == LONG_GMT || style == SHORT_GMT) {
      // Offset format
      TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(locale);
      int offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
      switch (style) {
      case LONG_GMT:
        result = tzfmt.formatOffsetLocalizedGMT(offset);
        break;
      case SHORT_GMT:
        result = tzfmt.formatOffsetISO8601Basic(offset, false, false, false);
        break;
      }
    } else {
      // Specific format
      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:
      case SHORT_COMMONLY_USED:
        nameType = daylight ? NameType.SHORT_DAYLIGHT : NameType.SHORT_STANDARD;
        break;
      }
      result = tznames.getDisplayName(ZoneMeta.getCanonicalCLDRID(this), nameType, date);
      if (result == null) {
        // Fallback to localized GMT
        TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(locale);
        int offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
        result = (style == LONG) ? tzfmt.formatOffsetLocalizedGMT(offset) : tzfmt.formatOffsetShortLocalizedGMT(offset);
      }
    }
    assert (result != null);

    return result;
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.TimeZoneFormat$GMTOffsetField

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.