OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
datetime.h File Reference

Header file for date and time functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Y_M_D   0
 Date format: year, month, day.
 
#define M_D_Y   1
 Date format: month, day, year.
 
#define D_M_Y   2
 Date format: day, month, year.
 
#define NO_DATE   -693594
 No date value.
 
#define DATE_STR_SIZE   12
 Size of a date string.
 
#define TIME_STR_SIZE   9
 Size of a time string.
 
#define TIME_STAMP_SIZE   21
 Size of a time stamp string.
 

Typedefs

typedef double DateTime
 Type for storing date and time values.
 

Functions

DateTime datetime_encodeDate (int year, int month, int day)
 Encodes a date values from year, month, and day to a DateTime value.
 
DateTime datetime_encodeTime (int hour, int minute, int second)
 Encodes a time value from hour, minute, and second to a DateTime value.
 
void datetime_decodeDate (DateTime date, int *y, int *m, int *d)
 Decodes a DateTime value to year, month, and day.
 
void datetime_decodeTime (DateTime time, int *h, int *m, int *s)
 Decodes a DateTime value to hour, minute, and second.
 
int datetime_monthOfYear (DateTime date)
 Finds the month of the year for a date.
 
int datetime_dayOfYear (DateTime date)
 Finds the day of the year for a date.
 
int datetime_dayOfWeek (DateTime date)
 Finds the day of the week for a date.
 
int datetime_hourOfDay (DateTime date)
 Finds the hour of the day for a time.
 
int datetime_daysPerMonth (int year, int month)
 Finds the number of days in a month.
 
void datetime_dateToStr (DateTime date, char *s)
 Converts a DateTime value to a string.
 
void datetime_timeToStr (DateTime time, char *s)
 Converts a DateTime value to a string.
 
void datetime_getTimeStamp (int fmt, DateTime aDate, int stampSize, char *timeStamp)
 Converts a DateTime value to a string.
 
int datetime_findMonth (char *s)
 Finds the month of the year for a date.
 
int datetime_strToDate (char *s, DateTime *d)
 Converts a string to a DateTime value.
 
int datetime_strToTime (char *s, DateTime *t)
 Converts a string to a DateTime value.
 
void datetime_setDateFormat (int fmt)
 Sets the date format.
 
DateTime datetime_addSeconds (DateTime date1, double seconds)
 Adds seconds to a DateTime value.
 
DateTime datetime_addDays (DateTime date1, DateTime date2)
 Adds days to a DateTime value.
 
long datetime_timeDiff (DateTime date1, DateTime date2)
 Finds the difference in seconds between two DateTime values.
 

Detailed Description

Header file for date and time functions.

Author
L. Rossman
Date
Created: 2021-11-01
Last updated: 2024-12-30
Version
5.3.0

The DateTime type is used to store date and time values. It is equivalent to a double floating point type.

The integral part of a DateTime value is the number of days that have passed since 12/31/1899. The fractional part of a DateTime value is the fraction of a 24 hour day that has elapsed.

Update History

Build 5.1.011:

  • New getTimeStamp function added.

Macro Definition Documentation

◆ D_M_Y

#define D_M_Y   2

Date format: day, month, year.

◆ DATE_STR_SIZE

#define DATE_STR_SIZE   12

Size of a date string.

◆ M_D_Y

#define M_D_Y   1

Date format: month, day, year.

◆ NO_DATE

#define NO_DATE   -693594

No date value.

◆ TIME_STAMP_SIZE

#define TIME_STAMP_SIZE   21

Size of a time stamp string.

◆ TIME_STR_SIZE

#define TIME_STR_SIZE   9

Size of a time string.

◆ Y_M_D

#define Y_M_D   0

Date format: year, month, day.

Typedef Documentation

◆ DateTime

Type for storing date and time values.

Function Documentation

◆ datetime_addDays()

DateTime datetime_addDays ( DateTime  date1,
DateTime  date2 
)

Adds days to a DateTime value.

Parameters
[in]date1Date value
[in]daysNumber of days to add
Returns
New DateTime value
Here is the call graph for this function:

◆ datetime_addSeconds()

