MCP7940  v1.2.0
Arduino Library for the MCP7940N and MCP7940M Real-time clocks
DateTime Class Reference

Simple general-purpose date/time class. More...

Public Member Functions

 DateTime (uint32_t t=SECS_1970_TO_2000)
 
 DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour=0, uint8_t min=0, uint8_t sec=0)
 
 DateTime (const DateTime &copy)
 
 DateTime (const char *date, const char *time)
 
 DateTime (const __FlashStringHelper *date, const __FlashStringHelper *time)
 
uint16_t year () const
 
uint8_t month () const
 
uint8_t day () const
 
uint8_t hour () const
 
uint8_t minute () const
 
uint8_t second () const
 
uint8_t dayOfTheWeek () const
 
long secondstime () const
 
uint32_t unixtime (void) const
 
bool equals (const DateTime *other)
 
DateTime operator+ (const TimeSpan &span)
 
DateTime operator- (const TimeSpan &span)
 
TimeSpan operator- (const DateTime &right)
 

Protected Attributes

uint8_t yOff
 Internal year offset value. More...
 
uint8_t m
 Internal month value.
 
uint8_t d
 Internal day value.
 
uint8_t hh
 Internal hour value.
 
uint8_t mm
 Internal minute value.
 
uint8_t ss
 Internal seconds.
 

Detailed Description

Simple general-purpose date/time class.

Copied from RTClib. For further information on this implementation see https://github.com/Zanduino/MCP7940/wiki/DateTimeClass

Constructor & Destructor Documentation

◆ DateTime() [1/5]

DateTime::DateTime ( uint32_t  t = SECS_1970_TO_2000)

DateTime constructor (overloaded)

Class Constructor for DateTime instantiates the class. This is an overloaded class constructor so there are multiple definitions. This implementation ignores time zones and DST changes. It also ignores leap seconds, see http://en.wikipedia.org/wiki/Leap_second

Parameters
[in]tseconds since the year 1970 (UNIX timet)

◆ DateTime() [2/5]

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

DateTime constructor (overloaded)

Class Constructor for DateTime instantiates the class. This is an overloaded class constructor so there are multiple definitions. This implementation sets each component of the date/time separately

Parameters
[in]yearYear
[in]monthMonth
[in]dayDay
[in]hourHour
[in]minMinute
[in]secSecond

◆ DateTime() [3/5]

DateTime::DateTime ( const DateTime copy)

DateTime constructor (overloaded)

Class Constructor for DateTime instantiates the class. This is an overloaded class constructor so there are multiple definitions. This implementation take a DateTime class value as the defining value

Parameters
[in]copyDateTime class

◆ DateTime() [4/5]

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

DateTime constructor (overloaded)

Class Constructor for DateTime instantiates the class. This is an overloaded class constructor so there are multiple definitions. This implementation uses a Date string formatted as "MMM DD YYYY" and a time string formatted as "hh:mm:ss" for the value

Parameters
[in]datePointer to date string
[in]timePointer to time string

◆ DateTime() [5/5]

DateTime::DateTime ( const __FlashStringHelper *  date,
const __FlashStringHelper *  time 
)

DateTime constructor (overloaded)

Class Constructor for DateTime instantiates the class. This is an overloaded class constructor so there are multiple definitions. This implementation uses the compile date and time as the value to set. It only works when the compiler runs in English. This implementation uses a Date string formatted as "MMM DD YYYY" and a time string formatted as "hh:mm:ss" for the value

Parameters
[in]datePointer to date string
[in]timePointer to time string

Member Function Documentation

◆ day()

uint8_t DateTime::day ( ) const
inline

return the current day of the month

◆ dayOfTheWeek()

uint8_t DateTime::dayOfTheWeek ( ) const

return the current day-of-week where Monday is day 1, Sunday is 7

Returns
integer day-of-week 1-7

◆ equals()

bool DateTime::equals ( const DateTime other)

return the current Unixtime

added equals method for class DateTime

Returns
true if date and time are equal else return false

◆ hour()

uint8_t DateTime::hour ( ) const
inline

return the current hour

◆ minute()

uint8_t DateTime::minute ( ) const
inline

return the current minute

◆ month()

uint8_t DateTime::month ( ) const
inline

return the current month

◆ operator+()

DateTime DateTime::operator+ ( const TimeSpan span)

return true if two datetimes hold the same value

overloaded "+" operator for class DateTime

Returns
Sum of two DateTime class instances

◆ operator-() [1/2]

DateTime DateTime::operator- ( const TimeSpan span)

Overloaded "+" operator to add two timespans

overloaded "+" operator for class DateTime

Returns
Sum of DateTime class and TimeSpan

◆ operator-() [2/2]

TimeSpan DateTime::operator- ( const DateTime right)

Overloaded "+" operator to add two timespans

overloaded "-" operator for class DateTime

Returns
Difference of two DateTime class instances

◆ second()

uint8_t DateTime::second ( ) const
inline

return the current second

◆ secondstime()

long DateTime::secondstime ( void  ) const

return the current day of the week starting at 0

return the time in seconds since the year 2000

Returns
number of seconds since 2000-01-01 00:00:00

◆ unixtime()

uint32_t DateTime::unixtime ( void  ) const

return the current seconds in the year

return the UNIX time, which is seconds since 1970-01-01 00:00:00

Returns
number of seconds since 1970-01-01 00:00:00 (Unixtime)

◆ year()

uint16_t DateTime::year ( ) const
inline

return the current year

Member Data Documentation

◆ yOff

uint8_t DateTime::yOff
protected

Internal year offset value.

Overloaded "-" operator subtract add two timespans


The documentation for this class was generated from the following files: