48#ifndef OPENSWMM_ENGINE_DATETIME_HPP
49#define OPENSWMM_ENGINE_DATETIME_HPP
60static constexpr int DateDelta = 693594;
61static constexpr double SecsPerDay = 86400.0;
62static constexpr double OneSecond = 1.1574074e-5;
83inline void divMod(
int n,
int d,
int* result,
int* remainder) {
89 *remainder = n - d * (*result);
99 return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
111 static constexpr int DaysPerMonth[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
112 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
114 if (year >= 1 && year <= 9999 && month >= 1 && month <= 12 && day >= 1 &&
115 day <= DaysPerMonth[i][month - 1]) {
116 for (
int j = 0; j < month - 1; ++j)
117 day += DaysPerMonth[i][j];
119 return y * 365 +
y / 4 -
y / 100 +
y / 400 + day - DateDelta;
135 if (hour >= 0 && minute >= 0 && second >= 0) {
136 int s = hour * 3600 + minute * 60 + second;
137 return static_cast<double>(s) / SecsPerDay;
153 static constexpr int DaysPerMonth[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
154 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
155 constexpr int D1 = 365, D4 = 1461, D100 = 36524, D400 = 146097;
157 int t =
static_cast<int>(std::floor(date)) + DateDelta;
189 i = DaysPerMonth[k][m - 1];
211 double fracDay = (time - std::floor(time)) * SecsPerDay;
212 int secs =
static_cast<int>(std::floor(fracDay + 0.5));
234 double d = std::floor(date);
237 return d + (3600.0 * h + 60.0 * m + s + seconds) / SecsPerDay;
250 double d1 = std::floor(date1);
251 double d2 = std::floor(date2);
254 long s1 = 3600L * h + 60L * m + s;
256 long s2 = 3600L * h + 60L * m + s;
257 long secs =
static_cast<long>(std::floor((d1 - d2) * SecsPerDay + 0.5));
286 return static_cast<int>(std::floor(date - startOfYear)) + 1;
Definition DateTime.hpp:54
void decodeDate(DateTime date, int &year, int &month, int &day)
Decode the whole-day part of a SWMM DateTime.
Definition DateTime.hpp:152
DateTime encodeTime(int hour, int minute, int second)
Convert nonnegative time components to an elapsed-day fraction.
Definition DateTime.hpp:134
DateTime addSeconds(DateTime date, double seconds)
Add an offset after rounding the input time to whole seconds.
Definition DateTime.hpp:233
double DateTime
Definition DateTime.hpp:68
int monthOfYear(DateTime date)
Extract the month from a SWMM DateTime.
Definition DateTime.hpp:269
bool isLeapYear(int year)
Test the proleptic Gregorian leap-year rule.
Definition DateTime.hpp:98
void divMod(int n, int d, int *result, int *remainder)
Divide integers with the legacy zero-divisor convention.
Definition DateTime.hpp:83
DateTime encodeDate(int year, int month, int day)
Encode a Gregorian calendar date as midnight in SWMM days.
Definition DateTime.hpp:110
long timeDiff(DateTime date1, DateTime date2)
Subtract two SWMM DateTimes using whole-second decoded times.
Definition DateTime.hpp:249
void decodeTime(DateTime time, int &h, int &m, int &s)
Decode a SWMM day fraction to the nearest whole second.
Definition DateTime.hpp:210
int dayOfYear(DateTime date)
Extract the ordinal day from a SWMM DateTime.
Definition DateTime.hpp:282
Definition ExchangeLaw.hpp:60
double * y
Definition odesolve.c:37