feat: embedded VTIMEZONE parsing, round-trip serialization

This commit is contained in:
Bernardo Magri
2026-07-23 15:39:41 +01:00
committed by Bernardo Magri
parent 725e48569e
commit 673a2c66c9
3 changed files with 311 additions and 25 deletions

View File

@@ -27,6 +27,15 @@ private:
friend class IcsStore;
};
// Embedded VTIMEZONE definition preserved for round-trip serialization.
struct VTimezoneDefinition {
std::string tzid;
// Complete raw content between BEGIN:VTIMEZONE and END:VTIMEZONE (exclusive
// of the framing lines). Empty when the definition was not parsed from a
// source calendar.
std::string raw;
};
struct LoadResult {
std::vector<Event> events;
std::vector<std::string> warnings;
@@ -36,6 +45,9 @@ struct LoadResult {
// Exact bytes that produced this result. Copies share immutable storage and
// can be supplied to save/restore as an optimistic concurrency token.
FileRevision revision;
// Embedded VTIMEZONE definitions from the source calendar, preserved for
// round-trip serialization. Populated only by load().
std::vector<VTimezoneDefinition> vtimezones;
};
class IcsStore {
@@ -49,9 +61,11 @@ public:
// requests durable filesystem flushes. I/O failures before replacement are
// reported as std::runtime_error. If expected is present, the destination
// must still contain the exact bytes represented by that revision.
// Supply vtimezones to preserve embedded timezone definitions.
static FileRevision save(
const std::filesystem::path& path, std::span<const Event> events,
std::optional<FileRevision> expected = std::nullopt);
std::optional<FileRevision> expected = std::nullopt,
std::span<const VTimezoneDefinition> vtimezones = {});
// Restores the exact bytes in <path>.bak without changing the backup.
static FileRevision restore_backup(