HomeWaterLeaksDetection
DateTime.h File Reference
#include "Wire.h"
#include "DS3231.h"
#include "Arduino.h"
#include "Setup.h"
#include <map>
#include <HTMLDataSource.h>

Go to the source code of this file.

Classes

class  DateTime
 

Macros

#define DELTA_TIME(time1, time2)   ((time_t)((time1) - (time2)))
 Calculates the time difference between two times given as parameters. More...
 
#define MILLIS_PER_SEC   1000UL
 number of milliseconds in onc second More...
 
#define SECS_PER_MIN   60UL
 number of seconds in one minute More...
 
#define MINS_PER_HOUR   60UL
 number of minutes in one hour More...
 
#define HOURS_PER_DAY   24UL
 numer of hours in one day More...
 
#define MILLIS_PER_MIN   (MILLIS_PER_SEC * SECS_PER_MIN)
 number of milliseconds in one minute More...
 
#define MILLIS_PER_HOD   (MILLIS_PER_MIN * MINS_PER_HOUR)
 number of milliseconds in one hour More...
 
#define MILLIS_PER_DAY   (MILLIS_PER_HOD * HOURS_PER_DAY)
 number of milliseconds in one day More...
 
#define SEC_TO_MILLIS(s)   ((time_t)(s) * MILLIS_PER_SEC)
 Converts seconds given as a parameter to milliseconds. More...
 
#define MIN_TO_MILLIS(m)   ((time_t)(m) * MILLIS_PER_MIN)
 Converts minutes given as a parameter to milliseconds. More...
 
#define HOD_TO_MILLIS(h)   ((time_t)(h) * MILLIS_PER_HOD)
 Converts hours given as a parameter to milliseconds. More...
 
#define DAY_TO_MILLIS(d)   ((time_t)(d) * MILLIS_PER_DAY)
 Converts days given as a parameter to milliseconds. More...
 
#define MILLIS(time)   ((time) % MILLIS_PER_SEC)
 Calculates the number of milliseconds when formatting the time given in milliseconds. More...
 
#define SECS(time)   (((time) / MILLIS_PER_SEC) % SECS_PER_MIN)
 Calculates the number of seconds when formatting the time given in milliseconds. More...
 
#define MINS(time)   (((time) / MILLIS_PER_MIN) % MINS_PER_HOUR)
 Calculates the number of minutes when formatting the time given in milliseconds. More...
 
#define HOURS(time)   (((time) / MILLIS_PER_HOD) % HOURS_PER_DAY)
 Calculates the number of hours when formatting the time given in milliseconds. More...
 
#define DAYS(time)   ((time) / MILLIS_PER_DAY)
 Calculates the number of days when formatting the time given in milliseconds. More...
 
#define FORMAT_2_DIGITS(x)   ((x) >= 10 ? String(x) : ("0" + String(x)))
 Converts the number given as a parameter into a 2 digit string. More...
 
#define FORMAT_3_DIGITS(x)
 Converts the number given as a parameter into a 3 digit string. More...
 
#define FORMAT_TIME(time)
 Converts a time in milliseconds into a formatted string. More...
 

Typedefs

typedef unsigned long time_t
 Referring to the data type unsigned long as time_t. More...
 

Macro Definition Documentation

◆ DAY_TO_MILLIS

#define DAY_TO_MILLIS (   d)    ((time_t)(d) * MILLIS_PER_DAY)

Converts days given as a parameter to milliseconds.

Parameters
dnumber of days
Returns
time given as a parameter [days] in milliseconds

Definition at line 77 of file DateTime.h.

◆ DAYS

#define DAYS (   time)    ((time) / MILLIS_PER_DAY)

Calculates the number of days when formatting the time given in milliseconds.

Parameters
timein milliseconds
Returns
number of days when converting into format [d:h:m:s:ms]

Definition at line 114 of file DateTime.h.

◆ DELTA_TIME

#define DELTA_TIME (   time1,
  time2 
)    ((time_t)((time1) - (time2)))

Calculates the time difference between two times given as parameters.

Since the data type of both parameters is unsigned long, it is not necessary to check if the result of the operation is negative or not. It is taken care of all automatically by the data type itself. Both parameters are in milliseconds.

Parameters
time1time x
time2time y
Returns
the result of the operation (x-y)[ms]

Definition at line 36 of file DateTime.h.

◆ FORMAT_2_DIGITS

#define FORMAT_2_DIGITS (   x)    ((x) >= 10 ? String(x) : ("0" + String(x)))

Converts the number given as a parameter into a 2 digit string.

For example, number 9 becomes "09".

Parameters
xnumber that is going to be formatted
Returns
formatted string - 2 digits

Definition at line 123 of file DateTime.h.

◆ FORMAT_3_DIGITS

#define FORMAT_3_DIGITS (   x)
Value:
((x) >= 100 ? String(x) : ( \
(x) >= 10 ? ("0" + String(x)) : ("00" + String(x))))

Converts the number given as a parameter into a 3 digit string.

For example, number 9 becomes "009" or number 15 becomes "015".

Parameters
xnumber that is going to be formatted
Returns
formatted string - 3 digits

Definition at line 134 of file DateTime.h.

◆ FORMAT_TIME

