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 | Static Public Member Functions | Static Public Attributes | Friends | List of all members
ace_time::LocalTime Class Reference

The time (hour, minute, second) fields representing the time without regards to the day or the time zone. More...

#include <LocalTime.h>

Public Member Functions

 LocalTime ()
 Default constructor does nothing. More...
 
bool isError () const
 Return true if any component is outside the normal time range of 00:00:00 to 23:59:59. 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 month)
 Set the minute. More...
 
uint8_t second () const
 Return the second. More...
 
void second (uint8_t second)
 Set the second. More...
 
acetime_t toSeconds () const
 Return the number of seconds since midnight. More...
 
int8_t compareTo (const LocalTime &that) const
 Compare this LocalTime with that LocalTime, and return (<0, 0, >0) according to whether (this<that, this==that, this>that). More...
 
void printTo (Print &printer) const
 Print LocalTime to 'printer' in ISO 8601 format. More...
 
 LocalTime (const LocalTime &)=default
 
LocalTimeoperator= (const LocalTime &)=default
 

Static Public Member Functions

static LocalTime forComponents (uint8_t hour, uint8_t minute, uint8_t second)
 Factory method using separated date, time, and time zone fields. More...
 
static LocalTime forSeconds (acetime_t seconds)
 Factory method. More...
 
static LocalTime forTimeString (const char *timeString)
 Factory method. More...
 
static LocalTime forError ()
 Factory method that returns an instance which indicates an error condition. More...
 

Static Public Attributes

static const acetime_t kInvalidSeconds = INT32_MIN
 An invalid seconds marker that indicates isError() true. More...
 

Friends

class LocalDateTime
 
class OffsetDateTime
 
bool operator== (const LocalTime &a, const LocalTime &b)
 Return true if two LocalTime objects are equal. More...
 

Detailed Description

The time (hour, minute, second) fields representing the time without regards to the day or the time zone.

The valid range is 00:00:00 to 23:59:59. Trying to create an instance outside of this range causes the isError() method to return true, and toSeconds() returns kInvalidSeconds.

Parts of this class were inspired by the java.time.LocalTime class of Java 8 (https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html).

Definition at line 20 of file LocalTime.h.

Constructor & Destructor Documentation

ace_time::LocalTime::LocalTime ( )
inlineexplicit

Default constructor does nothing.

Definition at line 81 of file LocalTime.h.

Member Function Documentation

int8_t ace_time::LocalTime::compareTo ( const LocalTime that) const
inline

Compare this LocalTime with that LocalTime, and return (<0, 0, >0) according to whether (this<that, this==that, this>that).

The behavior is undefined if isError() is true.

Definition at line 134 of file LocalTime.h.

static LocalTime ace_time::LocalTime::forComponents ( uint8_t  hour,
uint8_t  minute,
uint8_t  second 
)
inlinestatic

Factory method using separated date, time, and time zone fields.

The dayOfWeek will be lazily evaluated. No data validation is performed on the fields on construction, but if any field is out of range, then isError() will return true.

Parameters
hourhour (0-23)
minuteminute (0-59)
secondsecond (0-59), does not support leap seconds

Definition at line 35 of file LocalTime.h.

static LocalTime ace_time::LocalTime::forError ( )
inlinestatic

Factory method that returns an instance which indicates an error condition.

The isError() method will return true.

Definition at line 76 of file LocalTime.h.

static LocalTime ace_time::LocalTime::forSeconds ( acetime_t  seconds)
inlinestatic

Factory method.

Create the various components of the LocalTime from the number of seconds from midnight. If kInvalidSeconds is given, the isError() condition is set to be true. The behavior is undefined if seconds is greater than 86399.

Parameters
secondsnumber of seconds from midnight, (0-86399)

Definition at line 48 of file LocalTime.h.

LocalTime ace_time::LocalTime::forTimeString ( const char *  timeString)
static

Factory method.

Create a LocalTime from the ISO 8601 time string. If the string cannot be parsed, then isError() on the constructed object returns true. However, the data validation on parsing is very weak and the behavior is undefined for most invalid time strings.

Definition at line 22 of file LocalTime.cpp.

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

Return the hour.

Definition at line 99 of file LocalTime.h.

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

Set the hour.

Definition at line 102 of file LocalTime.h.

bool ace_time::LocalTime::isError ( ) const
inline

Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.

We add the exception that 24:00:00 is also considered valid to allow AutoZoneSpecififier to support midnight transitions from the TZ Database.

Definition at line 89 of file LocalTime.h.

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

Return the minute.

Definition at line 105 of file LocalTime.h.

void ace_time::LocalTime::minute ( uint8_t  month)
inline

Set the minute.

Definition at line 108 of file LocalTime.h.

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

Print LocalTime to 'printer' in ISO 8601 format.

Does not implement Printable to avoid memory cost of a vtable pointer.

Definition at line 8 of file LocalTime.cpp.

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

Return the second.

Definition at line 111 of file LocalTime.h.

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

Set the second.

Definition at line 114 of file LocalTime.h.

acetime_t ace_time::LocalTime::toSeconds ( ) const
inline

Return the number of seconds since midnight.

Return kInvalidSeconds if isError() is true.

Definition at line 120 of file LocalTime.h.

Friends And Related Function Documentation

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

Return true if two LocalTime objects are equal.

Definition at line 185 of file LocalTime.h.

Member Data Documentation

const acetime_t ace_time::LocalTime::kInvalidSeconds = INT32_MIN
static

An invalid seconds marker that indicates isError() true.

Definition at line 23 of file LocalTime.h.


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