datetime library  v0.50.0
Collection of convenience functions for timekeeping applications
Data Structures | Macros | Typedefs | Functions
datetime.h File Reference

This library provides convenient functions for a variety of timekeeping operations. Incorporates a manual Spin to C translation of Bob Belleville's date_time_ts.spin for timekeeping. More...

Go to the source code of this file.

Data Structures

struct  datetime_st
 < datetime_st Structure containing y, mo, h, m, s, and etv elements. More...

Macros

#define SECONDS   1
 Constant 1 for 1 second.
#define MINUTES   60
 Constant 60 for seconds in a minute.
#define HOURS   60 * MINUTES
 Constant 3600 for seconds in an hour.
#define DAYS   24 * HOURS
 Constant 86400 for seconds in a day.

Typedefs

typedef struct datetime_st datetime
 < datetime_st Structure containing y, mo, h, m, s, and etv elements.

Functions

int dt_start (datetime *dts)
 Start a date/time second counting process in another cog. Example: datetime dts = {2015, 9, 25, 8, 11, 04}; int cogid = dt_start(&dts);.
void dt_stop ()
 Stop a date/time second counting process and recover the cog and lock.
int dt_set (datetime *dt, int y, int mo, int d, int h, int m, int s)
 set a datetime type. Example datetime mydt; dt_set(&mydt, 2015, 9, 25, 8, 13, 51); You can also use this to change the the datetime type that was used in dt_start to "set" the second counter that auto-increments.
void dt_copy (datetime *dtDest, datetime *dtSrc)
 Copy contents of one time type to another. Example: datetime a = {2015, 9, 25, 8, 24, 45}; datetime b = {2015, 9, 25, 8, 24, 35}; dt_copy(&a, &b); Regardless of what it stored previously, the a time will contain the b time's contents after the call.
int dt_cmpSec (datetime *dtTarget, datetime *dtCmpVal)
 Compare etv second values of two datetime types. Example: datetime a = {2015, 9, 25, 8, 24, 45}; datetime b = {2015, 9, 25, 8, 24, 35}; dt_cmpSec(&a, &b); The result will be 10. Swap arguments, and the result will be -10. Useful for setting alarms and comparing with system time.
void dt_addSec (datetime *dt, int seconds)
 Add a number of seconds to a given datetime type. Example: datetime a = {2001, 1, 1, 0, 0, 0}; dt_addSec(&a, DAYS*1+HOURS*3 +MINUTES*4+SECONDS*5); Result: a == {2001, 1, 2, 3, 4, 5}.

Detailed Description

This library provides convenient functions for a variety of timekeeping operations. Incorporates a manual Spin to C translation of Bob Belleville's date_time_ts.spin for timekeeping.

Author
Parallax Inc.
Version
0.5

Definition in file datetime.h.

Typedef Documentation

typedef struct datetime_st datetime

< datetime_st Structure containing y, mo, h, m, s, and etv elements.

datetime Type definition of datetime_st structure.

Function Documentation

void dt_addSec ( datetime dt,
int  seconds 
)

Add a number of seconds to a given datetime type. Example: datetime a = {2001, 1, 1, 0, 0, 0}; dt_addSec(&a, DAYS*1+HOURS*3 +MINUTES*4+SECONDS*5); Result: a == {2001, 1, 2, 3, 4, 5}.

Parameters
*dtThe daytime type to be modified.
secondsThe number of seconds to add. May be multiplied by convenient values like DAYS, HOURS, MINUTES, or SECONDS.
int dt_cmpSec ( datetime dtTarget,
datetime dtCmpVal 
)

Compare etv second values of two datetime types. Example: datetime a = {2015, 9, 25, 8, 24, 45}; datetime b = {2015, 9, 25, 8, 24, 35}; dt_cmpSec(&a, &b); The result will be 10. Swap arguments, and the result will be -10. Useful for setting alarms and comparing with system time.

Parameters
*dtTargetAddress of target time. The number of seconds corresponding from this date/time that the dtCmpVal second value is subracted from.
*dtCmpValThe number seconds corresponding to this date/time are subtracted from the target value.
Returns
The number of seconds difference: dtTarget - dtCmpVal.
void dt_copy ( datetime dtDest,
datetime dtSrc 
)

Copy contents of one time type to another. Example: datetime a = {2015, 9, 25, 8, 24, 45}; datetime b = {2015, 9, 25, 8, 24, 35}; dt_copy(&a, &b); Regardless of what it stored previously, the a time will contain the b time's contents after the call.

Parameters
*dtDestAddress of destination time receives dtSrc values.
*dtSrcAddress of source time copied to dtDest.
int dt_set ( datetime dt,
int  y,
int  mo,
int  d,
int  h,
int  m,
int  s 
)

set a datetime type. Example datetime mydt; dt_set(&mydt, 2015, 9, 25, 8, 13, 51); You can also use this to change the the datetime type that was used in dt_start to "set" the second counter that auto-increments.

Parameters
*dtAddress of datetime type to be set.
yYear.
moMonth.
dDay.
hHour.
mMinute.
sSecond.
Returns
etv - the epoch time value, which is a number of seconds from an arbitrarily selected beginning time.
int dt_start ( datetime dts)

Start a date/time second counting process in another cog. Example: datetime dts = {2015, 9, 25, 8, 11, 04}; int cogid = dt_start(&dts);.

Parameters
*dtsAddress of a datetime type, preferably pre-set before the call.
Returns
cog+1 if successful, 0 if no cogs, -(cog+1) if no locks.