Search in sources :

Example 21 with TimeZoneTransition

use of android.icu.util.TimeZoneTransition in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TimeZoneInfoPreferenceController method formatInfo.

private CharSequence formatInfo(TimeZoneInfo item) {
    final CharSequence offsetAndName = formatOffsetAndName(item);
    final TimeZone timeZone = item.getTimeZone();
    if (!timeZone.observesDaylightTime()) {
        return mContext.getString(R.string.zone_info_footer_no_dst, offsetAndName);
    }
    final TimeZoneTransition nextDstTransition = findNextDstTransition(timeZone);
    if (nextDstTransition == null) {
        return null;
    }
    final boolean toDst = nextDstTransition.getTo().getDSTSavings() != 0;
    String timeType = toDst ? item.getDaylightName() : item.getStandardName();
    if (timeType == null) {
        // Fall back to generic "summer time" and "standard time" if the time zone has no
        // specific names.
        timeType = toDst ? mContext.getString(R.string.zone_time_type_dst) : mContext.getString(R.string.zone_time_type_standard);
    }
    final Calendar transitionTime = Calendar.getInstance(timeZone);
    transitionTime.setTimeInMillis(nextDstTransition.getTime());
    final String date = mDateFormat.format(transitionTime);
    return SpannableUtil.getResourcesText(mContext.getResources(), R.string.zone_info_footer, offsetAndName, timeType, date);
}
Also used : TimeZone(android.icu.util.TimeZone) BasicTimeZone(android.icu.util.BasicTimeZone) TimeZoneTransition(android.icu.util.TimeZoneTransition) Calendar(android.icu.util.Calendar)

Example 22 with TimeZoneTransition

use of android.icu.util.TimeZoneTransition in project android_packages_apps_Settings by omnirom.

the class TimeZoneInfoPreferenceController method formatInfo.

private CharSequence formatInfo(TimeZoneInfo item) {
    final CharSequence offsetAndName = formatOffsetAndName(item);
    final TimeZone timeZone = item.getTimeZone();
    if (!timeZone.observesDaylightTime()) {
        return mContext.getString(R.string.zone_info_footer_no_dst, offsetAndName);
    }
    final TimeZoneTransition nextDstTransition = findNextDstTransition(timeZone);
    if (nextDstTransition == null) {
        return null;
    }
    final boolean toDst = nextDstTransition.getTo().getDSTSavings() != 0;
    String timeType = toDst ? item.getDaylightName() : item.getStandardName();
    if (timeType == null) {
        // Fall back to generic "summer time" and "standard time" if the time zone has no
        // specific names.
        timeType = toDst ? mContext.getString(R.string.zone_time_type_dst) : mContext.getString(R.string.zone_time_type_standard);
    }
    final Calendar transitionTime = Calendar.getInstance(timeZone);
    transitionTime.setTimeInMillis(nextDstTransition.getTime());
    final String date = mDateFormat.format(transitionTime);
    return SpannableUtil.getResourcesText(mContext.getResources(), R.string.zone_info_footer, offsetAndName, timeType, date);
}
Also used : TimeZone(android.icu.util.TimeZone) BasicTimeZone(android.icu.util.BasicTimeZone) TimeZoneTransition(android.icu.util.TimeZoneTransition) Calendar(android.icu.util.Calendar)

Aggregations

TimeZoneTransition (android.icu.util.TimeZoneTransition)22 BasicTimeZone (android.icu.util.BasicTimeZone)17 Test (org.junit.Test)8 TimeZone (android.icu.util.TimeZone)6 AnnualTimeZoneRule (android.icu.util.AnnualTimeZoneRule)5 InitialTimeZoneRule (android.icu.util.InitialTimeZoneRule)5 TimeZoneRule (android.icu.util.TimeZoneRule)5 Date (java.util.Date)5 Calendar (android.icu.util.Calendar)4 SimpleTimeZone (android.icu.util.SimpleTimeZone)4 TimeArrayTimeZoneRule (android.icu.util.TimeArrayTimeZoneRule)4 VTimeZone (android.icu.util.VTimeZone)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Instant (java.time.Instant)2 ZoneOffset (java.time.ZoneOffset)2 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)2