AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized from an NTP server or an RTC chip.
Public Member Functions | Friends | List of all members
ace_time::TimePeriod Class Reference

Represents a period of time relative to some known point in time, potentially represented by a DateTime. More...

#include <TimePeriod.h>

Public Member Functions

 TimePeriod (uint8_t hour, uint8_t minute, uint8_t second, int8_t sign=1)
 Constructor. More...
 
 TimePeriod (int32_t seconds=0)
 Constructor from number of seconds. More...
 
uint8_t hour () const
 Return the hour. More...
 
void hour (uint8_t hour)
 Set the hour. More...
 
uint8_t minute () const
 Return the minute. More...
 
void minute (uint8_t minute)
 Set the minute. More...
 
uint8_t second () const
 Return the second. More...
 
void second (uint8_t second)
 Set the second. More...
 
int8_t sign () const
 Return the sign bit. More...
 
void sign (int8_t sign)
 Set the sign bit. More...
 
void printTo (Print &printer) const
 Print to given printer. More...
 
int32_t toSeconds () const
 Convert to number of seconds. More...
 
void negate ()
 Change the sign of the object. More...
 
void incrementHour ()
 Increment the hour component by one, modulo 24. More...
 
void incrementHour (uint8_t limit)
 Increment the hour by one, modulo 'limit'. More...
 
void incrementMinute ()
 Increment the minute by one, modulo 60. More...
 
int8_t compareTo (const TimePeriod &that) const
 Compare this TimePeriod with another TimePeriod and return (<0, 0, >0) according to (a<b, a==b, a>b).
 
 TimePeriod (const TimePeriod &)=default
 
TimePeriodoperator= (const TimePeriod &)=default
 

Friends

bool operator== (const TimePeriod &a, const TimePeriod &b)
 Return true if two TimePeriod objects are equal. More...
 

Detailed Description

Represents a period of time relative to some known point in time, potentially represented by a DateTime.

Each component (hour, minute, second) is stored as an unsigned byte (uint8_t). The sign bit allows forward and backward time periods to be represented.

Definition at line 17 of file TimePeriod.h.

Constructor & Destructor Documentation

ace_time::TimePeriod::TimePeriod ( uint8_t  hour,
uint8_t  minute,
uint8_t  second,
int8_t  sign = 1 
)
inlineexplicit

Constructor.

Parameters
hourhour (0-255)
minuteminute (0-59)
secondsecond (0-59)
signThe sign bit. Should be either +1 or -1, but in practice, anything greater than equal to 0 will be considered to be +1, and anything less than zero will be considered -1.

Definition at line 29 of file TimePeriod.h.

ace_time::TimePeriod::TimePeriod ( int32_t  seconds = 0)
inlineexplicit

Constructor from number of seconds.

The largest valid 'seconds' is +/- 921599 corresponding to (hour=255, minute=59, second=59). For larger numbers, the 'hour' component will be truncated.

Parameters
secondsnumber of seconds (default 0)

Definition at line 43 of file TimePeriod.h.

Member Function Documentation

uint8_t ace_time::TimePeriod::hour ( ) const
inline

Return the hour.

Definition at line 58 of file TimePeriod.h.

void ace_time::TimePeriod::hour ( uint8_t  hour)
inline

Set the hour.

Definition at line 61 of file TimePeriod.h.

void ace_time::TimePeriod::incrementHour ( )
inline

Increment the hour component by one, modulo 24.

Definition at line 107 of file TimePeriod.h.

void ace_time::TimePeriod::incrementHour ( uint8_t  limit)
inline

Increment the hour by one, modulo 'limit'.

Definition at line 112 of file TimePeriod.h.

void ace_time::TimePeriod::incrementMinute ( )
inline

Increment the minute by one, modulo 60.

Definition at line 117 of file TimePeriod.h.

uint8_t ace_time::TimePeriod::minute ( ) const
inline

Return the minute.

Definition at line 64 of file TimePeriod.h.

void ace_time::TimePeriod::minute ( uint8_t  minute)
inline

Set the minute.

Definition at line 67 of file TimePeriod.h.

void ace_time::TimePeriod::negate ( )
inline

Change the sign of the object.

Definition at line 104 of file TimePeriod.h.

void ace_time::TimePeriod::printTo ( Print &  printer) const

Print to given printer.

If the time period is negative, a minus sign is prepended. Does not implement Printable to avoid memory cost of vtable pointer.

Definition at line 8 of file TimePeriod.cpp.

uint8_t ace_time::TimePeriod::second ( ) const
inline

Return the second.

Definition at line 70 of file TimePeriod.h.

void ace_time::TimePeriod::second ( uint8_t  second)
inline

Set the second.

Definition at line 73 of file TimePeriod.h.

int8_t ace_time::TimePeriod::sign ( ) const
inline

Return the sign bit.

Definition at line 76 of file TimePeriod.h.

void ace_time::TimePeriod::sign ( int8_t  sign)
inline

Set the sign bit.

Should be either +1 or -1, but in practice, anything greater than equal to 0 will be considered to be +1, and anything less than zero will be considered -1.

Definition at line 83 of file TimePeriod.h.

int32_t ace_time::TimePeriod::toSeconds ( ) const
inline

Convert to number of seconds.

The largest/smallest possible value returned by this method is +/- 933555, corresponding to (hour=255, minute=255, second=255).

Definition at line 97 of file TimePeriod.h.

Friends And Related Function Documentation

bool operator== ( const TimePeriod a,
const TimePeriod b 
)
friend

Return true if two TimePeriod objects are equal.

Optimized for small changes in the less signficant fields.

Definition at line 162 of file TimePeriod.h.


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