You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2006/08/11 08:20:59 UTC
svn commit: r430691 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/util/GregorianCalendar.java
test/java/tests/api/java/util/GregorianCalendarTest.java
Author: hindessm
Date: Thu Aug 10 23:20:58 2006
New Revision: 430691
URL: http://svn.apache.org/viewvc?rev=430691&view=rev
Log:
Applying patch from "[#HARMONY-493] daylight savings parsing problem".
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java?rev=430691&r1=430690&r2=430691&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java Thu Aug 10 23:20:58 2006
@@ -716,8 +716,20 @@
&& timeVal >= gregorianCutover + julianError() * 86400000) {
timeVal -= julianError() * 86400000;
}
- timeVal -= getOffset(timeVal);
- this.time = timeVal;
+
+ // It is not possible to simply subtract getOffset(timeVal) from timeVal to get UTC.
+ // The trick is needed for the moment when DST transition occurs,
+ // say 1:00 is a transition time when DST offset becomes +1 hour,
+ // then wall time in the interval 1:00 - 2:00 is invalid and is
+ // treated as UTC time.
+ long timeValWithoutDST = timeVal - getOffset(timeVal) + getTimeZone().getRawOffset();
+ timeVal -= getOffset(timeValWithoutDST);
+ // Need to update wall time in fields, since it was invalid due to DST transition
+ this.time = timeVal;
+ if (timeValWithoutDST != timeVal) {
+ computeFields();
+ areFieldsSet = true;
+ }
}
private int computeYearAndDay(long dayCount, long localTime) {
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java?rev=430691&r1=430690&r2=430691&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java Thu Aug 10 23:20:58 2006
@@ -587,6 +587,33 @@
}
+ /**
+ * @tests java.util.GregorianCalendar#computeTime()
+ */
+ public void test_computeTime() {
+ // Regression for Harmony-493
+ GregorianCalendar g = new GregorianCalendar(
+ TimeZone.getTimeZone("Europe/London"),
+ new Locale("en", "GB")
+ );
+ g.clear();
+ g.set(2006, 02, 26, 01, 50, 00);
+ assertEquals(1143337800000L, g.getTimeInMillis());
+
+ GregorianCalendar g1 = new GregorianCalendar(
+ TimeZone.getTimeZone("Europe/Moscow")
+ );
+ g1.clear();
+ g1.set(2006, 02, 26, 02, 20, 00); // in the DST transition interval
+ assertEquals(1143328800000L, g1.getTimeInMillis());
+ assertEquals(3, g1.get(Calendar.HOUR_OF_DAY));
+ g1.clear();
+ g1.set(2006, 9, 29, 02, 50, 00); // transition from DST
+ assertEquals(1162079400000L, g1.getTimeInMillis());
+ assertEquals(2, g1.get(Calendar.HOUR_OF_DAY));
+ // End of regression test
+ }
+
/**
* Sets up the fixture, for example, open a network connection. This method
* is called before a test is executed.