#define FORMAT_TIME (   time)
Value:
(String(DAYS(time)) + ":" + \
String(FORMAT_2_DIGITS(HOURS(time))) + ":" + \
String(FORMAT_2_DIGITS(MINS(time))) + ":" + \
String(FORMAT_2_DIGITS(SECS(time))) + ":" + \
String(FORMAT_3_DIGITS(MILLIS(time))) \
)

Converts a time in milliseconds into a formatted string.

The format of the final string is [days:hrs:mins:secs:millis].

Parameters
timein millisecond that is going to be formatted
Returns
formatted string as [d:h:m:s:ms]

Definition at line 142 of file DateTime.h.

◆ HOD_TO_MILLIS

#define HOD_TO_MILLIS (   h)    ((time_t)(h) * MILLIS_PER_HOD)

Converts hours given as a parameter to milliseconds.

Parameters
hnumber of hours
Returns
time given as a parameter [hrs] in milliseconds

Definition at line 72 of file DateTime.h.

◆ HOURS

#define HOURS (   time)    (((time) / MILLIS_PER_HOD) % HOURS_PER_DAY)

Calculates the number of hours when formatting the time given in milliseconds.

Parameters
timein milliseconds
Returns
number of hours when converting into format [d:h:m:s:ms]

Definition at line 107 of file DateTime.h.

◆ HOURS_PER_DAY

#define HOURS_PER_DAY   24UL

numer of hours in one day

Definition at line 48 of file DateTime.h.

◆ MILLIS

#define MILLIS (   time)    ((time) % MILLIS_PER_SEC)

Calculates the number of milliseconds when formatting the time given in milliseconds.

Parameters
timein milliseconds
Returns
number of milliseconds when converting into format [d:h:m:s:ms]

Definition at line 86 of file DateTime.h.

◆ MILLIS_PER_DAY

#define MILLIS_PER_DAY   (MILLIS_PER_HOD * HOURS_PER_DAY)

number of milliseconds in one day

Definition at line 55 of file DateTime.h.

◆ MILLIS_PER_HOD

#define MILLIS_PER_HOD   (MILLIS_PER_MIN * MINS_PER_HOUR)

number of milliseconds in one hour

Definition at line 53 of file DateTime.h.

◆ MILLIS_PER_MIN

#define MILLIS_PER_MIN   (MILLIS_PER_SEC * SECS_PER_MIN)

number of milliseconds in one minute

Definition at line 51 of file DateTime.h.

◆ MILLIS_PER_SEC

#define MILLIS_PER_SEC   1000UL

number of milliseconds in onc second

Definition at line 42 of file DateTime.h.

◆ MIN_TO_MILLIS

#define MIN_TO_MILLIS (   m)    ((time_t)(m) * MILLIS_PER_MIN)

Converts minutes given as a parameter to milliseconds.

Parameters
mnumber of minutes
Returns
time given as a parameter [min] in milliseconds

Definition at line 67 of file DateTime.h.

◆ MINS

#define MINS (   time)    (((time) / MILLIS_PER_MIN) % MINS_PER_HOUR)

Calculates the number of minutes when formatting the time given in milliseconds.

Parameters
timein milliseconds
Returns
number of minutes when converting into format [d:h:m:s:ms]

Definition at line 100 of file DateTime.h.

◆ MINS_PER_HOUR

#define MINS_PER_HOUR   60UL

number of minutes in one hour

Definition at line 46 of file DateTime.h.

◆ SEC_TO_MILLIS

#define SEC_TO_MILLIS (   s)    ((time_t)(s) * MILLIS_PER_SEC)

Converts seconds given as a parameter to milliseconds.

Parameters
snumber of seconds
Returns
time given as a parameter [s] in milliseconds

Definition at line 62 of file DateTime.h.

◆ SECS

#define SECS (   time)    (((time) / MILLIS_PER_SEC) % SECS_PER_MIN)

Calculates the number of seconds when formatting the time given in milliseconds.

Parameters
timein milliseconds
Returns
number of seconds when converting into format [d:h:m:s:ms]

Definition at line 93 of file DateTime.h.

◆ SECS_PER_MIN

#define SECS_PER_MIN   60UL

number of seconds in one minute

Definition at line 44 of file DateTime.h.

Typedef Documentation

◆ time_t

typedef unsigned long time_t

Referring to the data type unsigned long as time_t.

It is used for variables holding time information in milliseconds.

Definition at line 20 of file DateTime.h.

MILLIS
#define MILLIS(time)
Calculates the number of milliseconds when formatting the time given in milliseconds.
Definition: DateTime.h:85
FORMAT_2_DIGITS
#define FORMAT_2_DIGITS(x)
Converts the number given as a parameter into a 2 digit string.
Definition: DateTime.h:122
FORMAT_3_DIGITS
#define FORMAT_3_DIGITS(x)
Converts the number given as a parameter into a 3 digit string.
Definition: DateTime.h:133
DAYS
#define DAYS(time)
Calculates the number of days when formatting the time given in milliseconds.
Definition: DateTime.h:113
SECS
#define SECS(time)
Calculates the number of seconds when formatting the time given in milliseconds.
Definition: DateTime.h:92
MINS
#define MINS(time)
Calculates the number of minutes when formatting the time given in milliseconds.
Definition: DateTime.h:99
HOURS
#define HOURS(time)
Calculates the number of hours when formatting the time given in milliseconds.
Definition: DateTime.h:106