src.dualinventive.com/jjacobs/dinetrpcll-sniffer/libdi/include/di/time.h

71 lines
1.7 KiB
C

#ifndef LIBDI_TIME_H_
#define LIBDI_TIME_H_
#ifdef __cplusplus
extern "C" {
#endif
#define DI_TIME_INVALID 0U /**< Invalid time (initialisation value) */
#define DI_TIME_MINIMAL_VALID 1451606400000U /**< 2016-01-01T00:00:00+00:00 in ISO 8601 */
#include <stdint.h>
#include <stdbool.h>
#include <di/types.h>
/**
* Convert date and time to unix timestamp (seconds)
* @param year e.g 2015
* @param month e.g 6
* @param day day of month, e.g 25
* @param hour e.g 16
* @param min minutes e.g 25
* @param sec seconds e.g 56
* When invalid month supplied epoch of 0 is returned.
*/
uint32_t di_time_datetime_to_unix(
uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t min,
uint8_t sec);
/**
* Initialize time and reset local and uptime
* @note MUST only be called once
*/
void di_time_init(void);
/** Reset local and uptime */
void di_time_reset(void);
/** Increment timestamp and uptime with one millisecond */
void di_time_tick(void);
/** Synchronize timestamp milliseconds to zero */
void di_time_tick_pps(void);
/**
* Update local time from UNIX timestamp (seconds)
* @note This function truncates current milliseconds
*/
void di_time_set(uint32_t epoch);
/** Update local time (milliseconds) */
void di_time_set_ms(uint64_t unix_ms);
/** Get current timestamp in milliseconds since UNIX epoch */
di_time_t di_time_get_stamp(void);
/** Check if current timestamp is valid and bigger than DI_TIME_MINIMAL_VALID (e.g synchronized with a timesource) */
bool di_time_is_stamp_valid(void);
/** Get current uptime in milliseconds since UNIX epoch */
di_time_t di_time_get_uptime(void);
#ifdef __cplusplus
}
#endif
#endif /* LIBDI_TIME_H_ */