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

Commit af6f8e23 authored by vichang's avatar vichang Committed by Gerrit Code Review
Browse files

Merge "Use new package name for ZoneInfo and libcore.timezone"

parents 5079d626 2ea241f6
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;


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


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


import android.util.TimeFormatException;
import android.util.TimeFormatException;


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


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


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


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


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


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


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


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


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


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


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


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


import android.content.res.Resources;
import android.content.res.Resources;


import com.android.i18n.timezone.ZoneInfoData;

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


import java.nio.CharBuffer;
import java.nio.CharBuffer;
import java.time.Instant;
import java.time.Instant;
@@ -94,8 +95,8 @@ class TimeFormatter {
     * incorrect digit localization behavior.
     * incorrect digit localization behavior.
     */
     */
    String formatMillisWithFixedFormat(long timeMillis) {
    String formatMillisWithFixedFormat(long timeMillis) {
        // This method is deliberately not a general purpose replacement for
        // This method is deliberately not a general purpose replacement for format(String,
        // format(String, ZoneInfo.WallTime, ZoneInfo): It hard-codes the pattern used; many of the
        // ZoneInfoData.WallTime, ZoneInfoData): It hard-codes the pattern used; many of the
        // pattern characters supported by Time.format() have unusual behavior which would make
        // 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
        // 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
        // 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.
     * 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 {
        try {
            StringBuilder stringBuilder = new StringBuilder();
            StringBuilder stringBuilder = new StringBuilder();


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


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


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


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


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


    @NonNull
    @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);
        mDelegate = Objects.requireNonNull(delegate);
    }
    }


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


    @NonNull
    @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);
        mDelegate = Objects.requireNonNull(delegate);
    }
    }


Loading