Repos
C++
749 B22 lines Opens in site
Directory
Raw
Download
#pragma once
// Spec: SPEC.md FR-MOD-02 (ISO8601 with optional fractional seconds).
#include <chrono>
#include <optional>
#include <string>
namespace dp {
using Date = std::chrono::system_clock::time_point;
class DateCodec {
public:
// "2026-11-29T08:00:00Z", "2026-11-29T08:00:00.123456Z", with +hh:mm / -hh:mm offsets.
static std::optional<Date> parseIso8601(const std::string& text);
// Swift `.formatted(.iso8601)`: "2026-11-29T08:00:00Z" (UTC, no fraction).
static std::string formatIso8601(Date date);
// yyyy-MM-dd in UTC-free civil terms from y/m/d components.
static std::string formatBirthDate(int year, unsigned month, unsigned day);
static Date now() { return std::chrono::system_clock::now(); }
};
} // namespace dp