OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::datetime Namespace Reference

Typedefs

using DateTime = double
 

Functions

void divMod (int n, int d, int *result, int *remainder)
 Divide integers with the legacy zero-divisor convention.
 
bool isLeapYear (int year)
 Test the proleptic Gregorian leap-year rule.
 
DateTime encodeDate (int year, int month, int day)
 Encode a Gregorian calendar date as midnight in SWMM days.
 
DateTime encodeTime (int hour, int minute, int second)
 Convert nonnegative time components to an elapsed-day fraction.
 
void decodeDate (DateTime date, int &year, int &month, int &day)
 Decode the whole-day part of a SWMM DateTime.
 
void decodeTime (DateTime time, int &h, int &m, int &s)
 Decode a SWMM day fraction to the nearest whole second.
 
DateTime addSeconds (DateTime date, double seconds)
 Add an offset after rounding the input time to whole seconds.
 
long timeDiff (DateTime date1, DateTime date2)
 Subtract two SWMM DateTimes using whole-second decoded times.
 
int monthOfYear (DateTime date)
 Extract the month from a SWMM DateTime.
 
int dayOfYear (DateTime date)
 Extract the ordinal day from a SWMM DateTime.
 

Typedef Documentation

◆ DateTime

Function Documentation

◆ addSeconds()

DateTime openswmm::datetime::addSeconds ( DateTime date,
double seconds )
inline

Add an offset after rounding the input time to whole seconds.

Parameters
[in]dateFinite SWMM DateTime in days relative to 1899-12-30.
[in]secondsFinite seconds to add; negative and fractional offsets are accepted, and the result may cross any number of day boundaries.
Returns
SWMM DateTime containing the rounded input time plus the offset.

Decodes the input using decodeTime(), then recomposes the day and time. The decompose/recompose sequence matches legacy arithmetic; subsecond precision already present in date is not retained.

See also
Legacy datetime_addSeconds() in datetime.c.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dayOfYear()

int openswmm::datetime::dayOfYear ( DateTime date)
inline

Extract the ordinal day from a SWMM DateTime.

Parameters
[in]dateFinite SWMM DateTime for a valid Gregorian date encoded by encodeDate(); the time-of-day does not affect the result.
Returns
One-based day in [1, 365] or [1, 366] for leap years.
Precondition
The date satisfies decodeDate()'s representability requirements.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeDate()

void openswmm::datetime::decodeDate ( DateTime date,
int & year,
int & month,
int & day )
inline

Decode the whole-day part of a SWMM DateTime.

Parameters
[in]dateFinite SWMM days relative to 1899-12-30; fractional days are discarded with floor(), including for dates before the epoch.
[out]yearDecoded Gregorian year; zero for dates before 0001-01-01.
[out]monthOne-based month; 1 for dates before 0001-01-01.
[out]dayOne-based day of month; 1 for dates before 0001-01-01.
Precondition
floor(date) and floor(date) + DateDelta must be representable as int.
See also
Legacy datetime_decodeDate() in datetime.c.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeTime()

void openswmm::datetime::decodeTime ( DateTime time,
int & h,
int & m,
int & s )
inline

Decode a SWMM day fraction to the nearest whole second.

Parameters
[in]timeFinite SWMM DateTime; only time - floor(time) is used.
[out]hHour in [0, 23].
[out]mMinute in [0, 59].
[out]sSecond in [0, 59].

Rounds fractional-day seconds with floor(seconds + 0.5). A value rounding to 86400 is clamped to 86399 rather than carrying into the next date. This matches legacy datetime_decodeTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ divMod()

void openswmm::datetime::divMod ( int n,
int d,
int * result,
int * remainder )
inline

Divide integers with the legacy zero-divisor convention.

Parameters
[in]nDividend; n / d must be representable as int when d is nonzero.
[in]dDivisor; zero requests zero quotient and remainder.
[out]resultNon-null writable quotient, truncated toward zero.
[out]remainderNon-null writable n - d * quotient; zero when d is zero.
Precondition
The two output pointers refer to distinct integers.
Note
Neither pointer is retained.
Here is the caller graph for this function:

◆ encodeDate()

DateTime openswmm::datetime::encodeDate ( int year,
int month,
int day )
inline

Encode a Gregorian calendar date as midnight in SWMM days.

Parameters
[in]yearYear in [1, 9999].
[in]monthMonth in [1, 12].
[in]dayOne-based day valid for the specified month and leap year.
Returns
Integer days relative to 1899-12-30, or -DateDelta for invalid input.
See also
Legacy datetime_encodeDate() in datetime.c.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeTime()

DateTime openswmm::datetime::encodeTime ( int hour,
int minute,
int second )
inline

Convert nonnegative time components to an elapsed-day fraction.

Parameters
[in]hourNonnegative hours; values above 23 are accepted.
[in]minuteNonnegative minutes; values above 59 are accepted.
[in]secondNonnegative seconds; values above 59 are accepted.
Returns
(3600 * hour + 60 * minute + second) / 86400, or zero if any component is negative. The result can exceed one day.
Precondition
The component sum must be representable as int.
See also
Legacy datetime_encodeTime() in datetime.c.
Here is the caller graph for this function:

◆ isLeapYear()

bool openswmm::datetime::isLeapYear ( int year)
inline

Test the proleptic Gregorian leap-year rule.

Parameters
[in]yearCalendar year to test; the arithmetic rule also accepts year zero.
Returns
True for multiples of 4 except centuries not divisible by 400.
Here is the caller graph for this function:

◆ monthOfYear()

int openswmm::datetime::monthOfYear ( DateTime date)
inline

Extract the month from a SWMM DateTime.

Parameters
[in]dateFinite SWMM DateTime for a valid Gregorian date encoded by encodeDate(); the time-of-day does not affect the result.
Returns
One-based Gregorian month in [1, 12].
Precondition
The date satisfies decodeDate()'s representability requirements.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeDiff()

long openswmm::datetime::timeDiff ( DateTime date1,
DateTime date2 )
inline

Subtract two SWMM DateTimes using whole-second decoded times.

Parameters
[in]date1Finite minuend in SWMM days; need not be later than date2.
[in]date2Finite subtrahend in SWMM days.
Returns
Signed date1 - date2 in seconds after independently rounding each time-of-day with decodeTime(). Negative values indicate date1 < date2.
Precondition
The whole-day difference in seconds and final result fit in long.
See also
Legacy datetime_timeDiff() in datetime.c.
Here is the call graph for this function:
Here is the caller graph for this function: