COSA
An Object-Oriented Platform for Arduino Programming
time_t Struct Reference

#include <Time.hh>

Collaboration diagram for time_t:
Collaboration graph

Public Member Functions

void to_binary ()
 
void to_bcd ()
 
 time_t ()
 
 time_t (clock_t c, int8_t zone=0)
 
 operator clock_t () const
 
void set_day ()
 
uint16_t days () const
 
uint16_t day_of_year () const
 
uint16_t full_year () const
 
bool is_leap () const
 
bool is_valid () const
 
bool parse (str_P s)
 

Static Public Member Functions

static uint16_t full_year (uint8_t year)
 
static bool is_leap (uint16_t year)
 
static uint16_t days_per (uint16_t year)
 
static uint8_t weekday_for (uint16_t dayno)
 
static void epoch_year (uint16_t y)
 
static uint16_t epoch_year ()
 
static void use_fastest_epoch ()
 

Public Attributes

uint8_t seconds
 00-59 Seconds. More...
 
uint8_t minutes
 00-59 Minutes. More...
 
uint8_t hours
 00-23 Hours. More...
 
uint8_t day
 01-07 Day. More...
 
uint8_t date
 01-31 Date. More...
 
uint8_t month
 01-12 Month. More...
 
uint8_t year
 00-99 Year. More...
 

Static Public Attributes

static uint8_t epoch_weekday = Y2K_EPOCH_WEEKDAY
 
static uint8_t pivot_year = 0
 
static const uint8_t days_in []
 

Static Protected Attributes

static uint16_t s_epoch_year = Y2K_EPOCH_YEAR
 
static uint8_t epoch_offset = 0
 

Detailed Description

Common date/time structure for real-time clocks. Data on some devices is stored in BCD (DS1307/DS3231), although internal representation is binary. Conversion methods are provided to convert to/from the BCD representation. It is up the caller to keep track of the representation. All time_t methods (except /to_binary/) expect the internal representation to be binary.

Definition at line 102 of file Time.hh.

Constructor & Destructor Documentation

time_t::time_t ( )
inline

Default constructor.

Definition at line 134 of file Time.hh.

time_t::time_t ( clock_t  c,
int8_t  zone = 0 
)

Construct time record from seconds from the Epoch.

Parameters
[in]cclock.
[in]zonetime (hours adjustment from UTC).

Definition at line 85 of file Time.cpp.

Member Function Documentation

uint16_t time_t::day_of_year ( ) const

Calculate day of the current year.

Returns
days from January 1, which is day zero.

Definition at line 151 of file Time.cpp.

uint16_t time_t::days ( ) const

Convert time to days.

Returns
days from January 1 of the epoch year.

Definition at line 140 of file Time.cpp.

static uint16_t time_t::days_per ( uint16_t  year)
inlinestatic

Calculate how many days are in the specified year.

Parameters
[in]year(4-digit).
Returns
number of days.

Definition at line 221 of file Time.hh.

static void time_t::epoch_year ( uint16_t  y)
inlinestatic

Set the epoch year for all time_t operations. Note that the pivot year defaults to the epoch_year % 100. Valid years will be in the range epoch_year..epoch_year+99. Selecting a different pivot year will slide this range to the right.

Parameters
[in]yepoch year to set. See also /full_year/.

Definition at line 262 of file Time.hh.

static uint16_t time_t::epoch_year ( )
inlinestatic

Get the epoch year.

Returns
year.

Definition at line 273 of file Time.hh.

uint16_t time_t::full_year ( ) const
inline

Calculate 4-digit year from internal 2-digit year member.

Returns
4-digit year.

Definition at line 173 of file Time.hh.

static uint16_t time_t::full_year ( uint8_t  year)
inlinestatic

Calculate 4-digit year from a 2-digit year

Parameters
[in]year(4-digit).
Returns
true if /year/ is a leap year.

Definition at line 183 of file Time.hh.

bool time_t::is_leap ( ) const
inline

Determine whether the current year is a leap year.

Returns
true if the two-digit /year/ member is a leap year.

Definition at line 199 of file Time.hh.

static bool time_t::is_leap ( uint16_t  year)
inlinestatic

Determine whether the 4-digit /year/ is a leap year.

Parameters
[in]year(4-digit).
Returns
true if /year/ is a leap year.

Definition at line 209 of file Time.hh.

bool time_t::is_valid ( ) const
inline

Check that all members are set to a coherent date/time.

Returns
true if valid date/time.

Definition at line 240 of file Time.hh.

time_t::operator clock_t ( ) const

Convert time to clock representation.

Returns
seconds from epoch.

Definition at line 127 of file Time.cpp.

bool time_t::parse ( str_P  s)

Parse a character string and fill out members.

Parameters
[in]sprogmem character string with format "YYYY-MM-DD HH:MM:SS".
Returns
success.

Definition at line 40 of file Time.cpp.

void time_t::set_day ( )
inline

Set day member from time record.

Definition at line 152 of file Time.hh.

void time_t::to_bcd ( )
inline

Convert time to BCD representation (from binary). Apply after setting new value and before writing to a BCD device.

Definition at line 125 of file Time.hh.

void time_t::to_binary ( )
inline

Convert time to binary representation (from BCD). Apply after reading from a BCD device and before any calculation.

Definition at line 115 of file Time.hh.

void time_t::use_fastest_epoch ( )
static

Use the current year for the epoch year. This will result in the best performance, but dates/times before January 1 of this year cannot be represented.

Definition at line 164 of file Time.cpp.

static uint8_t time_t::weekday_for ( uint16_t  dayno)
inlinestatic

Determine the day of the week for the specified day number

Parameters
[in]daynumber as counted from January 1 of the epoch year.
Returns
weekday number 1..7, as for the /day/ member.

Definition at line 231 of file Time.hh.

Member Data Documentation

uint8_t time_t::date

01-31 Date.

Definition at line 107 of file Time.hh.

uint8_t time_t::day

01-07 Day.

Definition at line 106 of file Time.hh.

const uint8_t time_t::days_in[]
static

Days by month index 1..12 in program memory vector.

Definition at line 304 of file Time.hh.

uint8_t time_t::epoch_offset = 0
staticprotected

Definition at line 308 of file Time.hh.

uint8_t time_t::epoch_weekday = Y2K_EPOCH_WEEKDAY
static

Definition at line 278 of file Time.hh.

uint8_t time_t::hours

00-23 Hours.

Definition at line 105 of file Time.hh.

uint8_t time_t::minutes

00-59 Minutes.

Definition at line 104 of file Time.hh.

uint8_t time_t::month

01-12 Month.

Definition at line 108 of file Time.hh.

uint8_t time_t::pivot_year = 0
static

The pivot year determine the range of years WRT the epoch_year For example, an epoch year of 2000 and a pivot year of 80 will allow years in the range 1980 to 2079. Default 0 for Y2K_EPOCH.

Definition at line 285 of file Time.hh.

uint16_t time_t::s_epoch_year = Y2K_EPOCH_YEAR
staticprotected

Definition at line 307 of file Time.hh.

uint8_t time_t::seconds

00-59 Seconds.

Definition at line 103 of file Time.hh.

uint8_t time_t::year

00-99 Year.

Definition at line 109 of file Time.hh.


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