OXYGENHUB
◆ main openmsx / src / utils / Date.hh
763 B · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef DATE_HH
2
#define DATE_HH
3
4
#include <ctime>
5
#include <limits>
6
#include <span>
7
#include <string>
8
#include <string_view>
9
10
namespace openmsx::Date {
11
12
	constexpr time_t INVALID_TIME_T = std::numeric_limits<time_t>::min();
13
14
	// Convert INVALID_TIME_T to a different (close) value.
15
	constexpr time_t adjustTimeT(time_t time) {
16
		return (time == Date::INVALID_TIME_T) ? (Date::INVALID_TIME_T + 1)
17
		                                      : time;
18
	}
19
20
	[[nodiscard]] time_t fromString(std::span<const char, 24> s);
21
22
	[[nodiscard]] std::string toString(time_t time);
23
24
	// Zero-allocation version: formats into buffer, always returns 24-char view.
25
	[[nodiscard]] std::string_view toString(time_t time, std::span<char, 24> buffer);
26
27
} // namespace openmsx::Date
28
29
#endif