Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
key,
") != j.end() && !std::regex_match(j.at(",
key,
').get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time");',
').get<std::string>(), std::regex("^(?:(?:[0-9]{4}-(?:0[13578]|1[02])-(?:0[1-9]|[12][0-9]|3[01]))|(?:[0-9]{4}-(?:0[469]|11)-(?:0[1-9]|[12][0-9]|30))|(?:[0-9]{4}-02-(?:0[1-9]|1[0-9]|2[0-8]))|(?:(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:[02468][048]|[13579][26])00)-02-29))[Tt](?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:[.][0-9]+)?(?:[Zz]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])?$"))) throw std::runtime_error("Expected date-time");',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,10 @@ export class ObjectiveCRenderer extends ConvenienceRenderer {
}
if (property.type.kind === "date-time") {
this.emitLine(
`if (dict[@"${objectiveCStringEscape(jsonName)}"] && [dict[@"${objectiveCStringEscape(jsonName)}"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil;`,
`if (dict[@"${objectiveCStringEscape(jsonName)}"] && [dict[@"${objectiveCStringEscape(jsonName)}"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}[Tt](?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\\\.[0-9]+)?(?:[Zz]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])?$" options:NSRegularExpressionSearch].location == NSNotFound) return nil;`,
);
this.emitLine(
`if (dict[@"${objectiveCStringEscape(jsonName)}"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"${objectiveCStringEscape(jsonName)}"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"${objectiveCStringEscape(jsonName)}"] substringToIndex:10]]) return nil;`,
);
}
if (
Expand Down
8 changes: 8 additions & 0 deletions packages/quicktype-core/src/language/Php/PhpRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ export class PhpRenderer extends ConvenienceRenderer {
(transformedStringType) => {
if (transformedStringType.kind === "date-time") {
this.emitLine("$tmp = ", "new DateTime(", args, ");");
this.emitLine("$errors = DateTime::getLastErrors();");
this.emitBlock(
"if ($errors && ($errors['warning_count'] || $errors['error_count']))",
() =>
this.emitLine(
"throw new Exception('Invalid date-time');",
),
);
this.transformDateTime(className, "", ["$tmp"]);
this.emitLine("return $tmp;");
return;
Expand Down
7 changes: 7 additions & 0 deletions test/inputs/schema/date-time.12.fail.date-time.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "1985-04-12",
"time": "23:20:50.52Z",
"date-time": "2023-00-15T12:00:00Z",
"union-array": ["1985-04-12", "23:20:50.52Z"],
"complex-union-array": ["2018-08-13T21:31:01+00:10", "foo", 123]
}
Loading