Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26ed852e authored by vichang's avatar vichang Committed by Automerger Merge Worker
Browse files

Merge "Use new package name for ZoneInfo and libcore.timezone" am: af6f8e23 am: 64937407

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1346485

Change-Id: I5ded5092e4c7706f58417a5c97f3207524b44a95
parents 7ac8fcba 64937407
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.proto.ProtoOutputStream;

import libcore.timezone.ZoneInfoDb;
import com.android.i18n.timezone.ZoneInfoDb;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+19 −19
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package android.text.format;

import android.util.TimeFormatException;

import libcore.timezone.ZoneInfoDb;
import libcore.util.ZoneInfo;
import com.android.i18n.timezone.ZoneInfoData;
import com.android.i18n.timezone.ZoneInfoDb;

import java.util.Locale;
import java.util.TimeZone;
@@ -1070,15 +1070,15 @@ public class Time {
     * to the enclosing object, but others do not: thus separate state is retained.
     */
    private static class TimeCalculator {
        public final ZoneInfo.WallTime wallTime;
        public final ZoneInfoData.WallTime wallTime;
        public String timezone;

        // Information about the current timezone.
        private ZoneInfo zoneInfo;
        private ZoneInfoData mZoneInfoData;

        public TimeCalculator(String timezoneId) {
            this.zoneInfo = lookupZoneInfo(timezoneId);
            this.wallTime = new ZoneInfo.WallTime();
            this.mZoneInfoData = lookupZoneInfoData(timezoneId);
            this.wallTime = new ZoneInfoData.WallTime();
        }

        public long toMillis(boolean ignoreDst) {
@@ -1086,7 +1086,7 @@ public class Time {
                wallTime.setIsDst(-1);
            }

            int r = wallTime.mktime(zoneInfo);
            int r = wallTime.mktime(mZoneInfoData);
            if (r == -1) {
                return -1;
            }
@@ -1098,7 +1098,7 @@ public class Time {
            int intSeconds = (int) (millis / 1000);

            updateZoneInfoFromTimeZone();
            wallTime.localtime(intSeconds, zoneInfo);
            wallTime.localtime(intSeconds, mZoneInfoData);
        }

        public String format(String format) {
@@ -1106,31 +1106,31 @@ public class Time {
                format = "%c";
            }
            TimeFormatter formatter = new TimeFormatter();
            return formatter.format(format, wallTime, zoneInfo);
            return formatter.format(format, wallTime, mZoneInfoData);
        }

        private void updateZoneInfoFromTimeZone() {
            if (!zoneInfo.getID().equals(timezone)) {
                this.zoneInfo = lookupZoneInfo(timezone);
            if (!mZoneInfoData.getID().equals(timezone)) {
                this.mZoneInfoData = lookupZoneInfoData(timezone);
            }
        }

        private static ZoneInfo lookupZoneInfo(String timezoneId) {
            ZoneInfo zoneInfo = ZoneInfoDb.getInstance().makeTimeZone(timezoneId);
            if (zoneInfo == null) {
                zoneInfo = ZoneInfoDb.getInstance().makeTimeZone("GMT");
        private static ZoneInfoData lookupZoneInfoData(String timezoneId) {
            ZoneInfoData zoneInfoData = ZoneInfoDb.getInstance().makeZoneInfoData(timezoneId);
            if (zoneInfoData == null) {
                zoneInfoData = ZoneInfoDb.getInstance().makeZoneInfoData("GMT");
            }
            if (zoneInfo == null) {
            if (zoneInfoData == null) {
                throw new AssertionError("GMT not found: \"" + timezoneId + "\"");
            }
            return zoneInfo;
            return zoneInfoData;
        }

        public void switchTimeZone(String timezone) {
            int seconds = wallTime.mktime(zoneInfo);
            int seconds = wallTime.mktime(mZoneInfoData);
            this.timezone = timezone;
            updateZoneInfoFromTimeZone();
            wallTime.localtime(seconds, zoneInfo);
            wallTime.localtime(seconds, mZoneInfoData);
        }

        public String format2445(boolean hasTime) {
+25 −21
Original line number Diff line number Diff line
@@ -22,8 +22,9 @@ package android.text.format;

import android.content.res.Resources;

import com.android.i18n.timezone.ZoneInfoData;

import libcore.icu.LocaleData;
import libcore.util.ZoneInfo;

import java.nio.CharBuffer;
import java.time.Instant;
@@ -94,8 +95,8 @@ class TimeFormatter {
     * incorrect digit localization behavior.
     */
    String formatMillisWithFixedFormat(long timeMillis) {
        // This method is deliberately not a general purpose replacement for
        // format(String, ZoneInfo.WallTime, ZoneInfo): It hard-codes the pattern used; many of the
        // This method is deliberately not a general purpose replacement for format(String,
        // ZoneInfoData.WallTime, ZoneInfoData): It hard-codes the pattern used; many of the
        // pattern characters supported by Time.format() have unusual behavior which would make
        // using java.time.format or similar packages difficult. It would be a lot of work to share
        // behavior and many internal Android usecases can be covered by this common pattern
@@ -144,7 +145,8 @@ class TimeFormatter {
    /**
     * Format the specified {@code wallTime} using {@code pattern}. The output is returned.
     */
    public String format(String pattern, ZoneInfo.WallTime wallTime, ZoneInfo zoneInfo) {
    public String format(String pattern, ZoneInfoData.WallTime wallTime,
            ZoneInfoData zoneInfoData) {
        try {
            StringBuilder stringBuilder = new StringBuilder();

@@ -153,7 +155,7 @@ class TimeFormatter {
            // and locale sensitive strings are output directly using outputBuilder.
            numberFormatter = new Formatter(stringBuilder, Locale.US);

            formatInternal(pattern, wallTime, zoneInfo);
            formatInternal(pattern, wallTime, zoneInfoData);
            String result = stringBuilder.toString();
            // The localizeDigits() behavior is the source of a bug since some formats are defined
            // as being in ASCII and not localized.
@@ -186,13 +188,14 @@ class TimeFormatter {
     * Format the specified {@code wallTime} using {@code pattern}. The output is written to
     * {@link #outputBuilder}.
     */
    private void formatInternal(String pattern, ZoneInfo.WallTime wallTime, ZoneInfo zoneInfo) {
    private void formatInternal(String pattern, ZoneInfoData.WallTime wallTime,
            ZoneInfoData zoneInfoData) {
        CharBuffer formatBuffer = CharBuffer.wrap(pattern);
        while (formatBuffer.remaining() > 0) {
            boolean outputCurrentChar = true;
            char currentChar = formatBuffer.get(formatBuffer.position());
            if (currentChar == '%') {
                outputCurrentChar = handleToken(formatBuffer, wallTime, zoneInfo);
                outputCurrentChar = handleToken(formatBuffer, wallTime, zoneInfoData);
            }
            if (outputCurrentChar) {
                outputBuilder.append(formatBuffer.get(formatBuffer.position()));
@@ -201,8 +204,8 @@ class TimeFormatter {
        }
    }

    private boolean handleToken(CharBuffer formatBuffer, ZoneInfo.WallTime wallTime,
            ZoneInfo zoneInfo) {
    private boolean handleToken(CharBuffer formatBuffer, ZoneInfoData.WallTime wallTime,
            ZoneInfoData zoneInfoData) {

        // The char at formatBuffer.position() is expected to be '%' at this point.
        int modifier = 0;
@@ -247,10 +250,10 @@ class TimeFormatter {
                    outputYear(wallTime.getYear(), true, false, modifier);
                    return false;
                case 'c':
                    formatInternal(dateTimeFormat, wallTime, zoneInfo);
                    formatInternal(dateTimeFormat, wallTime, zoneInfoData);
                    return false;
                case 'D':
                    formatInternal("%m/%d/%y", wallTime, zoneInfo);
                    formatInternal("%m/%d/%y", wallTime, zoneInfoData);
                    return false;
                case 'd':
                    numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
@@ -272,7 +275,7 @@ class TimeFormatter {
                            wallTime.getMonthDay());
                    return false;
                case 'F':
                    formatInternal("%Y-%m-%d", wallTime, zoneInfo);
                    formatInternal("%Y-%m-%d", wallTime, zoneInfoData);
                    return false;
                case 'H':
                    numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
@@ -315,21 +318,21 @@ class TimeFormatter {
                            : localeData.amPm[0], FORCE_LOWER_CASE);
                    return false;
                case 'R':
                    formatInternal("%H:%M", wallTime, zoneInfo);
                    formatInternal("%H:%M", wallTime, zoneInfoData);
                    return false;
                case 'r':
                    formatInternal("%I:%M:%S %p", wallTime, zoneInfo);
                    formatInternal("%I:%M:%S %p", wallTime, zoneInfoData);
                    return false;
                case 'S':
                    numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
                            wallTime.getSecond());
                    return false;
                case 's':
                    int timeInSeconds = wallTime.mktime(zoneInfo);
                    int timeInSeconds = wallTime.mktime(zoneInfoData);
                    outputBuilder.append(Integer.toString(timeInSeconds));
                    return false;
                case 'T':
                    formatInternal("%H:%M:%S", wallTime, zoneInfo);
                    formatInternal("%H:%M:%S", wallTime, zoneInfoData);
                    return false;
                case 't':
                    outputBuilder.append('\t');
@@ -383,7 +386,7 @@ class TimeFormatter {
                    return false;
                }
                case 'v':
                    formatInternal("%e-%b-%Y", wallTime, zoneInfo);
                    formatInternal("%e-%b-%Y", wallTime, zoneInfoData);
                    return false;
                case 'W':
                    int n = (wallTime.getYearDay() + DAYSPERWEEK - (
@@ -395,10 +398,10 @@ class TimeFormatter {
                    numberFormatter.format("%d", wallTime.getWeekDay());
                    return false;
                case 'X':
                    formatInternal(timeOnlyFormat, wallTime, zoneInfo);
                    formatInternal(timeOnlyFormat, wallTime, zoneInfoData);
                    return false;
                case 'x':
                    formatInternal(dateOnlyFormat, wallTime, zoneInfo);
                    formatInternal(dateOnlyFormat, wallTime, zoneInfoData);
                    return false;
                case 'y':
                    outputYear(wallTime.getYear(), false, true, modifier);
@@ -411,7 +414,8 @@ class TimeFormatter {
                        return false;
                    }
                    boolean isDst = wallTime.getIsDst() != 0;
                    modifyAndAppend(zoneInfo.getDisplayName(isDst, TimeZone.SHORT), modifier);
                    modifyAndAppend(TimeZone.getTimeZone(zoneInfoData.getID())
                            .getDisplayName(isDst, TimeZone.SHORT), modifier);
                    return false;
                case 'z': {
                    if (wallTime.getIsDst() < 0) {
@@ -432,7 +436,7 @@ class TimeFormatter {
                    return false;
                }
                case '+':
                    formatInternal("%a %b %e %H:%M:%S %Z %Y", wallTime, zoneInfo);
                    formatInternal("%a %b %e %H:%M:%S %Z %Y", wallTime, zoneInfoData);
                    return false;
                case '%':
                    // If conversion char is undefined, behavior is undefined. Print out the
+7 −7
Original line number Diff line number Diff line
@@ -50,14 +50,14 @@ public final class TzDataSetVersion {
     * Returns the major tz data format version supported by this device.
     */
    public static int currentFormatMajorVersion() {
        return libcore.timezone.TzDataSetVersion.currentFormatMajorVersion();
        return com.android.i18n.timezone.TzDataSetVersion.currentFormatMajorVersion();
    }

    /**
     * Returns the minor tz data format version supported by this device.
     */
    public static int currentFormatMinorVersion() {
        return libcore.timezone.TzDataSetVersion.currentFormatMinorVersion();
        return com.android.i18n.timezone.TzDataSetVersion.currentFormatMinorVersion();
    }

    /**
@@ -65,7 +65,7 @@ public final class TzDataSetVersion {
     * with the current system image, and set of active modules.
     */
    public static boolean isCompatibleWithThisDevice(TzDataSetVersion tzDataSetVersion) {
        return libcore.timezone.TzDataSetVersion.isCompatibleWithThisDevice(
        return com.android.i18n.timezone.TzDataSetVersion.isCompatibleWithThisDevice(
                tzDataSetVersion.mDelegate);
    }

@@ -76,8 +76,8 @@ public final class TzDataSetVersion {
    public static TzDataSetVersion read() throws IOException, TzDataSetException {
        try {
            return new TzDataSetVersion(
                    libcore.timezone.TzDataSetVersion.readTimeZoneModuleVersion());
        } catch (libcore.timezone.TzDataSetVersion.TzDataSetException e) {
                    com.android.i18n.timezone.TzDataSetVersion.readTimeZoneModuleVersion());
        } catch (com.android.i18n.timezone.TzDataSetVersion.TzDataSetException e) {
            throw new TzDataSetException(e.getMessage(), e);
        }
    }
@@ -100,9 +100,9 @@ public final class TzDataSetVersion {
    }

    @NonNull
    private final libcore.timezone.TzDataSetVersion mDelegate;
    private final com.android.i18n.timezone.TzDataSetVersion mDelegate;

    private TzDataSetVersion(@NonNull libcore.timezone.TzDataSetVersion delegate) {
    private TzDataSetVersion(@NonNull com.android.i18n.timezone.TzDataSetVersion delegate) {
        mDelegate = Objects.requireNonNull(delegate);
    }

+3 −3
Original line number Diff line number Diff line
@@ -41,16 +41,16 @@ public final class ZoneInfoDb {
    public static ZoneInfoDb getInstance() {
        synchronized (sLock) {
            if (sInstance == null) {
                sInstance = new ZoneInfoDb(libcore.timezone.ZoneInfoDb.getInstance());
                sInstance = new ZoneInfoDb(com.android.i18n.timezone.ZoneInfoDb.getInstance());
            }
        }
        return sInstance;
    }

    @NonNull
    private final libcore.timezone.ZoneInfoDb mDelegate;
    private final com.android.i18n.timezone.ZoneInfoDb mDelegate;

    private ZoneInfoDb(libcore.timezone.ZoneInfoDb delegate) {
    private ZoneInfoDb(com.android.i18n.timezone.ZoneInfoDb delegate) {
        mDelegate = Objects.requireNonNull(delegate);
    }

Loading