sun.util.calendar.ZoneInfo Java Examples

The following examples show how to use sun.util.calendar.ZoneInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocaleResources.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #2
Source File: LocaleResources.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #3
Source File: LocaleResources.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #4
Source File: LocaleResources.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #5
Source File: UTCAliasTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    Map<String,String> map = ZoneInfo.getAliasTable();
    String alias = map.get("UTC");
    if (!alias.equals("Etc/UTC")) {
        throw new RuntimeException("got " + alias + ", expected Etc/UTC");
    }
    TimeZone GMT = TimeZone.getTimeZone("GMT");
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    if (!GMT.hasSameRules(UTC)) {
        throw new RuntimeException("GMT and UTC have different rules");
    }
    TimeZone EtcUTC = TimeZone.getTimeZone("Etc/UTC");
    if (!UTC.hasSameRules(EtcUTC)) {
        throw new RuntimeException("UTC and Etc/UTC have different rules");
    }
}
 
Example #6
Source File: LocaleResources.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #7
Source File: LocaleResources.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #8
Source File: LocaleResources.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #9
Source File: UTCAliasTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    Map<String,String> map = ZoneInfo.getAliasTable();
    String alias = map.get("UTC");
    if (!alias.equals("Etc/UTC")) {
        throw new RuntimeException("got " + alias + ", expected Etc/UTC");
    }
    TimeZone GMT = TimeZone.getTimeZone("GMT");
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    if (!GMT.hasSameRules(UTC)) {
        throw new RuntimeException("GMT and UTC have different rules");
    }
    TimeZone EtcUTC = TimeZone.getTimeZone("Etc/UTC");
    if (!UTC.hasSameRules(EtcUTC)) {
        throw new RuntimeException("UTC and Etc/UTC have different rules");
    }
}
 
Example #10
Source File: LocaleResources.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #11
Source File: LocaleResources.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
Example #12
Source File: Calendar.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #13
Source File: Calendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #14
Source File: Calendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #15
Source File: Calendar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #16
Source File: Calendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #17
Source File: Calendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #18
Source File: Calendar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #19
Source File: Calendar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #20
Source File: Calendar.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #21
Source File: Calendar.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #22
Source File: Calendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #23
Source File: Calendar.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #24
Source File: Calendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #25
Source File: Calendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #26
Source File: Calendar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #27
Source File: Calendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
Example #28
Source File: Calendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #29
Source File: Calendar.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
Example #30
Source File: Date.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the offset, measured in minutes, for the local time zone
 * relative to UTC that is appropriate for the time represented by
 * this <code>Date</code> object.
 * <p>
 * For example, in Massachusetts, five time zones west of Greenwich:
 * <blockquote><pre>
 * new Date(96, 1, 14).getTimezoneOffset() returns 300</pre></blockquote>
 * because on February 14, 1996, standard time (Eastern Standard Time)
 * is in use, which is offset five hours from UTC; but:
 * <blockquote><pre>
 * new Date(96, 5, 1).getTimezoneOffset() returns 240</pre></blockquote>
 * because on June 1, 1996, daylight saving time (Eastern Daylight Time)
 * is in use, which is offset only four hours from UTC.<p>
 * This method produces the same result as if it computed:
 * <blockquote><pre>
 * (this.getTime() - UTC(this.getYear(),
 *                       this.getMonth(),
 *                       this.getDate(),
 *                       this.getHours(),
 *                       this.getMinutes(),
 *                       this.getSeconds())) / (60 * 1000)
 * </pre></blockquote>
 *
 * @return  the time-zone offset, in minutes, for the current time zone.
 * @see     java.util.Calendar#ZONE_OFFSET
 * @see     java.util.Calendar#DST_OFFSET
 * @see     java.util.TimeZone#getDefault
 * @deprecated As of JDK version 1.1,
 * replaced by <code>-(Calendar.get(Calendar.ZONE_OFFSET) +
 * Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000)</code>.
 */
@Deprecated
public int getTimezoneOffset() {
    int zoneOffset;
    if (cdate == null) {
        TimeZone tz = TimeZone.getDefaultRef();
        if (tz instanceof ZoneInfo) {
            zoneOffset = ((ZoneInfo)tz).getOffsets(fastTime, null);
        } else {
            zoneOffset = tz.getOffset(fastTime);
        }
    } else {
        normalize();
        zoneOffset = cdate.getZoneOffset();
    }
    return -zoneOffset/60000;  // convert to minutes
}