mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
Implement Calendar#getTime
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
b3d4f33522
commit
dcfcd193be
@ -55,6 +55,10 @@ public abstract class Calendar {
|
||||
time = date.getTime();
|
||||
}
|
||||
|
||||
public Date getTime() {
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
public abstract void roll(int field, boolean up);
|
||||
public abstract void add(int field, int amount);
|
||||
|
||||
@ -102,6 +106,23 @@ public abstract class Calendar {
|
||||
parseIntoFields(this.time);
|
||||
}
|
||||
|
||||
public Date getTime() {
|
||||
long days = fields[DAY_OF_MONTH] - 1;
|
||||
long years = fields[YEAR] - EPOCH_LEAP_YEAR;
|
||||
days += years * 365 + years / 4 + 1 - DAYS_TO_EPOCH;
|
||||
for (int month = 0; month < fields[MONTH]; month++) {
|
||||
days += DAYS_IN_MONTH[0][month];
|
||||
}
|
||||
if (fields[MONTH] < 2 && isLeapYear(fields[YEAR])) {
|
||||
days--;
|
||||
}
|
||||
long time = MILLIS_PER_DAY * days
|
||||
+ MILLIS_PER_HOUR * fields[HOUR_OF_DAY]
|
||||
+ MILLIS_PER_MINUTE * fields[MINUTE]
|
||||
+ MILLIS_PER_SECOND * fields[SECOND];
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
private static boolean isLeapYear(int year) {
|
||||
return (year%4 == 0) && (year%100 != 0) || (year%400 == 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user