support for timestamp as f128 (more)
f128 is not really the correct data type long term. More information on the exact details are https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html and https://smithy.io/2.0/spec/protocol-traits.html\#timestampformat-trait But...it will hold all our values and parses correctly, so we can use it for now
This commit is contained in:
parent
4313f8585b
commit
96e2b7bbc1
@ -716,7 +716,7 @@ fn generateTypeFor(shape_id: []const u8, writer: anytype, state: GenerationState
|
||||
// The serializer will have to deal with the idea we might be an array
|
||||
return try generateTypeFor(shape.set.member_target, writer, state, true);
|
||||
},
|
||||
.timestamp => |s| try generateSimpleTypeFor(s, "i64", writer),
|
||||
.timestamp => |s| try generateSimpleTypeFor(s, "f128", writer),
|
||||
.blob => |s| try generateSimpleTypeFor(s, "[]const u8", writer),
|
||||
.boolean => |s| try generateSimpleTypeFor(s, "bool", writer),
|
||||
.double => |s| try generateSimpleTypeFor(s, "f64", writer),
|
||||
|
@ -783,6 +783,12 @@ fn parseInt(comptime T: type, val: []const u8) !T {
|
||||
return e;
|
||||
};
|
||||
}
|
||||
if (T == f128) {
|
||||
return @as(f128, date.parseEnglishToTimestamp(val)) catch |e| {
|
||||
log.err("Error coercing date string '{s}' to timestamp value", .{val});
|
||||
return e;
|
||||
};
|
||||
}
|
||||
log.err("Error parsing string '{s}' to integer", .{val});
|
||||
return rc;
|
||||
}
|
||||
|
@ -105,6 +105,12 @@ fn parseInternal(comptime T: type, element: *xml.Element, options: ParseOptions)
|
||||
},
|
||||
.Float, .ComptimeFloat => {
|
||||
return std.fmt.parseFloat(T, element.children.items[0].CharData) catch |e| {
|
||||
if (element.children.items[0].CharData[element.children.items[0].CharData.len - 1] == 'Z') {
|
||||
// We have an iso8601 in an integer field (we think)
|
||||
// Try to coerce this into our type
|
||||
const timestamp = try date.parseIso8601ToTimestamp(element.children.items[0].CharData);
|
||||
return @floatFromInt(timestamp);
|
||||
}
|
||||
if (log_parse_traces) {
|
||||
std.log.err(
|
||||
"Could not parse '{s}' as float in element '{s}': {any}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user