-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdate.hpp
More file actions
39 lines (31 loc) · 906 Bytes
/
date.hpp
File metadata and controls
39 lines (31 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <functional>
#include <iostream>
#include "cppcon/common.hpp"
#include "fmt/format.h"
#include "nlohmann/json.hpp"
struct MyDate {
std::uint16_t year;
std::uint16_t month;
std::uint16_t day;
std::string to_string() const;
friend std::ostream& operator<<(std::ostream& os, const MyDate& dt);
serialized_t serialize() const {
std::cout << "serializing date" << std::endl;
return serialized_t();
}
};
void to_json(nlohmann::json& j, const MyDate& p);
template <>
struct fmt::formatter<MyDate> : fmt::formatter<std::string> {
auto format(const MyDate& date, auto& ctx) {
return formatter<std::string>::format(
fmt::format("{}/{}/{}", date.month, date.day, date.year), ctx);
}
};
template <>
struct std::hash<MyDate> {
std::size_t operator()(const MyDate& date) const noexcept {
return std::hash<std::string>{}(date.to_string());
}
};