LocalTimeRK
Public Member Functions | Data Fields
LocalTimeRange Class Reference

Class to hold a time range in local time in HH:MM:SS format. More...

#include <LocalTimeRK.h>

Inheritance diagram for LocalTimeRange:
LocalTimeRestrictedDate

Public Member Functions

 LocalTimeRange ()
 Construct a new Time Range object with the range of the entire day (inclusive) More...
 
 LocalTimeRange (LocalTimeHMS hmsStart, LocalTimeHMS hmsEnd=LocalTimeHMS("23:59:59"))
 Construct a new Time Range object with the specifies start and end times. More...
 
 LocalTimeRange (LocalTimeHMS hmsStart, LocalTimeHMS hmsEnd, LocalTimeRestrictedDate dateRestriction)
 Construct a new object that specifies start time, end time, and date restrictions. More...
 
 LocalTimeRange (LocalTimeHMS hmsStart, LocalTimeRestrictedDate dateRestriction)
 Construct a new object that specifies start time and date restrictions, used for at time and date schedules. More...
 
void clear ()
 Clear time range to all day, every day.
 
time_t getTimeSpan (const LocalTimeConvert &conv) const
 Get the number of seconds between start and end based on a LocalTimeConvert object. More...
 
int compareTo (LocalTimeHMS hms) const
 Compares a time (LocalTimeHHS, local time) to this time range. More...
 
bool isValidDate (LocalTimeYMD ymd) const
 Returns true if the date restrictions allow this day. More...
 
bool inRange (LocalTimeValue localTimeValue) const
 Returns true if the date restrictions allow this date and the time is in this range (inclusive) More...
 
LocalTimeYMD getExpirationDate () const
 For restricted time ranges, get the last date (YMD) that this time range could be valid. More...
 
void fromTime (LocalTimeHMSRestricted hms)
 Set the date restrictions from a LocalTimeHMSRestricted object. More...
 
void fromJson (JSONValue jsonObj)
 Fills in the time range from a JSON object. More...
 
- Public Member Functions inherited from LocalTimeRestrictedDate
 LocalTimeRestrictedDate ()
 Create an empty restricted date object. It will return false for any date passed to isValid.
 
 LocalTimeRestrictedDate (uint8_t mask)
 Create a date restricted object restricted to days of the week. More...
 
 LocalTimeRestrictedDate (uint8_t mask, std::initializer_list< const char * > onlyOnDates, std::initializer_list< const char * > exceptDates)
 Construct an object with an initializer list of strings. More...
 
 LocalTimeRestrictedDate (uint8_t mask, std::initializer_list< LocalTimeYMD > onlyOnDates, std::initializer_list< LocalTimeYMD > exceptDates)
 Construct an object with an initializer list of LocalTimeYMD objects. More...
 
LocalTimeRestrictedDatewithOnAllDays ()
 Set the mask value to MASK_ALL. Does not change only on date or except on date lists. More...
 
LocalTimeRestrictedDatewithOnlyOnDays (LocalTimeDayOfWeek value)
 Restrict to days of the week. More...
 
LocalTimeRestrictedDatewithOnlyOnDays (uint8_t mask)
 Restrict to certain dates. More...
 
LocalTimeRestrictedDatewithOnlyOnDates (std::initializer_list< const char * > dates)
 Restrict to certain dates. More...
 
LocalTimeRestrictedDatewithOnlyOnDates (std::initializer_list< LocalTimeYMD > dates)
 Restrict to certain dates. More...
 
LocalTimeRestrictedDatewithExceptDates (std::initializer_list< const char * > dates)
 Dates that will always return false for isValid. More...
 
LocalTimeRestrictedDatewithExceptDates (std::initializer_list< LocalTimeYMD > dates)
 Dates that will always return false for isValid. More...
 
bool isEmpty () const
 Returns true if onlyOnDays mask is 0 and the onlyOnDates and exceptDates lists are empty. More...
 
void clear ()
 Clear all settings.
 
bool isValid (LocalTimeValue localTimeValue) const
 Returns true if a date is in the onlyOnDays or onlyOnDates list, and not in the exceptDates list. More...
 
bool isValid (LocalTimeYMD ymd) const
 Returns true if a date is in the onlyOnDays or onlyOnDates list, and not in the exceptDates list. More...
 
bool inOnlyOnDates (LocalTimeYMD ymd) const
 Returns true of a date is in the onlyOnDates list. More...
 
bool inExceptDates (LocalTimeYMD ymd) const
 Returns true of a date is in the exceptDates list. More...
 
LocalTimeYMD getExpirationDate () const
 Get the last date (YMD) that this restricted date could be valid. More...
 
void fromJson (JSONValue jsonObj)
 Fills in this object from JSON data. More...
 

Data Fields

LocalTimeHMS hmsStart
 Starting time, inclusive.
 
