libcommonc++  0.7
TimeSpec Class Reference

A time specification, such as that used by cron servers. More...

#include <TimeSpec.h++>

Public Member Functions

 TimeSpec ()
 Construct a new TimeSpec with all masks empty. More...
 
 TimeSpec (const DateTime &time)
 Construct a new TimeSpec that matches the given date/time. More...
 
 TimeSpec (uint_t hour, uint_t minute)
 Construct a new TimeSpec that matches the given hour and minute, and all possible dates. More...
 
 TimeSpec (uint_t hour, uint_t minute, uint_t month, uint_t day)
 Construct a new TimeSpec that matches the given hour, minute, month and day, and all weekdays. More...
 
 TimeSpec (const String &spec)
 Construct a new TimeSpec from the given String representation. More...
 
virtual ~TimeSpec ()
 Destructor. More...
 
void setSpec (const String &spec)
 Set the specification according to the given String. More...
 
TimeSpecsetMonth (uint_t month)
 Set a month in the TimeSpec. More...
 
TimeSpecsetMonths (uint_t month1, uint_t month2)
 Set a range of months in the TimeSpec. More...
 
TimeSpecclearMonth (uint_t month)
 Clear a month in the TimeSpec. More...
 
TimeSpecclearMonths (uint_t month1, uint_t month2)
 Clear a range of months in the TimeSpec. More...
 
TimeSpecsetAllMonths ()
 Set all of the months in the TimeSpec. More...
 
TimeSpecclearAllMonths ()
 Clear all of the months in the TimeSpec. More...
 
TimeSpecsetDay (uint_t day)
 Set a day in the TimeSpec. More...
 
TimeSpecsetDays (uint_t day1, uint_t day2)
 Set a range of days in the TimeSpec. More...
 
TimeSpecclearDay (uint_t day)
 Clear a day in the TimeSpec. More...
 
TimeSpecclearDays (uint_t day1, uint_t day2)
 Clear a range of days in the TimeSpec. More...
 
TimeSpecsetAllDays ()
 Set all of the days in the TimeSpec. More...
 
TimeSpecclearAllDays ()
 Clear all of the days in the TimeSpec. More...
 
TimeSpecsetDayOfWeek (uint_t dow)
 Set a weekday in the TimeSpec. More...
 
TimeSpecsetDaysOfWeek (uint_t dow1, uint_t dow2)
 Set a range of weekdays in the TimeSpec. More...
 
TimeSpecclearDayOfWeek (uint_t dow)
 Clear a weekday in the TimeSpec. More...
 
TimeSpecclearDaysOfWeek (uint_t dow1, uint_t dow2)
 Clear a range of weekdays in the TimeSpec. More...
 
TimeSpecsetAllDaysOfWeek ()
 Set all of the weekdays in the TimeSpec. More...
 
TimeSpecclearAllDaysOfWeek ()
 Clear all of the weekdays in the TimeSpec. More...
 
TimeSpecsetHour (uint_t hour)
 Set an hour in the TimeSpec. More...
 
TimeSpecsetHours (uint_t hour1, uint_t hour2)
 Set a range of hours in the TimeSpec. More...
 
TimeSpecclearHour (uint_t hour)
 Clear an hour in the TimeSpec. More...
 
TimeSpecclearHours (uint_t hour1, uint_t hour2)
 Clear a range of hours in the TimeSpec. More...
 
TimeSpecsetAllHours ()
 Set all of the hours in the TimeSpec. More...
 
TimeSpecclearAllHours ()
 Clear all of the hours in the TimeSpec. More...
 
TimeSpecsetMinute (uint_t minute)
 Set a minute in the TimeSpec. More...
 
TimeSpecsetMinutes (uint_t minute1, uint_t minute2)
 Set a range of minutes in the TimeSpec. More...
 
TimeSpecclearMinute (uint_t minute)
 Clear a minute in the TimeSpec. More...
 
TimeSpecclearMinutes (uint_t minute1, uint_t minute2)
 Clear a range of minutes in the TimeSpec. More...
 
TimeSpecsetAllMinutes ()
 Set all of the minutes in the TimeSpec. More...
 
TimeSpecclearAllMinutes ()
 Clear all of the minutes in the TimeSpec. More...
 
bool matches (time_s_t time) const
 Test if the TimeSpec matches the given time. More...
 
bool matches (time_ms_t time) const
 Test if the TimeSpec matches the given time. More...
 
bool matches (uint_t month, uint_t day, uint_t weekday, uint_t hour, uint_t minute) const
 Test if the TimeSpec matches the given time. More...
 
String toString () const
 Get a String representation of the TimeSpec. More...
 

Detailed Description

A time specification, such as that used by cron servers.

The TimeSpec can be thought of as an expression for matching against dates/times, down to a one-minute resolution, which is adequate for most automated task scheduling. The TimeSpec maintains a list of bitmasks representing all possible hours of the day, minutes of the hour, days of the week, days of the month, and months of the year. Individual minutes, hours, days, weekdays, and months can be toggled "on" or "off" in the TimeSpec. The TimeSpec can then be compared against a time value; if the hour, minute, day, weekday, and month components of that time correspond to bits that are "on" in the corresponding bitmasks, then the match is successful.

A TimeSpec can be represented in textual form as five tokens separated by spaces; these five tokens correspond to the minute, hour, day, month, and weekday values that are set in the corresponding masks. Each of these tokens may consist of a comma-separated series of wildcards (denoted by an asterisk '*'), single values, or value ranges, the latter being defined as two integers separated by a dash ('-'). For example, the specification:

0 * 1-5,7 * 0

represents a TimeSpec that matches every hour, on the hour, on the first through fifth or the seventh day of any month, but only if it is a Sunday.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ TimeSpec() [1/5]

TimeSpec ( )

Construct a new TimeSpec with all masks empty.

◆ TimeSpec() [2/5]

TimeSpec ( const DateTime time)

Construct a new TimeSpec that matches the given date/time.

◆ TimeSpec() [3/5]

TimeSpec ( uint_t  hour,
uint_t  minute 
)

Construct a new TimeSpec that matches the given hour and minute, and all possible dates.

◆ TimeSpec() [4/5]

TimeSpec ( uint_t  hour,
uint_t  minute,
uint_t  month,
uint_t  day 
)

Construct a new TimeSpec that matches the given hour, minute, month and day, and all weekdays.

◆ TimeSpec() [5/5]

TimeSpec ( const String spec)

Construct a new TimeSpec from the given String representation.

◆ ~TimeSpec()

~TimeSpec ( )
virtual

Destructor.

Member Function Documentation

◆ clearAllDays()

TimeSpec & clearAllDays ( )

Clear all of the days in the TimeSpec.

◆ clearAllDaysOfWeek()

TimeSpec & clearAllDaysOfWeek ( )

Clear all of the weekdays in the TimeSpec.

◆ clearAllHours()

TimeSpec & clearAllHours ( )

Clear all of the hours in the TimeSpec.

◆ clearAllMinutes()

TimeSpec & clearAllMinutes ( )

Clear all of the minutes in the TimeSpec.

◆ clearAllMonths()

TimeSpec & clearAllMonths ( )

Clear all of the months in the TimeSpec.

◆ clearDay()

TimeSpec & clearDay ( uint_t  day)

Clear a day in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
dayThe day, a value from 1 to 31, inclusive.

◆ clearDayOfWeek()

TimeSpec & clearDayOfWeek ( uint_t  dow)

Clear a weekday in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
dowThe weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.

◆ clearDays()

TimeSpec & clearDays ( uint_t  day1,
uint_t  day2 
)

Clear a range of days in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
day1The start day, a value from 1 to 31, inclusive.
day2The end day, a value from 1 to 31, inclusive.

◆ clearDaysOfWeek()

TimeSpec & clearDaysOfWeek ( uint_t  dow1,
uint_t  dow2 
)

Clear a range of weekdays in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
dow1The start weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.
dow2The end weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.

◆ clearHour()

TimeSpec & clearHour ( uint_t  hour)

Clear an hour in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
hourThe hour, a value from 0 to 23, inclusive.

◆ clearHours()

TimeSpec & clearHours ( uint_t  hour1,
uint_t  hour2 
)

Clear a range of hours in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
hour1The start hour, a value from 0 to 23, inclusive.
hour2The end hour, a value from 0 to 23, inclusive.

◆ clearMinute()

TimeSpec & clearMinute ( uint_t  minute)

Clear a minute in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
minuteThe minute, a value from 0 to 59, inclusive.

◆ clearMinutes()

TimeSpec & clearMinutes ( uint_t  minute1,
uint_t  minute2 
)