DateTime datetime_addSeconds ( DateTime  date1,
double  seconds 
)

Adds seconds to a DateTime value.

Parameters
[in]date1Date value
[in]secondsNumber of seconds to add
Returns
New DateTime value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_dateToStr()

void datetime_dateToStr ( DateTime  date,
char *  s 
)

Converts a DateTime value to a string.

Parameters
[in]dateDate value
[out]sString to store the date
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_dayOfWeek()

int datetime_dayOfWeek ( DateTime  date)

Finds the day of the week for a date.

Parameters
[in]dateDate value
Returns
Day of week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
Here is the caller graph for this function:

◆ datetime_dayOfYear()

int datetime_dayOfYear ( DateTime  date)

Finds the day of the year for a date.

Parameters
[in]dateDate value
Returns
Day of year
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_daysPerMonth()

int datetime_daysPerMonth ( int  year,
int  month 
)

Finds the number of days in a month.

Parameters
[in]yearYear
[in]monthMonth
Returns
Number of days in the month
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_decodeDate()

void datetime_decodeDate ( DateTime  date,
int *  y,
int *  m,
int *  d 
)

Decodes a DateTime value to year, month, and day.

Parameters
[in]dateDate value
[out]yYear
[out]mMonth
[out]dDay
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_decodeTime()

void datetime_decodeTime ( DateTime  time,
int *  h,
int *  m,
int *  s 
)

Decodes a DateTime value to hour, minute, and second.

Parameters
[in]timeTime value
[out]hHour
[out]mMinute
[out]sSecond
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_encodeDate()

DateTime datetime_encodeDate ( int  year,
int  month,
int  day 
)

Encodes a date values from year, month, and day to a DateTime value.

Parameters
[in]yearYear
[in]monthMonth
[in]dayDay
Returns
DateTime value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_encodeTime()

DateTime datetime_encodeTime ( int  hour,
int  minute,
int  second 
)

Encodes a time value from hour, minute, and second to a DateTime value.

Parameters
[in]hourHour
[in]minuteMinute
[in]secondSecond
Returns
DateTime value
Here is the caller graph for this function:

◆ datetime_findMonth()

int datetime_findMonth ( char *  s)

Finds the month of the year for a date.

Parameters
[in]sString date
Returns
Month of year
Here is the caller graph for this function:

◆ datetime_getTimeStamp()

void datetime_getTimeStamp ( int  fmt,
DateTime  aDate,
int  stampSize,
char *  timeStamp 
)

Converts a DateTime value to a string.

Parameters
[in]dateDate value
[in]timeTime value
[out]sString to store the date and time
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_hourOfDay()

int datetime_hourOfDay ( DateTime  date)

Finds the hour of the day for a time.

Parameters
[in]timeTime value
Returns
Hour of day
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_monthOfYear()

int datetime_monthOfYear ( DateTime  date)

Finds the month of the year for a date.

Parameters
[in]dateDate value
Returns
Month of year
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_setDateFormat()

void datetime_setDateFormat ( int  fmt)

Sets the date format.

Parameters
[in]fmtDate format
Here is the caller graph for this function:

◆ datetime_strToDate()

int datetime_strToDate ( char *  s,
DateTime d 
)

Converts a string to a DateTime value.

Parameters
[in]sString date
[out]dDateTime value
Returns
1 if successful, 0 if not
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_strToTime()

int datetime_strToTime ( char *  s,
DateTime t 
)

Converts a string to a DateTime value.

Parameters
[in]sString time
[out]tDateTime value
Returns
1 if successful, 0 if not
Here is the call graph for this function:
Here is the caller graph for this function:

◆ datetime_timeDiff()

long datetime_timeDiff ( DateTime  date1,
DateTime  date2 
)

Finds the difference in seconds between two DateTime values.

Parameters
[in]date1First date value
[in]date2Second date value
Returns
Number of seconds
Here is the call graph for this function:

◆ datetime_timeToStr()

void datetime_timeToStr ( DateTime  time,
char *  s 
)

Converts a DateTime value to a string.

Parameters
[in]timeTime value
[out]sString to store the time
Here is the call graph for this function:
Here is the caller graph for this function: