update: receive Time
This commit is contained in:
parent
5ff94ccf17
commit
c4319f5da3
1 changed files with 11 additions and 0 deletions
|
|
@ -1,4 +1,6 @@
|
|||
const std = @import("std");
|
||||
const time = @import("time.zig");
|
||||
const util = @import("util.zig");
|
||||
|
||||
pub const Value = union(enum) {
|
||||
null,
|
||||
|
|
@ -36,6 +38,10 @@ pub const Context = struct {
|
|||
|
||||
fn toValue(self: *Context, value: anytype) !Value {
|
||||
const T = @TypeOf(value);
|
||||
if (T == time.Time) {
|
||||
return Value{ .string = try time.formatDateTime(self.allocator(), value, "Y-m-d H:i:s") };
|
||||
}
|
||||
|
||||
return switch (@typeInfo(T)) {
|
||||
.bool => Value{ .bool = value },
|
||||
.int, .comptime_int => Value{ .int = @intCast(value) },
|
||||
|
|
@ -109,6 +115,11 @@ pub const Context = struct {
|
|||
return self.get(path) orelse try self.toValue(default);
|
||||
}
|
||||
|
||||
fn isArrayList(value: anytype) bool {
|
||||
if (std.mem.startsWith(u8, @typeName(value), "array_list")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// pub fn get(self: *const Context, comptime T: type, key: []const u8) !T {
|
||||
// // const opt_value = self.map.get(key) orelse return error.KeyNotFound;
|
||||
// const opt_value = self.getOptional(T, key);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue