Merge branch 'master' of dice:git/vm

This commit is contained in:
Joel Dice 2007-10-22 19:23:14 -06:00
commit cb7189c5a7

View File

@ -65,6 +65,9 @@ public abstract class Calendar {
private static final int MILLIS_PER_SECOND = 1000;
private static final int EPOCH_YEAR = 1970;
private static final int EPOCH_LEAP_YEAR = 1968;
private static final int DAYS_TO_EPOCH = 731;
private static final int[][] DAYS_IN_MONTH = new int[][] {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
@ -85,22 +88,22 @@ public abstract class Calendar {
return (year%4 == 0) && (year%100 != 0) || (year%400 == 0);
}
private static int daysInYear(int year) {
return isLeapYear(year) ? 366 : 365;
}
private void parseIntoFields(long timeInMillis) {
long days = timeInMillis / MILLIS_PER_DAY;
int year = EPOCH_YEAR;
while (days >= daysInYear(year)) {
days -= daysInYear(year++);
}
/* convert days since Jan 1, 1970 to days since Jan 1, 1968 */
days += DAYS_TO_EPOCH;
long years = 4 * days / 1461; /* days/365.25 = 4*days/(4*365.25) */
int year = (int)(EPOCH_LEAP_YEAR + years);
days -= 365 * years + years / 4;
if (!isLeapYear(year)) days--;
int month=0;
int leapIndex = isLeapYear(year) ? 1 : 0;
while (days >= DAYS_IN_MONTH[leapIndex][month]) {
days -= DAYS_IN_MONTH[leapIndex][month++];
}
days++;
int remainder = (int)(timeInMillis % MILLIS_PER_DAY);
int hour = remainder / MILLIS_PER_HOUR;
remainder = remainder % MILLIS_PER_HOUR;