datetime library  v0.60.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

void dt_run (datetime dt)
 Run a date/time second counting process in another cog. Example: datetime dts = {2015, 9, 25, 8, 11, 04}; dt_run(dts);.
void dt_end ()
 Stop a date/time second counting process and recover the cog and lock.
void dt_set (datetime dt)
 Set the system date and time. This can be used to change the system's current date/time. Example datetime mydt={2015, 9, 25, 8, 13, 51}; dt_set(mydt); You can also use this to change the datetime type that was used in dt_start to "set" the second counter that auto-increments.
datetime dt_get ()
 Get the current system time. To find the current system time (as a datetime type), call this function. Note: This assumes that a call to dt_run has been made. This is common near the beginning of a program that uses the system timekeeping.
int dt_getms ()
 Get the number of ms into the current second from the system time second. Notes: This assumes that a call to dt_run has been made. This is common near the beginning of a program that uses the system timekeeping. The current second can be captured with dt_get.
int dt_toEt (datetime dt)
 Get the Unix epoch time (number of seconds from Midnight, 1/1/1970) from a datetime type. This number is a common form of timekeeping for computer systems.
datetime dt_fromEt (int et)
 Get the datetime representation of an a Unix epoch time (number of seconds from Midnight, 1/1/1970).
void dt_toDateStr (datetime dt, char *s)
 Populates a string (minimum 9 characters) with the mm/dd/yy representation of a datetime type's date.
void dt_toTimeStr (datetime dt, char *s)
 Populates a string (minimum 9 characters) with the hh:mm:ss representation of a datetime type's time.
datetime dt_fromDateStr (datetime dt, char *s)
 Populates the y, mo, and d fields in a datetime type with value representations of the characters in a string that contains the date in mm/dd/yy format.
datetime dt_fromTimeStr (datetime dt, char *s)
 Populates the time fields (h, m, and s) in a datetime type with value representations of the characters in a string that contains the time in hh/mm/ss format.

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.6

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

datetime dt_fromDateStr ( datetime  dt,
char *  s 
)

Populates the y, mo, and d fields in a datetime type with value representations of the characters in a string that contains the date in mm/dd/yy format.

Parameters
dtDatetime type. This datetime type may already contain a time that will be unaffected. Only the date (y, mo, d) fields will be changed.
*sString (minimum 9 characters) containing the date in mm/dd/yy format.
Returns
A copy of the datetime type with updated date fields.
datetime dt_fromEt ( int  et)

Get the datetime representation of an a Unix epoch time (number of seconds from Midnight, 1/1/1970).

Parameters
etThe number of seconds that date is from Midnight, 1/1/1970.
Returns
dt A datetime type with the equivalent date and time.
datetime dt_fromTimeStr ( datetime  dt,
char *  s 
)

Populates the time fields (h, m, and s) in a datetime type with value representations of the characters in a string that contains the time in hh/mm/ss format.

Parameters
dtDatetime type. This datetime type may already contain a date that will be unaffected. Only the date (h, m, s) fields will be changed.
*sString (minimum 9 characters) containing the time in hh:mm:ss format.
Returns
A copy of the datetime type with updated time fields.
datetime dt_get ( )

Get the current system time. To find the current system time (as a datetime type), call this function. Note: This assumes that a call to dt_run has been made. This is common near the beginning of a program that uses the system timekeeping.

Returns
The datetime representation of the current system time.
int dt_getms ( )

Get the number of ms into the current second from the system time second. Notes: This assumes that a call to dt_run has been made. This is common near the beginning of a program that uses the system timekeeping. The current second can be captured with dt_get.

Returns
Milliseconds since into the current second. This second .
void dt_run ( datetime  dt)

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

Parameters
dtA datetime structure, pre-set before the call.
void dt_set ( datetime  dt)

Set the system date and time. This can be used to change the system's current date/time. Example datetime mydt={2015, 9, 25, 8, 13, 51}; dt_set(mydt); You can also use this to change the datetime type that was used in dt_start to "set" the second counter that auto-increments.

Parameters
dtA datetime type containing the new date and time.
void dt_toDateStr ( datetime  dt,
char *  s 
)

Populates a string (minimum 9 characters) with the mm/dd/yy representation of a datetime type's date.

Parameters
dtDatetime type containing a valid date.
*sString (minimum 9 characters) address.
int dt_toEt ( datetime  dt)

Get the Unix epoch time (number of seconds from Midnight, 1/1/1970) from a datetime type. This number is a common form of timekeeping for computer systems.

Parameters
dtA datetime type that contains a valid date and time.
Returns
et The number of seconds that date is from Midnight, 1/1/1970.
void dt_toTimeStr ( datetime  dt,
char *  s 
)

Populates a string (minimum 9 characters) with the hh:mm:ss representation of a datetime type's time.

Parameters
dtDatetime type containing a valid time.
*sString (minimum 9 characters) address.