LocalTimeHMS hmsEnd
 Ending time, inclusive.
 
- Data Fields inherited from LocalTimeRestrictedDate
LocalTimeDayOfWeek onlyOnDays
 Allow on that day of week if mask bit is set.
 
std::vector< LocalTimeYMDonlyOnDates
 Dates to allow.
 
std::vector< LocalTimeYMDexceptDates
 Dates to exclude.
 

Detailed Description

Class to hold a time range in local time in HH:MM:SS format.

Constructor & Destructor Documentation

◆ LocalTimeRange() [1/4]

LocalTimeRange::LocalTimeRange ( )
inline

Construct a new Time Range object with the range of the entire day (inclusive)

This is start = 00:00:00, end = 23:59:59. The system clock does not have a concept of leap seconds.

◆ LocalTimeRange() [2/4]

LocalTimeRange::LocalTimeRange ( LocalTimeHMS  hmsStart,
LocalTimeHMS  hmsEnd = LocalTimeHMS("23:59:59") 
)
inline

Construct a new Time Range object with the specifies start and end times.

Parameters
hmsStartStart time in local time 00:00:00 <= hmsStart <= 23:59:59
hmsEndEnd time in local time 00:00:00 <= hmsStart <= 23:59:59 (optional)

Note that 24:00:00 is not a valid time. You should generally use inclusive times such that 23:59:59 is the end of the day.

◆ LocalTimeRange() [3/4]

LocalTimeRange::LocalTimeRange ( LocalTimeHMS  hmsStart,
LocalTimeHMS  hmsEnd,
LocalTimeRestrictedDate  dateRestriction 
)
inline

Construct a new object that specifies start time, end time, and date restrictions.

Parameters
hmsStartStart time in local time 00:00:00 <= hmsStart <= 23:59:59
hmsEndEnd time in local time 00:00:00 <= hmsStart <= 23:59:59
dateRestrictionOnly use this time range on certain dates

◆ LocalTimeRange() [4/4]

LocalTimeRange::LocalTimeRange ( LocalTimeHMS  hmsStart,
LocalTimeRestrictedDate  dateRestriction 
)
inline

Construct a new object that specifies start time and date restrictions, used for at time and date schedules.

Parameters
hmsStartStart time in local time 00:00:00 <= hmsStart <= 23:59:59
hmsEndEnd time in local time 00:00:00 <= hmsStart <= 23:59:59
dateRestrictionOnly use this time range on certain dates

Member Function Documentation

◆ compareTo()

int LocalTimeRange::compareTo ( LocalTimeHMS  hms) const
inline

Compares a time (LocalTimeHHS, local time) to this time range.

Parameters
hms
Returns
int -1 if hms is before hmsStart, 0 if in range, +1 if hms is after hmsEnd

◆ fromJson()

void LocalTimeRange::fromJson ( JSONValue  jsonObj)

Fills in the time range from a JSON object.

Parameters
jsonObj

Keys:

  • s (string) The start time (HH:MM:SS format, can omit MM or SS)
  • e (string) The end time (HH:MM:SS format, can omit MM or SS)

◆ fromTime()

void LocalTimeRange::fromTime ( LocalTimeHMSRestricted  hms)
inline

Set the date restrictions from a LocalTimeHMSRestricted object.

Parameters
hmsLocalTimeHMSRestricted, really only uses the date restrictions, not the HMS part

◆ getExpirationDate()

LocalTimeYMD LocalTimeRange::getExpirationDate ( ) const
inline

For restricted time ranges, get the last date (YMD) that this time range could be valid.

Returns
LocalTimeYMD

This will return the empty date for most cases. A valid value is returned if the LocalTimeRestrictedDate is used, and an only on date is set. In this case, there's as point in time where this range will never be true. This is used to optimize scheduling.

◆ getTimeSpan()

time_t LocalTimeRange::getTimeSpan ( const LocalTimeConvert conv) const

Get the number of seconds between start and end based on a LocalTimeConvert object.

The reason for the conv object is that it contains the time to calculate at, as well as the daylight saving time settings. This methods takes into account the actual number of seconds including when a time change is crossed.

Parameters
convThe time and timezone settings to calculate the time span at
Returns
time_t Time difference in seconds

In the weird case that start > end, it can return a negative value, as time_t is a signed long (or long long) value.

This does not take into account date restrictions!

◆ inRange()

bool LocalTimeRange::inRange ( LocalTimeValue  localTimeValue) const
inline

Returns true if the date restrictions allow this date and the time is in this range (inclusive)

Parameters
localTimeValue
Returns
true
false

◆ isValidDate()

bool LocalTimeRange::isValidDate ( LocalTimeYMD  ymd) const
inline

Returns true if the date restrictions allow this day.

Parameters
ymd
Returns
true
false

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