Skip to content

Commit

Permalink
Date: slightly better handling of milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed Nov 17, 2024
1 parent 2d499c9 commit b49442a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,16 @@ DateData Date::calc(double t)
}
date.day = yd - month_days[leap][date.month] + 1;

double dt = ((t / 86400.0) - floor(t / 86400.0)) + 5.7e-9;
t += 0.0005;
double dt = ((t / 86400.0) - floor(t / 86400.0));
int h = (int)floor(24 * dt);
int m = (int)floor((24 * dt - h) * 60);
int s = (int)floor(((24 * dt - h) * 60 - m) * 60.0);

date.hours = h;
date.minutes = m;
date.seconds = s;
date.weekDay = ((int)floor(t / 86400.0 + 1e-6) - 3) % 7;
date.weekDay = ((int)floor(t / 86400.0) - 3) % 7;
if (date.weekDay < 0)
date.weekDay += 7;
return date;
Expand Down

0 comments on commit b49442a

Please sign in to comment.