summaryrefslogtreecommitdiff
path: root/lib/chronology.cpp
blob: 49f6df2e3066e07d5300b278241a5002aa052ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "chronology.h"

time_t
operator""_time_t(const char * iso, size_t)
{
	struct tm tm {};

	if (const auto end = strptime(iso, "%FT%T", &tm); !end || *end) {
		throw std::invalid_argument("Invalid date");
	}
	return mktime(&tm);
}

std::chrono::seconds
operator""_seconds(const char * iso, size_t)
{
	return std::chrono::seconds(operator""_time_t(iso, 0));
}