|
From: <ls...@us...> - 2008-08-23 09:33:55
|
Revision: 4484
http://jnode.svn.sourceforge.net/jnode/?rev=4484&view=rev
Author: lsantha
Date: 2008-08-23 09:33:49 +0000 (Sat, 23 Aug 2008)
Log Message:
-----------
Moved time2millis from RTC to TimeUtils for wider reusability.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/util/TimeUtils.java
trunk/core/src/driver/org/jnode/driver/system/cmos/def/RTC.java
Modified: trunk/core/src/core/org/jnode/util/TimeUtils.java
===================================================================
--- trunk/core/src/core/org/jnode/util/TimeUtils.java 2008-08-22 20:12:44 UTC (rev 4483)
+++ trunk/core/src/core/org/jnode/util/TimeUtils.java 2008-08-23 09:33:49 UTC (rev 4484)
@@ -57,4 +57,29 @@
}
}
}
+
+ /**
+ * Converts Gregorian date to milliseconds since 1970-01-01 00:00:00 .
+ *
+ * @param year the year
+ * @param mon the month 1..12
+ * @param day the day of month 1..31
+ * @param hours hours of day 0..23
+ * @param mins minutes 0..59
+ * @param secs seconds 0..59
+ * @return the milliseconds since 1970-01-01 00:00:00
+ */
+ public static long time2millis(int year, int mon, int day, int hours, int mins, int secs) {
+ if (0 >= (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
+ mon += 12; /* Puts Feb last since it has leap day */
+ year -= 1;
+ }
+
+ return ((((
+ ((long) (year / 4 - year / 100 + year / 400 + 367 * mon / 12 + day) + year * 365 - 719499)) /* days */
+ * 24l + hours) /* hours */
+ * 60l + mins) /* minutes */
+ * 60l + secs) /* seconds */
+ * 1000l; /* milliseconds */
+ }
}
Modified: trunk/core/src/driver/org/jnode/driver/system/cmos/def/RTC.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/system/cmos/def/RTC.java 2008-08-22 20:12:44 UTC (rev 4483)
+++ trunk/core/src/driver/org/jnode/driver/system/cmos/def/RTC.java 2008-08-23 09:33:49 UTC (rev 4484)
@@ -24,6 +24,7 @@
import org.jnode.driver.system.cmos.CMOSConstants;
import org.jnode.driver.system.cmos.CMOSService;
import org.jnode.util.BCDUtils;
+import org.jnode.util.TimeUtils;
import org.jnode.vm.RTCService;
/**
@@ -146,31 +147,6 @@
* @see java.util.Calendar#setTimeInMillis(long)
*/
public long getTime() {
- return time2millis(getYear(), getMonth(), getDay(), getHours(), getMinutes(), getSeconds());
+ return TimeUtils.time2millis(getYear(), getMonth(), getDay(), getHours(), getMinutes(), getSeconds());
}
-
- /**
- * Converts Gregorian date to milliseconds since 1970-01-01 00:00:00 .
- *
- * @param year the year
- * @param mon the month 1..12
- * @param day the day of month 1..31
- * @param hours hours of day 0..23
- * @param mins minutes 0..59
- * @param secs seconds 0..59
- * @return the milliseconds since 1970-01-01 00:00:00
- */
- static long time2millis(int year, int mon, int day, int hours, int mins, int secs) {
- if (0 >= (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
- mon += 12; /* Puts Feb last since it has leap day */
- year -= 1;
- }
-
- return ((((
- ((long) (year / 4 - year / 100 + year / 400 + 367 * mon / 12 + day) + year * 365 - 719499)) /* days */
- * 24l + hours) /* hours */
- * 60l + mins) /* minutes */
- * 60l + secs) /* seconds */
- * 1000l; /* milliseconds */
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|