Solar.fromJulianDay constructor
Solar.fromJulianDay(
- double julianDay
Implementation
Solar.fromJulianDay(double julianDay) {
int d = (julianDay + 0.5).floor();
double f = julianDay + 0.5 - d;
int c;
if (d >= 2299161) {
c = ((d - 1867216.25) / 36524.25).floor();
d += 1 + c - (c * 1.0 / 4).floor();
}
d += 1524;
int year = ((d - 122.1) / 365.25).floor();
d -= (365.25 * year).floor();
int month = (d * 1.0 / 30.601).floor();
d -= (30.601 * month).floor();
int day = d;
if (month > 13) {
month -= 13;
year -= 4715;
} else {
month -= 1;
year -= 4716;
}
f *= 24;
int hour = f.floor();
f -= hour;
f *= 60;
int minute = f.floor();
f -= minute;
f *= 60;
int second = f.round();
if (second > 59) {
second -= 60;
minute++;
}
if (minute > 59) {
minute -= 60;
hour++;
}
if (hour > 23) {
hour -= 24;
day += 1;
}
_year = year;
_month = month;
_day = day;
_hour = hour;
_minute = minute;
_second = second;
}