OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches

DateTime utility functions — numerically identical to legacy datetime.c. More...

#include <cmath>
Include dependency graph for DateTime.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  openswmm
 
namespace  openswmm::datetime
 

Typedefs

using openswmm::datetime::DateTime = double
 

Functions

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

Detailed Description

DateTime utility functions — numerically identical to legacy datetime.c.

Uses the OLE Automation Date (OADate) / Delphi TDateTime convention: a double where the integer part is the number of days since December 30, 1899 and the fractional part represents time-of-day.

DateDelta = 693594 is the Gregorian ordinal of 1899-12-30 when 0001-01-01 is ordinal day 1. Subtracting it converts calendar ordinals to the SWMM epoch.

Replicates the exact date/time encoding, decoding, and arithmetic from the legacy SWMM datetime.c including the same integer H:M:S decomposition and the same rounding behavior.

This ensures that operations like datetime_addSeconds() produce bit-identical results to the legacy engine, which is critical for deterministic rain gage interval boundary alignment.

Note
This is NOT an astronomical Julian Date. SWMM uses the OADate convention throughout (matching Delphi's TDateTime type).
See also
Legacy reference: src/legacy/engine/datetime.c
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License
Apache-2.0