AceTime  0.5.2
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize 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 forTimeStringChainable (const char *&timeString)
 Variant of forTimeString() that updates the pointer to the next unprocessed character. 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

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 11 (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalTime.html).

Definition at line 26 of file LocalTime.h.

Constructor & Destructor Documentation

◆ LocalTime()

ace_time::LocalTime::LocalTime ( )
inlineexplicit

Default constructor does nothing.

Definition at line 98 of file LocalTime.h.

Member Function Documentation

◆ compareTo()

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 151 of file LocalTime.h.

◆ forComponents()

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 41 of file LocalTime.h.

◆ forError()

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 93 of file LocalTime.h.

◆ forSeconds()

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 54 of file LocalTime.h.

◆ forTimeString()

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 returns LocalTime::forError(). However, the data validation on parsing is very weak and the behavior is undefined for most invalid time strings.

Parameters

Definition at line 27 of file LocalTime.cpp.

◆ forTimeStringChainable()

LocalTime ace_time::LocalTime::forTimeStringChainable ( const char *&  timeString)
static

Variant of forTimeString() that updates the pointer to the next unprocessed character.

This allows chaining to another forXxxStringChainable() method.

This method assumes that the dateString is sufficiently long.

Definition at line 35 of file LocalTime.cpp.

◆ hour() [1/2]

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

Return the hour.

Definition at line 116 of file LocalTime.h.

◆ hour() [2/2]

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

Set the hour.

Definition at line 119 of file LocalTime.h.

◆ isError()

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 106 of file LocalTime.h.

◆ minute() [1/2]

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

Return the minute.

Definition at line 122 of file LocalTime.h.

◆ minute() [2/2]

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

Set the minute.

Definition at line 125 of file LocalTime.h.

◆ printTo()

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

Print LocalTime to 'printer' in ISO 8601 format.

This class does not implement the Printable interface to avoid increasing the size of the object from the additional virtual function.

Definition at line 13 of file LocalTime.cpp.

◆ second() [1/2]

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

Return the second.

Definition at line 128 of file LocalTime.h.

◆ second() [2/2]

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

Set the second.

Definition at line 131 of file LocalTime.h.

◆ toSeconds()

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

Return the number of seconds since midnight.

Return kInvalidSeconds if isError() is true.

Definition at line 137 of file LocalTime.h.

Friends And Related Function Documentation

◆ operator==

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

Return true if two LocalTime objects are equal.

Definition at line 193 of file LocalTime.h.

Member Data Documentation

◆ kInvalidSeconds

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

An invalid seconds marker that indicates isError() true.

Definition at line 29 of file LocalTime.h.


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