2023-08-28 12:31:18 +02:00
|
|
|
/* Time related functions.
|
2018-08-22 11:29:39 +02:00
|
|
|
*
|
2023-08-31 11:17:07 +02:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-08-28 12:31:18 +02:00
|
|
|
*/
|
2018-08-22 11:29:39 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-06-23 16:26:44 +02:00
|
|
|
#include <cstdint>
|
2023-09-07 13:19:19 +02:00
|
|
|
#include <cstdio>
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2019-06-23 16:26:44 +02:00
|
|
|
#include <ctime>
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Compare two timestamps. Return zero if they are equal.
|
2018-10-21 20:24:32 +01:00
|
|
|
ssize_t time_cmp(const struct timespec *a, const struct timespec *b);
|
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Get delta between two timespec structs.
|
2023-09-07 13:19:19 +02:00
|
|
|
struct timespec time_diff(const struct timespec *start,
|
|
|
|
const struct timespec *end);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Get sum of two timespec structs.
|
2023-09-07 13:19:19 +02:00
|
|
|
struct timespec time_add(const struct timespec *start,
|
|
|
|
const struct timespec *end);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Return current time as a struct timespec.
|
2018-08-22 11:29:39 +02:00
|
|
|
struct timespec time_now();
|
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Return the diffrence off two timestamps as double value in seconds.
|
2018-08-22 11:29:39 +02:00
|
|
|
double time_delta(const struct timespec *start, const struct timespec *end);
|
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Convert timespec to double value representing seconds.
|
2018-08-22 11:29:39 +02:00
|
|
|
double time_to_double(const struct timespec *ts);
|
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Convert double containing seconds after 1970 to timespec.
|
2018-08-22 11:29:39 +02:00
|
|
|
struct timespec time_from_double(double secs);
|