OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
datetime.c File Reference
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "datetime.h"
Include dependency graph for datetime.c:

Macros

#define _CRT_SECURE_NO_DEPRECATE
 
#define UCHAR(x)   (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
 

Functions

void divMod (int n, int d, int *result, int *remainder)
 
int isLeapYear (int year)
 
int datetime_findMonth (char *month)
 Finds the month of the year for a date.
 
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 *year, int *month, int *day)
 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.
 
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.
 
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.
 
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_getTimeStamp (int fmt, DateTime aDate, int stampSize, char *timeStamp)
 Converts a DateTime value to a string.
 

Macro Definition Documentation

◆ _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_DEPRECATE

◆ UCHAR

#define UCHAR (   x)    (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))

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:

◆ divMod()

void divMod ( int  n,
int  d,
int *  result,
int *  remainder 
)
Here is the caller graph for this function:

◆ isLeapYear()

int isLeapYear ( int  year)
Here is the caller graph for this function: