Alejandro Lara / DS3231
Embed: (wiki syntax)

« Back to documentation index

DateTime Class Reference

Simple general-purpose date/time class (no TZ / DST / leap second handling!). See http://en.wikipedia.org/wiki/Leap_second. More...

#include <RTClib.h>

Public Types

enum  timestampOpt
 

ISO 8601 Timestamp function.

More...

Public Member Functions

 DateTime (uint32_t t=SECONDS_FROM_1970_TO_2000)
 DateTime constructor from unixtime.
 DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour=0, uint8_t min=0, uint8_t sec=0)
 DateTime constructor from Y-M-D H:M:S.
 DateTime (const DateTime &copy)
 DateTime copy constructor using a member initializer list.
 DateTime (const char *date, const char *time)
 A convenient constructor for using "the compiler's time": DateTime now (__DATE__, __TIME__); NOTE: using F() would further reduce the RAM footprint, see below.
char * tostring (char *buffer)
 A convenient constructor for using "the compiler's time": This version will save RAM by using PROGMEM to store it by using the F macro. DateTime now (F(__DATE__), F(__TIME__));.
uint16_t year () const
 Return the year, stored as an offset from 2000.
uint8_t month () const
 Return month.
uint8_t day () const
 Return day.
uint8_t hour () const
 Return hours.
uint8_t minute () const
 Return minutes.
uint8_t second () const
 Return seconds.
uint8_t dayOfTheWeek () const
 Return the day of the week for this object, from 0-6.
long secondstime () const
 32-bit times as seconds since 1/1/2000
uint32_t unixtime (void) const
 32-bit times as seconds since 1/1/1970
string timestamp (timestampOpt opt=TIMESTAMP_FULL)
 ISO 8601 Timestamp.
DateTime operator+ (const TimeSpan &span)
 Add a TimeSpan to the DateTime object.
DateTime operator- (const TimeSpan &span)
 Subtract a TimeSpan from the DateTime object.
TimeSpan operator- (const DateTime &right)
 Subtract one DateTime from another.
bool operator< (const DateTime &right) const
 Is one DateTime object less than (older) than the other?
bool operator> (const DateTime &right) const
 Test if one DateTime is greater (later) than another.
bool operator<= (const DateTime &right) const
 Test if one DateTime is less (earlier) than or equal to another.
bool operator>= (const DateTime &right) const
 Test if one DateTime is greater (later) than or equal to another.
bool operator== (const DateTime &right) const
 Is one DateTime object equal to the other?
bool operator!= (const DateTime &right) const
 Test if two DateTime objects not equal.

Protected Attributes

uint8_t yOff
 Year offset from 2000.
uint8_t m
 Month 1-12.
uint8_t d
 Day 1-31.
uint8_t hh
 Hours 0-23.
uint8_t mm
 Minutes 0-59.
uint8_t ss
 Seconds 0-59.

Detailed Description

Simple general-purpose date/time class (no TZ / DST / leap second handling!). See http://en.wikipedia.org/wiki/Leap_second.

Definition at line 62 of file RTClib.h.


Member Enumeration Documentation

ISO 8601 Timestamp function.

Definition at line 131 of file RTClib.h.


Constructor & Destructor Documentation

DateTime ( uint32_t  t = SECONDS_FROM_1970_TO_2000 )

DateTime constructor from unixtime.

Parameters:
tInitial time in seconds since Jan 1, 1970 (Unix time)

Definition at line 141 of file RTClib.cpp.

DateTime ( uint16_t  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour = 0,
uint8_t  min = 0,
uint8_t  sec = 0 
)

DateTime constructor from Y-M-D H:M:S.

Parameters:
yearYear, 2 or 4 digits (year 2000 or higher)
monthMonth 1-12
dayDay 1-31
hour0-23
min0-59
sec0-59

Definition at line 180 of file RTClib.cpp.

DateTime ( const DateTime copy )

DateTime copy constructor using a member initializer list.

Parameters:
copyDateTime object to copy

Definition at line 198 of file RTClib.cpp.

DateTime ( const char *  date,
const char *  time 
)

A convenient constructor for using "the compiler's time": DateTime now (__DATE__, __TIME__); NOTE: using F() would further reduce the RAM footprint, see below.

Parameters:
dateDate string, e.g. "Dec 26 2009"
timeTime string, e.g. "12:34:56"

Definition at line 230 of file RTClib.cpp.


Member Function Documentation

uint8_t day (  ) const

Return day.

Returns:
uint8_t day

Definition at line 93 of file RTClib.h.

uint8_t dayOfTheWeek (  ) const

Return the day of the week for this object, from 0-6.

Returns:
Day of week 0-6 starting with Sunday, e.g. Sunday = 0, Saturday = 6

Definition at line 366 of file RTClib.cpp.

uint8_t hour (  ) const

Return hours.

Returns:
uint8_t hours

