mpd/src/time/Convert.hxx

45 lines
910 B
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-2-Clause
// Copyright CM4all GmbH
// author: Max Kellermann <mk@cm4all.com>
2018-07-25 08:29:55 +02:00
#ifndef TIME_CONVERT_HXX
#define TIME_CONVERT_HXX
#include <chrono>
/**
* Convert a UTC-based time point to a UTC-based "struct tm".
2019-05-08 16:14:12 +02:00
*
* Throws on error.
2018-07-25 08:29:55 +02:00
*/
struct tm
GmTime(std::chrono::system_clock::time_point tp);
/**
* Convert a UTC-based time point to a local "struct tm".
2019-05-08 16:14:12 +02:00
*
* Throws on error.
2018-07-25 08:29:55 +02:00
*/
struct tm
LocalTime(std::chrono::system_clock::time_point tp);
/**
* Convert a UTC-based "struct tm" to a UTC-based time point.
*/
[[gnu::pure]]
2018-07-25 08:29:55 +02:00
std::chrono::system_clock::time_point
2019-05-08 16:09:27 +02:00
TimeGm(struct tm &tm) noexcept;
2018-07-25 08:29:55 +02:00
/**
* Convert a local "struct tm" to a UTC-based time point.
*/
[[gnu::pure]]
2018-07-25 08:29:55 +02:00
std::chrono::system_clock::time_point
2019-05-08 16:09:27 +02:00
MakeTime(struct tm &tm) noexcept;
2018-07-25 08:29:55 +02:00
[[gnu::pure]]
std::chrono::steady_clock::duration
ToSteadyClockDuration(const struct timeval &tv) noexcept;
2018-07-25 08:29:55 +02:00
#endif