Clear a range of minutes in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
minute1The start minute, a value from 0 to 59, inclusive.
minute2The end minute, a value from 0 to 59, inclusive.

◆ clearMonth()

TimeSpec & clearMonth ( uint_t  month)

Clear a month in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
monthThe month, a value from 1 to 12, inclusive.

◆ clearMonths()

TimeSpec & clearMonths ( uint_t  month1,
uint_t  month2 
)

Clear a range of months in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
month1The start month, a value from 1 to 12, inclusive.
month2The end month, a value from 1 to 12, inclusive.

◆ matches() [1/3]

bool matches ( time_s_t  time) const

Test if the TimeSpec matches the given time.

Parameters
timeThe time to compare against.
Returns
true if there is a match, false otherwise.

◆ matches() [2/3]

bool matches ( time_ms_t  time) const

Test if the TimeSpec matches the given time.

Parameters
timeThe time to compare against.
Returns
true if there is a match, false otherwise.

◆ matches() [3/3]

bool matches ( uint_t  month,
uint_t  day,
uint_t  weekday,
uint_t  hour,
uint_t  minute 
) const

Test if the TimeSpec matches the given time.

Parameters
monthThe month.
dayThe day.
weekdayThe weekday.
hourThe hour.
minuteThe minute.
Returns
true if there is a match, false otherwise.

◆ setAllDays()

TimeSpec & setAllDays ( )

Set all of the days in the TimeSpec.

◆ setAllDaysOfWeek()

TimeSpec & setAllDaysOfWeek ( )

Set all of the weekdays in the TimeSpec.

◆ setAllHours()

TimeSpec & setAllHours ( )

Set all of the hours in the TimeSpec.

◆ setAllMinutes()

TimeSpec & setAllMinutes ( )

Set all of the minutes in the TimeSpec.

◆ setAllMonths()

TimeSpec & setAllMonths ( )

Set all of the months in the TimeSpec.

◆ setDay()

TimeSpec & setDay ( uint_t  day)

Set a day in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
dayThe day, a value from 1 to 31, inclusive.

◆ setDayOfWeek()

TimeSpec & setDayOfWeek ( uint_t  dow)

Set a weekday in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
dowThe weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.

◆ setDays()

TimeSpec & setDays ( uint_t  day1,
uint_t  day2 
)

Set a range of days in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
day1The start day, a value from 1 to 31, inclusive.
day2The end day, a value from 1 to 31, inclusive.

◆ setDaysOfWeek()

TimeSpec & setDaysOfWeek ( uint_t  dow1,
uint_t  dow2 
)

Set a range of weekdays in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
dow1The start weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.
dow2The end weekday, a value from 0 to 7, inclusive, where both 0 and 7 indicate Sunday, and the remaining values indicate the number of days since Sunday.

◆ setHour()

TimeSpec & setHour ( uint_t  hour)

Set an hour in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
hourThe hour, a value from 0 to 23, inclusive.

◆ setHours()

TimeSpec & setHours ( uint_t  hour1,
uint_t  hour2 
)

Set a range of hours in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
hour1The start hour, a value from 0 to 23, inclusive.
hour2The end hour, a value from 0 to 23, inclusive.

◆ setMinute()

TimeSpec & setMinute ( uint_t  minute)

Set a minute in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
minuteThe minute, a value from 0 to 59, inclusive.

◆ setMinutes()

TimeSpec & setMinutes ( uint_t  minute1,
uint_t  minute2 
)

Set a range of minutes in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
minute1The start minute, a value from 0 to 59, inclusive.
minute2The end minute, a value from 0 to 59, inclusive.

◆ setMonth()

TimeSpec & setMonth ( uint_t  month)

Set a month in the TimeSpec.

If the value is invalid, the TimeSpec is not changed.

Parameters
monthThe month, a value from 1 to 12, inclusive.

◆ setMonths()

TimeSpec & setMonths ( uint_t  month1,
uint_t  month2 
)

Set a range of months in the TimeSpec.

If the range is invalid, the TimeSpec is not changed.

Parameters
month1The start month, a value from 1 to 12, inclusive.
month2The start month, a value from 1 to 12, inclusive.

◆ setSpec()

void setSpec ( const String spec)

Set the specification according to the given String.

◆ toString()

String toString ( ) const

Get a String representation of the TimeSpec.


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