43 using base_t::operator=;
45 static constexpr std::string_view kind_id =
"time:sys_seconds";
47 [[nodiscard]] std::string
to_string()
const override {
48 return std::to_string(this->
value.time_since_epoch().count());
61 const auto epoch = base_t::cell_from_json<std::int64_t>(j, kind_id);
62 auto cell = std::make_shared<SystemTimePointCell>(
63 std::chrono::sys_seconds{std::chrono::seconds{epoch}});
70 std::make_shared<SimpleCellTypeDescriptor<SystemTimePointCell>>(
DisplayInfo{
71 .name =
"SystemTimePoint", .description =
"Wall-clock time, second resolution"});
84 :
public BaseCell<UnixMillisCell, std::chrono::sys_time<std::chrono::milliseconds>> {
89 using base_t::operator=;
91 static constexpr std::string_view kind_id =
"time:unix_ms";
93 [[nodiscard]] std::string
to_string()
const override {
94 return std::to_string(this->
value.time_since_epoch().count()) +
"ms";
107 const auto epoch = base_t::cell_from_json<std::int64_t>(j, kind_id);
108 auto cell = std::make_shared<UnixMillisCell>(
109 std::chrono::sys_time<std::chrono::milliseconds>{std::chrono::milliseconds{epoch}});
115 static const auto d =
116 std::make_shared<SimpleCellTypeDescriptor<UnixMillisCell>>(
DisplayInfo{
117 .name =
"UnixMillis", .description =
"Wall-clock time as Unix epoch milliseconds"});
134 using base_t::base_t;
135 using base_t::operator=;
137 static constexpr std::string_view kind_id =
"time:ms";
140 return std::to_string(this->
value.count()) +
"ms";
153 const auto v = base_t::cell_from_json<std::int64_t>(j, kind_id);
154 auto cell = std::make_shared<DurationMsCell>(std::chrono::milliseconds{v});
160 static const auto d = std::make_shared<SimpleCellTypeDescriptor<DurationMsCell>>(
161 DisplayInfo{.name =
"DurationMs", .description =
"Duration in milliseconds"});
175 using base_t::base_t;
176 using base_t::operator=;
178 static constexpr std::string_view kind_id =
"time:ymd";
181 return format_iso(this->
value);
194 const auto s = base_t::cell_from_json<std::string>(j, kind_id);
195 auto cell = std::make_shared<YmdCell>(parse_iso(s));
200 static cell_type_descriptor_t descriptor() {
201 static const auto d = std::make_shared<SimpleCellTypeDescriptor<YmdCell>>(DisplayInfo{
202 .name =
"YearMonthDay", .description =
"Calendar date (ISO-8601 YYYY-MM-DD)"});
207 static std::string format_iso(std::chrono::year_month_day
const& ymd) {
210 const int y =
static_cast<int>(ymd.year());
211 const unsigned m =
static_cast<unsigned>(ymd.month());
212 const unsigned d =
static_cast<unsigned>(ymd.day());
213 const bool neg = y < 0;
214 const auto ay =
static_cast<unsigned>(neg ? -y : y);
220 std::snprintf(buf,
sizeof(buf),
"%s%04u-%02u-%02u", neg ?
"-" :
"", ay, m, d);
225 static std::chrono::year_month_day parse_iso(std::string
const& s) {
227 const std::string_view sv{s};
230 throw InvalidJsonException(
"YmdCell: invalid ISO-8601 date '" + s +
"'",
231 std::string(YmdCell::kind_id));
238 std::size_t first_dash = 4;
239 if (!sv.empty() && sv.front() ==
'-') {
243 if (sv.size() < first_dash + 4 || sv[first_dash] !=
'-') {
247 auto const year_part = sv.substr(0, first_dash);
248 auto const month_part = sv.substr(first_dash + 1, 2);
250 if (sv[first_dash + 3] !=
'-') {
254 auto const day_part = sv.substr(first_dash + 4);
256 auto parse_int = [](
const std::string_view part,
auto& out) {
257 auto const* first = part.data();
258 auto const* last = part.data() + part.size();
259 auto const [ptr, ec] = std::from_chars(first, last, out);
260 return ec == std::errc{} && ptr == last;
263 if (!parse_int(year_part, y) || !parse_int(month_part, m) || !parse_int(day_part, d)) {
267 auto const result = std::chrono::year_month_day{
268 std::chrono::year{y}, std::chrono::month{m}, std::chrono::day{d}};
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICellTypeDescriptor > cell_type_descriptor_t
Shared handle to a runtime cell-type descriptor.
Definition cell.h:63
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
Duration in milliseconds.
Definition chrono.h:130
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition chrono.h:139
json_t to_json() const override
Default JSON serialization for cells with JSON-convertible storage.
Definition chrono.h:143
Runtime catalog of cell-type descriptors, keyed by wire kind id.
Definition registry.h:115
Wall-clock time at second resolution (ISO-8601-friendly).
Definition chrono.h:38
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition chrono.h:47
json_t to_json() const override
Default JSON serialization for cells with JSON-convertible storage.
Definition chrono.h:51
Wall-clock time at millisecond resolution.
Definition chrono.h:84
json_t to_json() const override
Default JSON serialization for cells with JSON-convertible storage.
Definition chrono.h:97
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition chrono.h:93
Calendar date (no time of day).
Definition chrono.h:171
json_t to_json() const override
Default JSON serialization for cells with JSON-convertible storage.
Definition chrono.h:184
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition chrono.h:180
comms::DisplayInfo DisplayInfo
Display info attached to a cell or descriptor — re-exported from comms::DisplayInfo.
Definition common.h:75
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
#define PARCEL_DEFAULT_CELL(CellT)
Register a cell type as the default wrapper for its payload type.
Definition defaults.h:269
auto cell(T &&v)
Wrap a raw value into its default cell, returning a shared_ptr to the cell.
Definition defaults.h:192
Runtime cell-type descriptors and the schema-graph mix-ins (IHasFields, ISubTypes).
nlohmann::json typedef shared across cell types.
nlohmann::json json_t
Project-wide alias for nlohmann::json.
Definition json.h:19
CRTP base providing default to_json / clone / kind plumbing on top of a storage type.
Definition cell.h:343
static void absorb_display_info(json_t const &j, Out &out)
Read "d" (if present) from a JSON object and assign it onto a cell.
Definition cell.h:499
std::chrono::sys_seconds value
Held value of the cell.
Definition cell.h:348
void inject_display_info(json_t &j) const
Copy this cell's display info (if any) into the JSON object under "d".
Definition cell.h:486
static constexpr std::string_view KEY_VALUE
JSON key for the value payload ("v").
Definition cell.h:88
static constexpr std::string_view KEY_KIND
JSON key for the kind id ("k").
Definition cell.h:86