Definition at line 101 of file RTClib.h.

uint8_t minute (  ) const

Return minutes.

Returns:
uint8_t minutes

Definition at line 109 of file RTClib.h.

uint8_t month (  ) const

Return month.

Returns:
uint8_t month

Definition at line 85 of file RTClib.h.

bool operator!= ( const DateTime right ) const

Test if two DateTime objects not equal.

Parameters:
rightDateTime object to compare
Returns:
True if the two objects are not equal, false if they are

Definition at line 175 of file RTClib.h.

DateTime operator+ ( const TimeSpan span )

Add a TimeSpan to the DateTime object.

Parameters:
spanTimeSpan object
Returns:
new DateTime object with span added to it

Definition at line 409 of file RTClib.cpp.

DateTime operator- ( const TimeSpan span )

Subtract a TimeSpan from the DateTime object.

Parameters:
spanTimeSpan object
Returns:
new DateTime object with span subtracted from it

Definition at line 421 of file RTClib.cpp.

TimeSpan operator- ( const DateTime right )

Subtract one DateTime from another.

Parameters:
rightThe DateTime object to subtract from self (the left object)
Returns:
TimeSpan of the difference between DateTimes

Definition at line 433 of file RTClib.cpp.

bool operator< ( const DateTime right ) const

Is one DateTime object less than (older) than the other?

Parameters:
rightComparison DateTime object
Returns:
True if the left object is older than the right object

Definition at line 445 of file RTClib.cpp.

bool operator<= ( const DateTime right ) const

Test if one DateTime is less (earlier) than or equal to another.

Parameters:
rightDateTime object to compare
Returns:
True if the left object is less than or equal to the right object, false otherwise

Definition at line 156 of file RTClib.h.

bool operator== ( const DateTime right ) const

Is one DateTime object equal to the other?

Parameters:
rightComparison DateTime object
Returns:
True if both DateTime objects are the same

Definition at line 457 of file RTClib.cpp.

bool operator> ( const DateTime right ) const

Test if one DateTime is greater (later) than another.

Parameters:
rightDateTime object to compare
Returns:
True if the left object is greater than the right object, false otherwise

Definition at line 147 of file RTClib.h.

bool operator>= ( const DateTime right ) const

Test if one DateTime is greater (later) than or equal to another.

Parameters:
rightDateTime object to compare
Returns:
True if the left object is greater than or equal to the right object, false otherwise

Definition at line 165 of file RTClib.h.

uint8_t second (  ) const

Return seconds.

Returns:
uint8_t seconds

Definition at line 117 of file RTClib.h.

long secondstime ( void   ) const

32-bit times as seconds since 1/1/2000

Convert the DateTime to seconds.

Returns:
The object as seconds since 2000-01-01

Definition at line 394 of file RTClib.cpp.

string timestamp ( timestampOpt  opt = TIMESTAMP_FULL )

ISO 8601 Timestamp.

Parameters:
optFormat of the timestamp
Returns:
Timestamp string, e.g. "2000-01-01T12:34:56"

Definition at line 469 of file RTClib.cpp.

char * tostring ( char *  buffer )

A convenient constructor for using "the compiler's time": This version will save RAM by using PROGMEM to store it by using the F macro. DateTime now (F(__DATE__), F(__TIME__));.

Parameters:
dateDate string, e.g. "Dec 26 2009"
timeTime string, e.g. "12:34:56"

Return DateTime in based on user defined format.

Parameters:
buffer,:array of char for holding the format description and the formatted DateTime. Before calling this method, the buffer should be initialized by the user with a format string, e.g. "YYYY-MM-DD hh:mm:ss". The method will overwrite the buffer with the formatted date and/or time.
Returns:
a pointer to the provided buffer. This is returned for convenience, in order to enable idioms such as Serial.println(now.tostring(buffer));

Definition at line 311 of file RTClib.cpp.

uint32_t unixtime ( void   ) const

32-bit times as seconds since 1/1/1970

Return unix time, seconds since Jan 1, 1970.

Returns:
Number of seconds since Jan 1, 1970

Definition at line 378 of file RTClib.cpp.

uint16_t year (  ) const

Return the year, stored as an offset from 2000.

Returns:
uint16_t year

Definition at line 77 of file RTClib.h.


Field Documentation

uint8_t d [protected]

Day 1-31.

Definition at line 183 of file RTClib.h.

uint8_t hh [protected]

Hours 0-23.

Definition at line 184 of file RTClib.h.

uint8_t m [protected]

Month 1-12.

Definition at line 182 of file RTClib.h.

uint8_t mm [protected]

Minutes 0-59.

Definition at line 185 of file RTClib.h.

uint8_t ss [protected]

Seconds 0-59.

Definition at line 186 of file RTClib.h.

uint8_t yOff [protected]

Year offset from 2000.

Definition at line 181 of file RTClib.h.