Looking at date time more, I don't think DateTime is a good candidate for serializing because it contains pointers to functions that determine timezone. How do you want to handle the timezones? I would recommend just stocking with unix epoc (seconds from 1970) if you don't want to make your life x100 harder by dealing with timezone sterilization.
I don't usually use DateTime (I use the <https://github.com/treeform/chrono)>, but here is what I got: import times, flatty proc toFlatty(s: var string, x: DateTime) = s.toFlatty(x.toTime.toUnix) proc fromFlatty(s: string, i: var int, x: var DateTime) = var unix: int64 s.fromFlatty(i, unix) x = parse("1970-01-01", "yyyy-MM-dd", utc()) + initTimeInterval(seconds = unix.int) var date = parse("2000-01-01", "yyyy-MM-dd", utc()) echo date echo date.toFlatty().fromFlatty(type(date)) assert date == date.toFlatty().fromFlatty(type(date)) Run
