Test case
3 generated files · +14 −4test/inputs/json/misc/0a358.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -149,12 +149,12 @@ namespace quicktype { | ||
| 149 | 149 | inline void from_json(const json & j, Result& x) { |
| 150 | 150 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 151 | 151 | x.set_code(j.at("code").get<std::string>()); |
| 152 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 152 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 153 | 153 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 154 | 154 | if (j.find("id") != j.end() && !j.at("id").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 155 | 155 | x.set_id(j.at("id").get<int64_t>()); |
| 156 | 156 | x.set_name(j.at("name").get<std::string>()); |
| 157 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 157 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 158 | 158 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 159 | 159 | x.set_uri(j.at("uri").get<std::string>()); |
| 160 | 160 | } |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -228,12 +228,14 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 228 | 228 | { |
| 229 | 229 | if (self = [super init]) { |
| 230 | 230 | if (![dict[@"code"] isKindOfClass:NSString.class]) return nil; |
| 231 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 231 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 232 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 232 | 233 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 233 | 234 | if (![dict[@"id"] isKindOfClass:NSNumber.class]) return nil; |
| 234 | 235 | if ([dict[@"id"] doubleValue] != [dict[@"id"] longLongValue]) return nil; |
| 235 | 236 | if (![dict[@"name"] isKindOfClass:NSString.class]) return nil; |
| 236 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 237 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 238 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 237 | 239 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 238 | 240 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 239 | 241 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+8 −0
| @@ -583,6 +583,10 @@ class Result { | ||
| 583 | 583 | */ |
| 584 | 584 | public static function fromCreatedAt(string $value): DateTime { |
| 585 | 585 | $tmp = new DateTime($value); |
| 586 | + $errors = DateTime::getLastErrors(); | |
| 587 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 588 | + throw new Exception('Invalid date-time'); | |
| 589 | + } | |
| 586 | 590 | if (!is_a($tmp, 'DateTime')) { |
| 587 | 591 | throw new Exception('Attribute Error:Result::'); |
| 588 | 592 | } |
| @@ -731,6 +735,10 @@ class Result { | ||
| 731 | 735 | */ |
| 732 | 736 | public static function fromUpdatedAt(string $value): DateTime { |
| 733 | 737 | $tmp = new DateTime($value); |
| 738 | + $errors = DateTime::getLastErrors(); | |
| 739 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 740 | + throw new Exception('Invalid date-time'); | |
| 741 | + } | |
| 734 | 742 | if (!is_a($tmp, 'DateTime')) { |
| 735 | 743 | throw new Exception('Attribute Error:Result::'); |
| 736 | 744 | } |
Test case
3 generated files · +56 −16test/inputs/json/misc/0a91a.json
Mcplusplusdefault / quicktype.hpp+8 −8
| @@ -1243,7 +1243,7 @@ namespace quicktype { | ||
| 1243 | 1243 | x.set_compare_url(j.at("compare_url").get<std::string>()); |
| 1244 | 1244 | x.set_contents_url(j.at("contents_url").get<std::string>()); |
| 1245 | 1245 | x.set_contributors_url(j.at("contributors_url").get<std::string>()); |
| 1246 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1246 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1247 | 1247 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1248 | 1248 | x.set_default_branch(j.at("default_branch").get<std::string>()); |
| 1249 | 1249 | x.set_deployments_url(j.at("deployments_url").get<std::string>()); |
| @@ -1289,7 +1289,7 @@ namespace quicktype { | ||
| 1289 | 1289 | x.set_open_issues_count(j.at("open_issues_count").get<int64_t>()); |
| 1290 | 1290 | x.set_owner(j.at("owner").get<MergedBy>()); |
| 1291 | 1291 | x.set_pulls_url(j.at("pulls_url").get<std::string>()); |
| 1292 | - if (j.find("pushed_at") != j.end() && !std::regex_match(j.at("pushed_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1292 | + if (j.find("pushed_at") != j.end() && !std::regex_match(j.at("pushed_at").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"); | |
| 1293 | 1293 | x.set_pushed_at(j.at("pushed_at").get<std::string>()); |
| 1294 | 1294 | x.set_releases_url(j.at("releases_url").get<std::string>()); |
| 1295 | 1295 | x.set_repo_private(j.at("private").get<bool>()); |
| @@ -1306,7 +1306,7 @@ namespace quicktype { | ||
| 1306 | 1306 | x.set_tags_url(j.at("tags_url").get<std::string>()); |
| 1307 | 1307 | x.set_teams_url(j.at("teams_url").get<std::string>()); |
| 1308 | 1308 | x.set_trees_url(j.at("trees_url").get<std::string>()); |
| 1309 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1309 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1310 | 1310 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1311 | 1311 | x.set_url(j.at("url").get<std::string>()); |
| 1312 | 1312 | if (j.find("watchers") != j.end() && !j.at("watchers").is_number_integer()) throw std::runtime_error("Expected integer"); |
| @@ -1450,7 +1450,7 @@ namespace quicktype { | ||
| 1450 | 1450 | x.set_body(j.at("body").get<std::string>()); |
| 1451 | 1451 | if (j.find("changed_files") != j.end() && !j.at("changed_files").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1452 | 1452 | x.set_changed_files(j.at("changed_files").get<int64_t>()); |
| 1453 | - if (j.find("closed_at") != j.end() && !std::regex_match(j.at("closed_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1453 | + if (j.find("closed_at") != j.end() && !std::regex_match(j.at("closed_at").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"); | |
| 1454 | 1454 | x.set_closed_at(j.at("closed_at").get<std::string>()); |
| 1455 | 1455 | if (j.find("comments") != j.end() && !j.at("comments").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1456 | 1456 | x.set_comments(j.at("comments").get<int64_t>()); |
| @@ -1458,7 +1458,7 @@ namespace quicktype { | ||
| 1458 | 1458 | if (j.find("commits") != j.end() && !j.at("commits").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1459 | 1459 | x.set_commits(j.at("commits").get<int64_t>()); |
| 1460 | 1460 | x.set_commits_url(j.at("commits_url").get<std::string>()); |
| 1461 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1461 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1462 | 1462 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1463 | 1463 | if (j.find("deletions") != j.end() && !j.at("deletions").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1464 | 1464 | x.set_deletions(j.at("deletions").get<int64_t>()); |
| @@ -1475,7 +1475,7 @@ namespace quicktype { | ||
| 1475 | 1475 | x.set_mergeable(get_untyped(j, "mergeable")); |
| 1476 | 1476 | x.set_mergeable_state(j.at("mergeable_state").get<std::string>()); |
| 1477 | 1477 | x.set_merged(j.at("merged").get<bool>()); |
| 1478 | - if (j.find("merged_at") != j.end() && !std::regex_match(j.at("merged_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1478 | + if (j.find("merged_at") != j.end() && !std::regex_match(j.at("merged_at").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"); | |
| 1479 | 1479 | x.set_merged_at(j.at("merged_at").get<std::string>()); |
| 1480 | 1480 | x.set_merged_by(j.at("merged_by").get<MergedBy>()); |
| 1481 | 1481 | x.set_milestone(get_untyped(j, "milestone")); |
| @@ -1491,7 +1491,7 @@ namespace quicktype { | ||
| 1491 | 1491 | x.set_state(j.at("state").get<std::string>()); |
| 1492 | 1492 | x.set_statuses_url(j.at("statuses_url").get<std::string>()); |
| 1493 | 1493 | x.set_title(j.at("title").get<std::string>()); |
| 1494 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1494 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1495 | 1495 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1496 | 1496 | x.set_url(j.at("url").get<std::string>()); |
| 1497 | 1497 | x.set_user(j.at("user").get<MergedBy>()); |
| @@ -1613,7 +1613,7 @@ namespace quicktype { | ||
| 1613 | 1613 | inline void from_json(const json & j, TopLevelElement& x) { |
| 1614 | 1614 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 1615 | 1615 | x.set_actor(j.at("actor").get<Actor>()); |
| 1616 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1616 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1617 | 1617 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1618 | 1618 | x.set_id(j.at("id").get<std::string>()); |
| 1619 | 1619 | if (j.find("org") != j.end() && j.at("org").is_null()) throw std::runtime_error("Unexpected null"); |
Mobjective-cdefault / QTTopLevel.m+16 −8
| @@ -175,7 +175,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 175 | 175 | { |
| 176 | 176 | if (self = [super init]) { |
| 177 | 177 | if (![dict[@"actor"] isKindOfClass:NSDictionary.class]) return nil; |
| 178 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 178 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 179 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 179 | 180 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 180 | 181 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 181 | 182 | if (![dict[@"public"] isKindOfClass:NSNumber.class]) return nil; |
| @@ -539,7 +540,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 539 | 540 | if (![dict[@"body"] isKindOfClass:NSString.class]) return nil; |
| 540 | 541 | if (![dict[@"changed_files"] isKindOfClass:NSNumber.class]) return nil; |
| 541 | 542 | if ([dict[@"changed_files"] doubleValue] != [dict[@"changed_files"] longLongValue]) return nil; |
| 542 | - if (dict[@"closed_at"] && [dict[@"closed_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 543 | + if (dict[@"closed_at"] && [dict[@"closed_at"] 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; | |
| 544 | + if (dict[@"closed_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"closed_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"closed_at"] substringToIndex:10]]) return nil; | |
| 543 | 545 | if (![dict[@"closed_at"] isKindOfClass:NSString.class]) return nil; |
| 544 | 546 | if (![dict[@"comments"] isKindOfClass:NSNumber.class]) return nil; |
| 545 | 547 | if ([dict[@"comments"] doubleValue] != [dict[@"comments"] longLongValue]) return nil; |
| @@ -547,7 +549,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 547 | 549 | if (![dict[@"commits"] isKindOfClass:NSNumber.class]) return nil; |
| 548 | 550 | if ([dict[@"commits"] doubleValue] != [dict[@"commits"] longLongValue]) return nil; |
| 549 | 551 | if (![dict[@"commits_url"] isKindOfClass:NSString.class]) return nil; |
| 550 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 552 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 553 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 551 | 554 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 552 | 555 | if (![dict[@"deletions"] isKindOfClass:NSNumber.class]) return nil; |
| 553 | 556 | if ([dict[@"deletions"] doubleValue] != [dict[@"deletions"] longLongValue]) return nil; |
| @@ -564,7 +567,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 564 | 567 | if (![dict[@"merge_commit_sha"] isKindOfClass:NSString.class]) return nil; |
| 565 | 568 | if (!dict[@"mergeable"]) return nil; |
| 566 | 569 | if (![dict[@"mergeable_state"] isKindOfClass:NSString.class]) return nil; |
| 567 | - if (dict[@"merged_at"] && [dict[@"merged_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 570 | + if (dict[@"merged_at"] && [dict[@"merged_at"] 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; | |
| 571 | + if (dict[@"merged_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"merged_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"merged_at"] substringToIndex:10]]) return nil; | |
| 568 | 572 | if (![dict[@"merged_at"] isKindOfClass:NSString.class]) return nil; |
| 569 | 573 | if (![dict[@"merged_by"] isKindOfClass:NSDictionary.class]) return nil; |
| 570 | 574 | if (!dict[@"milestone"]) return nil; |
| @@ -580,7 +584,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 580 | 584 | if (![dict[@"state"] isKindOfClass:NSString.class]) return nil; |
| 581 | 585 | if (![dict[@"statuses_url"] isKindOfClass:NSString.class]) return nil; |
| 582 | 586 | if (![dict[@"title"] isKindOfClass:NSString.class]) return nil; |
| 583 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 587 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 588 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 584 | 589 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 585 | 590 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 586 | 591 | if (![dict[@"user"] isKindOfClass:NSDictionary.class]) return nil; |
| @@ -794,7 +799,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 794 | 799 | if (![dict[@"compare_url"] isKindOfClass:NSString.class]) return nil; |
| 795 | 800 | if (![dict[@"contents_url"] isKindOfClass:NSString.class]) return nil; |
| 796 | 801 | if (![dict[@"contributors_url"] isKindOfClass:NSString.class]) return nil; |
| 797 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 802 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 803 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 798 | 804 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 799 | 805 | if (![dict[@"default_branch"] isKindOfClass:NSString.class]) return nil; |
| 800 | 806 | if (![dict[@"deployments_url"] isKindOfClass:NSString.class]) return nil; |
| @@ -840,7 +846,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 840 | 846 | if ([dict[@"open_issues_count"] doubleValue] != [dict[@"open_issues_count"] longLongValue]) return nil; |
| 841 | 847 | if (![dict[@"owner"] isKindOfClass:NSDictionary.class]) return nil; |
| 842 | 848 | if (![dict[@"pulls_url"] isKindOfClass:NSString.class]) return nil; |
| 843 | - if (dict[@"pushed_at"] && [dict[@"pushed_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 849 | + if (dict[@"pushed_at"] && [dict[@"pushed_at"] 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; | |
| 850 | + if (dict[@"pushed_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"pushed_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"pushed_at"] substringToIndex:10]]) return nil; | |
| 844 | 851 | if (![dict[@"pushed_at"] isKindOfClass:NSString.class]) return nil; |
| 845 | 852 | if (![dict[@"releases_url"] isKindOfClass:NSString.class]) return nil; |
| 846 | 853 | if (![dict[@"size"] isKindOfClass:NSNumber.class]) return nil; |
| @@ -857,7 +864,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 857 | 864 | if (![dict[@"teams_url"] isKindOfClass:NSString.class]) return nil; |
| 858 | 865 | if (!dict[@"description"]) return nil; |
| 859 | 866 | if (![dict[@"trees_url"] isKindOfClass:NSString.class]) return nil; |
| 860 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 867 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 868 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 861 | 869 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 862 | 870 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 863 | 871 | if (![dict[@"watchers"] isKindOfClass:NSNumber.class]) return nil; |
Mphpdefault / TopLevel.php+32 −0
| @@ -89,6 +89,10 @@ class TopLevel { | ||
| 89 | 89 | */ |
| 90 | 90 | public static function fromCreatedAt(string $value): DateTime { |
| 91 | 91 | $tmp = new DateTime($value); |
| 92 | + $errors = DateTime::getLastErrors(); | |
| 93 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 94 | + throw new Exception('Invalid date-time'); | |
| 95 | + } | |
| 92 | 96 | if (!is_a($tmp, 'DateTime')) { |
| 93 | 97 | throw new Exception('Attribute Error:TopLevel::'); |
| 94 | 98 | } |
| @@ -2790,6 +2794,10 @@ class PullRequest { | ||
| 2790 | 2794 | */ |
| 2791 | 2795 | public static function fromClosedAt(string $value): DateTime { |
| 2792 | 2796 | $tmp = new DateTime($value); |
| 2797 | + $errors = DateTime::getLastErrors(); | |
| 2798 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2799 | + throw new Exception('Invalid date-time'); | |
| 2800 | + } | |
| 2793 | 2801 | if (!is_a($tmp, 'DateTime')) { |
| 2794 | 2802 | throw new Exception('Attribute Error:PullRequest::'); |
| 2795 | 2803 | } |
| @@ -3032,6 +3040,10 @@ class PullRequest { | ||
| 3032 | 3040 | */ |
| 3033 | 3041 | public static function fromCreatedAt(string $value): DateTime { |
| 3034 | 3042 | $tmp = new DateTime($value); |
| 3043 | + $errors = DateTime::getLastErrors(); | |
| 3044 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 3045 | + throw new Exception('Invalid date-time'); | |
| 3046 | + } | |
| 3035 | 3047 | if (!is_a($tmp, 'DateTime')) { |
| 3036 | 3048 | throw new Exception('Attribute Error:PullRequest::'); |
| 3037 | 3049 | } |
| @@ -3702,6 +3714,10 @@ class PullRequest { | ||
| 3702 | 3714 | */ |
| 3703 | 3715 | public static function fromMergedAt(string $value): DateTime { |
| 3704 | 3716 | $tmp = new DateTime($value); |
| 3717 | + $errors = DateTime::getLastErrors(); | |
| 3718 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 3719 | + throw new Exception('Invalid date-time'); | |
| 3720 | + } | |
| 3705 | 3721 | if (!is_a($tmp, 'DateTime')) { |
| 3706 | 3722 | throw new Exception('Attribute Error:PullRequest::'); |
| 3707 | 3723 | } |
| @@ -4338,6 +4354,10 @@ class PullRequest { | ||
| 4338 | 4354 | */ |
| 4339 | 4355 | public static function fromUpdatedAt(string $value): DateTime { |
| 4340 | 4356 | $tmp = new DateTime($value); |
| 4357 | + $errors = DateTime::getLastErrors(); | |
| 4358 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 4359 | + throw new Exception('Invalid date-time'); | |
| 4360 | + } | |
| 4341 | 4361 | if (!is_a($tmp, 'DateTime')) { |
| 4342 | 4362 | throw new Exception('Attribute Error:PullRequest::'); |
| 4343 | 4363 | } |
| @@ -5873,6 +5893,10 @@ class BaseRepo { | ||
| 5873 | 5893 | */ |
| 5874 | 5894 | public static function fromCreatedAt(string $value): DateTime { |
| 5875 | 5895 | $tmp = new DateTime($value); |
| 5896 | + $errors = DateTime::getLastErrors(); | |
| 5897 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 5898 | + throw new Exception('Invalid date-time'); | |
| 5899 | + } | |
| 5876 | 5900 | if (!is_a($tmp, 'DateTime')) { |
| 5877 | 5901 | throw new Exception('Attribute Error:BaseRepo::'); |
| 5878 | 5902 | } |
| @@ -7817,6 +7841,10 @@ class BaseRepo { | ||
| 7817 | 7841 | */ |
| 7818 | 7842 | public static function fromPushedAt(string $value): DateTime { |
| 7819 | 7843 | $tmp = new DateTime($value); |
| 7844 | + $errors = DateTime::getLastErrors(); | |
| 7845 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 7846 | + throw new Exception('Invalid date-time'); | |
| 7847 | + } | |
| 7820 | 7848 | if (!is_a($tmp, 'DateTime')) { |
| 7821 | 7849 | throw new Exception('Attribute Error:BaseRepo::'); |
| 7822 | 7850 | } |
| @@ -8435,6 +8463,10 @@ class BaseRepo { | ||
| 8435 | 8463 | */ |
| 8436 | 8464 | public static function fromUpdatedAt(string $value): DateTime { |
| 8437 | 8465 | $tmp = new DateTime($value); |
| 8466 | + $errors = DateTime::getLastErrors(); | |
| 8467 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 8468 | + throw new Exception('Invalid date-time'); | |
| 8469 | + } | |
| 8438 | 8470 | if (!is_a($tmp, 'DateTime')) { |
| 8439 | 8471 | throw new Exception('Attribute Error:BaseRepo::'); |
| 8440 | 8472 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/16bc5.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/262f0.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -716,7 +716,7 @@ namespace quicktype { | ||
| 716 | 716 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 717 | 717 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 718 | 718 | x.set_count(j.at("count").get<int64_t>()); |
| 719 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 719 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 720 | 720 | x.set_created(j.at("created").get<std::string>()); |
| 721 | 721 | x.set_lang(j.at("lang").get<std::string>()); |
| 722 | 722 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -246,7 +246,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 246 | 246 | if (self = [super init]) { |
| 247 | 247 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 248 | 248 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 249 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 249 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 250 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 250 | 251 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 251 | 252 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 252 | 253 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
1 generated file · +4 −0test/inputs/json/misc/32d5c.json
Mphpdefault / TopLevel.php+4 −0
| @@ -42,6 +42,10 @@ class TopLevel { | ||
| 42 | 42 | public static function fromBirthDate(?string $value): ?DateTime { |
| 43 | 43 | if (!is_null($value)) { |
| 44 | 44 | $tmp = new DateTime($value); |
| 45 | + $errors = DateTime::getLastErrors(); | |
| 46 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 47 | + throw new Exception('Invalid date-time'); | |
| 48 | + } | |
| 45 | 49 | if (!is_a($tmp, 'DateTime')) { |
| 46 | 50 | throw new Exception('Attribute Error:TopLevel::'); |
| 47 | 51 | } |
Test case
3 generated files · +42 −12test/inputs/json/misc/337ed.json
Mcplusplusdefault / quicktype.hpp+6 −6
| @@ -386,13 +386,13 @@ namespace quicktype { | ||
| 386 | 386 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 387 | 387 | if (j.find("amount") != j.end() && !j.at("amount").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 388 | 388 | x.set_amount(j.at("amount").get<int64_t>()); |
| 389 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 389 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 390 | 390 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 391 | 391 | x.set_id(j.at("id").get<std::string>()); |
| 392 | 392 | x.set_name(j.at("name").get<std::string>()); |
| 393 | 393 | x.set_status(j.at("status").get<Status>()); |
| 394 | 394 | x.set_type(j.at("type").get<CustomIncomeType>()); |
| 395 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 395 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 396 | 396 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 397 | 397 | x.set_uri(j.at("uri").get<std::string>()); |
| 398 | 398 | } |
| @@ -417,12 +417,12 @@ namespace quicktype { | ||
| 417 | 417 | x.set_cost_max(get_stack_optional<int64_t>(j, "cost_max")); |
| 418 | 418 | j.at("cost_min"); |
| 419 | 419 | x.set_cost_min(get_stack_optional<int64_t>(j, "cost_min")); |
| 420 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 420 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 421 | 421 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 422 | 422 | x.set_custom_incomes(j.at("customIncomes").get<std::vector<CustomIncome>>()); |
| 423 | 423 | x.set_direct_rep_costs_max(get_untyped(j, "direct_rep_costs_max")); |
| 424 | 424 | x.set_direct_rep_costs_min(get_untyped(j, "direct_rep_costs_min")); |
| 425 | - if (j.find("end_date") != j.end() && !std::regex_match(j.at("end_date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 425 | + if (j.find("end_date") != j.end() && !std::regex_match(j.at("end_date").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"); | |
| 426 | 426 | x.set_end_date(j.at("end_date").get<std::string>()); |
| 427 | 427 | if (j.find("eur_sources_grants") != j.end() && !j.at("eur_sources_grants").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 428 | 428 | x.set_eur_sources_grants(j.at("eur_sources_grants").get<int64_t>()); |
| @@ -451,7 +451,7 @@ namespace quicktype { | ||
| 451 | 451 | j.at("public_financing_total"); |
| 452 | 452 | x.set_public_financing_total(get_stack_optional<int64_t>(j, "public_financing_total")); |
| 453 | 453 | x.set_representative(j.at("representative").get<std::string>()); |
| 454 | - if (j.find("start_date") != j.end() && !std::regex_match(j.at("start_date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 454 | + if (j.find("start_date") != j.end() && !std::regex_match(j.at("start_date").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"); | |
| 455 | 455 | x.set_start_date(j.at("start_date").get<std::string>()); |
| 456 | 456 | x.set_status(j.at("status").get<Status>()); |
| 457 | 457 | j.at("total_budget"); |
| @@ -463,7 +463,7 @@ namespace quicktype { | ||
| 463 | 463 | j.at("turnover_min"); |
| 464 | 464 | x.set_turnover_min(get_stack_optional<int64_t>(j, "turnover_min")); |
| 465 | 465 | x.set_type(j.at("type").get<ResultType>()); |
| 466 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 466 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 467 | 467 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 468 | 468 | x.set_uri(j.at("uri").get<std::string>()); |
| 469 | 469 | } |
Mobjective-cdefault / QTTopLevel.m+12 −6
| @@ -344,12 +344,14 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 344 | 344 | if (!dict[@"cost_absolute"]) return nil; |
| 345 | 345 | if (!dict[@"cost_max"]) return nil; |
| 346 | 346 | if (!dict[@"cost_min"]) return nil; |
| 347 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 347 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 348 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 348 | 349 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 349 | 350 | if (![dict[@"customIncomes"] isKindOfClass:NSArray.class]) return nil; |
| 350 | 351 | if (!dict[@"direct_rep_costs_max"]) return nil; |
| 351 | 352 | if (!dict[@"direct_rep_costs_min"]) return nil; |
| 352 | - if (dict[@"end_date"] && [dict[@"end_date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 353 | + if (dict[@"end_date"] && [dict[@"end_date"] 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; | |
| 354 | + if (dict[@"end_date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"end_date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"end_date"] substringToIndex:10]]) return nil; | |
| 353 | 355 | if (![dict[@"end_date"] isKindOfClass:NSString.class]) return nil; |
| 354 | 356 | if (![dict[@"eur_sources_grants"] isKindOfClass:NSNumber.class]) return nil; |
| 355 | 357 | if ([dict[@"eur_sources_grants"] doubleValue] != [dict[@"eur_sources_grants"] longLongValue]) return nil; |
| @@ -367,7 +369,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 367 | 369 | if (!dict[@"public_financing_national"]) return nil; |
| 368 | 370 | if (!dict[@"public_financing_total"]) return nil; |
| 369 | 371 | if (![dict[@"representative"] isKindOfClass:NSString.class]) return nil; |
| 370 | - if (dict[@"start_date"] && [dict[@"start_date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 372 | + if (dict[@"start_date"] && [dict[@"start_date"] 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; | |
| 373 | + if (dict[@"start_date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"start_date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"start_date"] substringToIndex:10]]) return nil; | |
| 371 | 374 | if (![dict[@"start_date"] isKindOfClass:NSString.class]) return nil; |
| 372 | 375 | if (![dict[@"status"] isKindOfClass:NSString.class]) return nil; |
| 373 | 376 | if (!dict[@"new_organisation"]) return nil; |
| @@ -376,7 +379,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 376 | 379 | if (!dict[@"turnover_max"]) return nil; |
| 377 | 380 | if (!dict[@"turnover_min"]) return nil; |
| 378 | 381 | if (![dict[@"type"] isKindOfClass:NSString.class]) return nil; |
| 379 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 382 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 383 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 380 | 384 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 381 | 385 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 382 | 386 | [self setValuesForKeysWithDictionary:dict]; |
| @@ -447,13 +451,15 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 447 | 451 | if (self = [super init]) { |
| 448 | 452 | if (![dict[@"amount"] isKindOfClass:NSNumber.class]) return nil; |
| 449 | 453 | if ([dict[@"amount"] doubleValue] != [dict[@"amount"] longLongValue]) return nil; |
| 450 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 454 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 455 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 451 | 456 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 452 | 457 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 453 | 458 | if (![dict[@"name"] isKindOfClass:NSString.class]) return nil; |
| 454 | 459 | if (![dict[@"status"] isKindOfClass:NSString.class]) return nil; |
| 455 | 460 | if (![dict[@"type"] isKindOfClass:NSString.class]) return nil; |
| 456 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 461 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 462 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 457 | 463 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 458 | 464 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 459 | 465 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+24 −0
| @@ -785,6 +785,10 @@ class Result { | ||
| 785 | 785 | */ |
| 786 | 786 | public static function fromCreatedAt(string $value): DateTime { |
| 787 | 787 | $tmp = new DateTime($value); |
| 788 | + $errors = DateTime::getLastErrors(); | |
| 789 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 790 | + throw new Exception('Invalid date-time'); | |
| 791 | + } | |
| 788 | 792 | if (!is_a($tmp, 'DateTime')) { |
| 789 | 793 | throw new Exception('Attribute Error:Result::'); |
| 790 | 794 | } |
| @@ -998,6 +1002,10 @@ class Result { | ||
| 998 | 1002 | */ |
| 999 | 1003 | public static function fromEndDate(string $value): DateTime { |
| 1000 | 1004 | $tmp = new DateTime($value); |
| 1005 | + $errors = DateTime::getLastErrors(); | |
| 1006 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 1007 | + throw new Exception('Invalid date-time'); | |
| 1008 | + } | |
| 1001 | 1009 | if (!is_a($tmp, 'DateTime')) { |
| 1002 | 1010 | throw new Exception('Attribute Error:Result::'); |
| 1003 | 1011 | } |
| @@ -1860,6 +1868,10 @@ class Result { | ||
| 1860 | 1868 | */ |
| 1861 | 1869 | public static function fromStartDate(string $value): DateTime { |
| 1862 | 1870 | $tmp = new DateTime($value); |
| 1871 | + $errors = DateTime::getLastErrors(); | |
| 1872 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 1873 | + throw new Exception('Invalid date-time'); | |
| 1874 | + } | |
| 1863 | 1875 | if (!is_a($tmp, 'DateTime')) { |
| 1864 | 1876 | throw new Exception('Attribute Error:Result::'); |
| 1865 | 1877 | } |
| @@ -2238,6 +2250,10 @@ class Result { | ||
| 2238 | 2250 | */ |
| 2239 | 2251 | public static function fromUpdatedAt(string $value): DateTime { |
| 2240 | 2252 | $tmp = new DateTime($value); |
| 2253 | + $errors = DateTime::getLastErrors(); | |
| 2254 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2255 | + throw new Exception('Invalid date-time'); | |
| 2256 | + } | |
| 2241 | 2257 | if (!is_a($tmp, 'DateTime')) { |
| 2242 | 2258 | throw new Exception('Attribute Error:Result::'); |
| 2243 | 2259 | } |
| @@ -2678,6 +2694,10 @@ class CustomIncome { | ||
| 2678 | 2694 | */ |
| 2679 | 2695 | public static function fromCreatedAt(string $value): DateTime { |
| 2680 | 2696 | $tmp = new DateTime($value); |
| 2697 | + $errors = DateTime::getLastErrors(); | |
| 2698 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2699 | + throw new Exception('Invalid date-time'); | |
| 2700 | + } | |
| 2681 | 2701 | if (!is_a($tmp, 'DateTime')) { |
| 2682 | 2702 | throw new Exception('Attribute Error:CustomIncome::'); |
| 2683 | 2703 | } |
| @@ -2922,6 +2942,10 @@ class CustomIncome { | ||
| 2922 | 2942 | */ |
| 2923 | 2943 | public static function fromUpdatedAt(string $value): DateTime { |
| 2924 | 2944 | $tmp = new DateTime($value); |
| 2945 | + $errors = DateTime::getLastErrors(); | |
| 2946 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2947 | + throw new Exception('Invalid date-time'); | |
| 2948 | + } | |
| 2925 | 2949 | if (!is_a($tmp, 'DateTime')) { |
| 2926 | 2950 | throw new Exception('Attribute Error:CustomIncome::'); |
| 2927 | 2951 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/3f1ce.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -716,7 +716,7 @@ namespace quicktype { | ||
| 716 | 716 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 717 | 717 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 718 | 718 | x.set_count(j.at("count").get<int64_t>()); |
| 719 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 719 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 720 | 720 | x.set_created(j.at("created").get<std::string>()); |
| 721 | 721 | x.set_lang(j.at("lang").get<std::string>()); |
| 722 | 722 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -242,7 +242,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 242 | 242 | if (self = [super init]) { |
| 243 | 243 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 244 | 244 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 245 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 245 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 246 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 246 | 247 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 247 | 248 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 248 | 249 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/4c547.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +14 −4test/inputs/json/misc/54d32.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -153,13 +153,13 @@ namespace quicktype { | ||
| 153 | 153 | |
| 154 | 154 | inline void from_json(const json & j, Result& x) { |
| 155 | 155 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 156 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 156 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 157 | 157 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 158 | 158 | x.set_id(j.at("id").get<std::string>()); |
| 159 | 159 | x.set_person_id(j.at("person_id").get<std::string>()); |
| 160 | 160 | x.set_representative_id(j.at("representative_id").get<std::string>()); |
| 161 | 161 | x.set_status(j.at("status").get<Status>()); |
| 162 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 162 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 163 | 163 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 164 | 164 | } |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -254,13 +254,15 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 254 | 254 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 255 | 255 | { |
| 256 | 256 | if (self = [super init]) { |
| 257 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 257 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 258 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 258 | 259 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 259 | 260 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 260 | 261 | if (![dict[@"person_id"] isKindOfClass:NSString.class]) return nil; |
| 261 | 262 | if (![dict[@"representative_id"] isKindOfClass:NSString.class]) return nil; |
| 262 | 263 | if (![dict[@"status"] isKindOfClass:NSString.class]) return nil; |
| 263 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 264 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 265 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 264 | 266 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 265 | 267 | [self setValuesForKeysWithDictionary:dict]; |
| 266 | 268 | _status = [QTStatus withValue:(id)_status]; |
Mphpdefault / TopLevel.php+8 −0
| @@ -536,6 +536,10 @@ class Result { | ||
| 536 | 536 | */ |
| 537 | 537 | public static function fromCreatedAt(string $value): DateTime { |
| 538 | 538 | $tmp = new DateTime($value); |
| 539 | + $errors = DateTime::getLastErrors(); | |
| 540 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 541 | + throw new Exception('Invalid date-time'); | |
| 542 | + } | |
| 539 | 543 | if (!is_a($tmp, 'DateTime')) { |
| 540 | 544 | throw new Exception('Attribute Error:Result::'); |
| 541 | 545 | } |
| @@ -779,6 +783,10 @@ class Result { | ||
| 779 | 783 | */ |
| 780 | 784 | public static function fromUpdatedAt(string $value): DateTime { |
| 781 | 785 | $tmp = new DateTime($value); |
| 786 | + $errors = DateTime::getLastErrors(); | |
| 787 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 788 | + throw new Exception('Invalid date-time'); | |
| 789 | + } | |
| 782 | 790 | if (!is_a($tmp, 'DateTime')) { |
| 783 | 791 | throw new Exception('Attribute Error:Result::'); |
| 784 | 792 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/5eae5.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -69,7 +69,7 @@ namespace quicktype { | ||
| 69 | 69 | |
| 70 | 70 | inline void from_json(const json & j, TopLevelElement& x) { |
| 71 | 71 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 72 | - if (j.find("Date") != j.end() && !std::regex_match(j.at("Date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 72 | + if (j.find("Date") != j.end() && !std::regex_match(j.at("Date").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"); | |
| 73 | 73 | x.set_date(j.at("Date").get<std::string>()); |
| 74 | 74 | if (j.find("ID") != j.end() && !j.at("ID").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 75 | 75 | x.set_id(j.at("ID").get<int64_t>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -82,7 +82,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 82 | 82 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 83 | 83 | { |
| 84 | 84 | if (self = [super init]) { |
| 85 | - if (dict[@"Date"] && [dict[@"Date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 85 | + if (dict[@"Date"] && [dict[@"Date"] 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; | |
| 86 | + if (dict[@"Date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"Date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"Date"] substringToIndex:10]]) return nil; | |
| 86 | 87 | if (![dict[@"Date"] isKindOfClass:NSString.class]) return nil; |
| 87 | 88 | if (![dict[@"ID"] isKindOfClass:NSNumber.class]) return nil; |
| 88 | 89 | if ([dict[@"ID"] doubleValue] != [dict[@"ID"] longLongValue]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -29,6 +29,10 @@ class TopLevel { | ||
| 29 | 29 | */ |
| 30 | 30 | public static function fromDate(string $value): DateTime { |
| 31 | 31 | $tmp = new DateTime($value); |
| 32 | + $errors = DateTime::getLastErrors(); | |
| 33 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 34 | + throw new Exception('Invalid date-time'); | |
| 35 | + } | |
| 32 | 36 | if (!is_a($tmp, 'DateTime')) { |
| 33 | 37 | throw new Exception('Attribute Error:TopLevel::'); |
| 34 | 38 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/6dec6.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -716,7 +716,7 @@ namespace quicktype { | ||
| 716 | 716 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 717 | 717 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 718 | 718 | x.set_count(j.at("count").get<int64_t>()); |
| 719 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 719 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 720 | 720 | x.set_created(j.at("created").get<std::string>()); |
| 721 | 721 | x.set_lang(j.at("lang").get<std::string>()); |
| 722 | 722 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -246,7 +246,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 246 | 246 | if (self = [super init]) { |
| 247 | 247 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 248 | 248 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 249 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 249 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 250 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 250 | 251 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 251 | 252 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 252 | 253 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +28 −8test/inputs/json/misc/734ad.json
Mcplusplusdefault / quicktype.hpp+4 −4
| @@ -478,7 +478,7 @@ namespace quicktype { | ||
| 478 | 478 | x.set_code_of_conduct(j.at("code_of_conduct").get<std::string>()); |
| 479 | 479 | if (j.find("contact_country") != j.end() && !j.at("contact_country").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 480 | 480 | x.set_contact_country(j.at("contact_country").get<int64_t>()); |
| 481 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 481 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 482 | 482 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 483 | 483 | x.set_entity(j.at("entity").get<std::string>()); |
| 484 | 484 | x.set_goals(j.at("goals").get<std::string>()); |
| @@ -498,7 +498,7 @@ namespace quicktype { | ||
| 498 | 498 | x.set_id(j.at("id").get<std::string>()); |
| 499 | 499 | x.set_identification_code(j.at("identification_code").get<std::string>()); |
| 500 | 500 | x.set_info_members(j.at("info_members").get<std::string>()); |
| 501 | - if (j.find("last_update_date") != j.end() && !std::regex_match(j.at("last_update_date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 501 | + if (j.find("last_update_date") != j.end() && !std::regex_match(j.at("last_update_date").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"); | |
| 502 | 502 | x.set_last_update_date(j.at("last_update_date").get<std::string>()); |
| 503 | 503 | x.set_legal(j.at("legal").get<std::string>()); |
| 504 | 504 | x.set_legal_status(j.at("legal_status").get<std::string>()); |
| @@ -524,14 +524,14 @@ namespace quicktype { | ||
| 524 | 524 | x.set_number_of_natural_persons(get_stack_optional<int64_t>(j, "number_of_natural_persons")); |
| 525 | 525 | j.at("other_code_of_conduct"); |
| 526 | 526 | x.set_other_code_of_conduct(get_stack_optional<std::string>(j, "other_code_of_conduct")); |
| 527 | - if (j.find("registration_date") != j.end() && !std::regex_match(j.at("registration_date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 527 | + if (j.find("registration_date") != j.end() && !std::regex_match(j.at("registration_date").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"); | |
| 528 | 528 | x.set_registration_date(j.at("registration_date").get<std::string>()); |
| 529 | 529 | x.set_status(j.at("status").get<Status>()); |
| 530 | 530 | x.set_structure_members(j.at("structure_members").get<std::string>()); |
| 531 | 531 | if (j.find("sub_category") != j.end() && !j.at("sub_category").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 532 | 532 | x.set_sub_category(j.at("sub_category").get<int64_t>()); |
| 533 | 533 | x.set_sub_category_title(j.at("sub_category_title").get<std::string>()); |
| 534 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 534 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 535 | 535 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 536 | 536 | x.set_uri(j.at("uri").get<std::string>()); |
| 537 | 537 | j.at("web_site_url"); |
Mobjective-cdefault / QTTopLevel.m+8 −4
| @@ -318,7 +318,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 318 | 318 | if (![dict[@"code_of_conduct"] isKindOfClass:NSString.class]) return nil; |
| 319 | 319 | if (![dict[@"contact_country"] isKindOfClass:NSNumber.class]) return nil; |
| 320 | 320 | if ([dict[@"contact_country"] doubleValue] != [dict[@"contact_country"] longLongValue]) return nil; |
| 321 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 321 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 322 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 322 | 323 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 323 | 324 | if (![dict[@"entity"] isKindOfClass:NSString.class]) return nil; |
| 324 | 325 | if (![dict[@"goals"] isKindOfClass:NSString.class]) return nil; |
| @@ -334,7 +335,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 334 | 335 | if (![dict[@"identification_code"] isKindOfClass:NSString.class]) return nil; |
| 335 | 336 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 336 | 337 | if (![dict[@"info_members"] isKindOfClass:NSString.class]) return nil; |
| 337 | - if (dict[@"last_update_date"] && [dict[@"last_update_date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 338 | + if (dict[@"last_update_date"] && [dict[@"last_update_date"] 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; | |
| 339 | + if (dict[@"last_update_date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"last_update_date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"last_update_date"] substringToIndex:10]]) return nil; | |
| 338 | 340 | if (![dict[@"last_update_date"] isKindOfClass:NSString.class]) return nil; |
| 339 | 341 | if (![dict[@"legal"] isKindOfClass:NSString.class]) return nil; |
| 340 | 342 | if (![dict[@"legal_status"] isKindOfClass:NSString.class]) return nil; |
| @@ -353,14 +355,16 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 353 | 355 | if (!dict[@"networking"]) return nil; |
| 354 | 356 | if (!dict[@"number_of_natural_persons"]) return nil; |
| 355 | 357 | if (!dict[@"other_code_of_conduct"]) return nil; |
| 356 | - if (dict[@"registration_date"] && [dict[@"registration_date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 358 | + if (dict[@"registration_date"] && [dict[@"registration_date"] 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; | |
| 359 | + if (dict[@"registration_date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"registration_date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"registration_date"] substringToIndex:10]]) return nil; | |
| 357 | 360 | if (![dict[@"registration_date"] isKindOfClass:NSString.class]) return nil; |
| 358 | 361 | if (![dict[@"status"] isKindOfClass:NSString.class]) return nil; |
| 359 | 362 | if (![dict[@"structure_members"] isKindOfClass:NSString.class]) return nil; |
| 360 | 363 | if (![dict[@"sub_category"] isKindOfClass:NSNumber.class]) return nil; |
| 361 | 364 | if ([dict[@"sub_category"] doubleValue] != [dict[@"sub_category"] longLongValue]) return nil; |
| 362 | 365 | if (![dict[@"sub_category_title"] isKindOfClass:NSString.class]) return nil; |
| 363 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 366 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 367 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 364 | 368 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 365 | 369 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 366 | 370 | if (!dict[@"web_site_url"]) return nil; |
Mphpdefault / TopLevel.php+16 −0
| @@ -1685,6 +1685,10 @@ class Result { | ||
| 1685 | 1685 | */ |
| 1686 | 1686 | public static function fromCreatedAt(string $value): DateTime { |
| 1687 | 1687 | $tmp = new DateTime($value); |
| 1688 | + $errors = DateTime::getLastErrors(); | |
| 1689 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 1690 | + throw new Exception('Invalid date-time'); | |
| 1691 | + } | |
| 1688 | 1692 | if (!is_a($tmp, 'DateTime')) { |
| 1689 | 1693 | throw new Exception('Attribute Error:Result::'); |
| 1690 | 1694 | } |
| @@ -2437,6 +2441,10 @@ class Result { | ||
| 2437 | 2441 | */ |
| 2438 | 2442 | public static function fromLastUpdateDate(string $value): DateTime { |
| 2439 | 2443 | $tmp = new DateTime($value); |
| 2444 | + $errors = DateTime::getLastErrors(); | |
| 2445 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2446 | + throw new Exception('Invalid date-time'); | |
| 2447 | + } | |
| 2440 | 2448 | if (!is_a($tmp, 'DateTime')) { |
| 2441 | 2449 | throw new Exception('Attribute Error:Result::'); |
| 2442 | 2450 | } |
| @@ -3269,6 +3277,10 @@ class Result { | ||
| 3269 | 3277 | */ |
| 3270 | 3278 | public static function fromRegistrationDate(string $value): DateTime { |
| 3271 | 3279 | $tmp = new DateTime($value); |
| 3280 | + $errors = DateTime::getLastErrors(); | |
| 3281 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 3282 | + throw new Exception('Invalid date-time'); | |
| 3283 | + } | |
| 3272 | 3284 | if (!is_a($tmp, 'DateTime')) { |
| 3273 | 3285 | throw new Exception('Attribute Error:Result::'); |
| 3274 | 3286 | } |
| @@ -3512,6 +3524,10 @@ class Result { | ||
| 3512 | 3524 | */ |
| 3513 | 3525 | public static function fromUpdatedAt(string $value): DateTime { |
| 3514 | 3526 | $tmp = new DateTime($value); |
| 3527 | + $errors = DateTime::getLastErrors(); | |
| 3528 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 3529 | + throw new Exception('Invalid date-time'); | |
| 3530 | + } | |
| 3515 | 3531 | if (!is_a($tmp, 'DateTime')) { |
| 3516 | 3532 | throw new Exception('Attribute Error:Result::'); |
| 3517 | 3533 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/77392.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -167,7 +167,7 @@ namespace quicktype { | ||
| 167 | 167 | inline void from_json(const json & j, TopLevelElement& x) { |
| 168 | 168 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 169 | 169 | x.set_designation(j.at("designation").get<std::string>()); |
| 170 | - if (j.find("discovery_date") != j.end() && !std::regex_match(j.at("discovery_date").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 170 | + if (j.find("discovery_date") != j.end() && !std::regex_match(j.at("discovery_date").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"); | |
| 171 | 171 | x.set_discovery_date(j.at("discovery_date").get<std::string>()); |
| 172 | 172 | if (j.find("h_mag") != j.end() && j.at("h_mag").is_null()) throw std::runtime_error("Unexpected null"); |
| 173 | 173 | x.set_h_mag(get_stack_optional<std::string>(j, "h_mag")); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -159,7 +159,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 159 | 159 | { |
| 160 | 160 | if (self = [super init]) { |
| 161 | 161 | if (![dict[@"designation"] isKindOfClass:NSString.class]) return nil; |
| 162 | - if (dict[@"discovery_date"] && [dict[@"discovery_date"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 162 | + if (dict[@"discovery_date"] && [dict[@"discovery_date"] 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; | |
| 163 | + if (dict[@"discovery_date"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"discovery_date"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"discovery_date"] substringToIndex:10]]) return nil; | |
| 163 | 164 | if (![dict[@"discovery_date"] isKindOfClass:NSString.class]) return nil; |
| 164 | 165 | if (![dict[@"i_deg"] isKindOfClass:NSString.class]) return nil; |
| 165 | 166 | if (![dict[@"moid_au"] isKindOfClass:NSString.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -94,6 +94,10 @@ class TopLevel { | ||
| 94 | 94 | */ |
| 95 | 95 | public static function fromDiscoveryDate(string $value): DateTime { |
| 96 | 96 | $tmp = new DateTime($value); |
| 97 | + $errors = DateTime::getLastErrors(); | |
| 98 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 99 | + throw new Exception('Invalid date-time'); | |
| 100 | + } | |
| 97 | 101 | if (!is_a($tmp, 'DateTime')) { |
| 98 | 102 | throw new Exception('Attribute Error:TopLevel::'); |
| 99 | 103 | } |
Test case
3 generated files · +14 −4test/inputs/json/misc/7f568.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -254,7 +254,7 @@ namespace quicktype { | ||
| 254 | 254 | x.set_comments(j.at("comments").get<int64_t>()); |
| 255 | 255 | x.set_comments_url(j.at("comments_url").get<std::string>()); |
| 256 | 256 | x.set_commits_url(j.at("commits_url").get<std::string>()); |
| 257 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 257 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 258 | 258 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 259 | 259 | j.at("description"); |
| 260 | 260 | x.set_description(get_stack_optional<std::string>(j, "description")); |
| @@ -266,7 +266,7 @@ namespace quicktype { | ||
| 266 | 266 | x.set_id(j.at("id").get<std::string>()); |
| 267 | 267 | x.set_top_level_public(j.at("public").get<bool>()); |
| 268 | 268 | x.set_truncated(j.at("truncated").get<bool>()); |
| 269 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 269 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 270 | 270 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 271 | 271 | x.set_url(j.at("url").get<std::string>()); |
| 272 | 272 | x.set_user(get_untyped(j, "user")); |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -153,7 +153,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 153 | 153 | if ([dict[@"comments"] doubleValue] != [dict[@"comments"] longLongValue]) return nil; |
| 154 | 154 | if (![dict[@"comments_url"] isKindOfClass:NSString.class]) return nil; |
| 155 | 155 | if (![dict[@"commits_url"] isKindOfClass:NSString.class]) return nil; |
| 156 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 156 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 157 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 157 | 158 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 158 | 159 | if (![dict[@"files"] isKindOfClass:NSDictionary.class]) return nil; |
| 159 | 160 | if (![dict[@"forks_url"] isKindOfClass:NSString.class]) return nil; |
| @@ -164,7 +165,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 164 | 165 | if (![dict[@"public"] isKindOfClass:NSNumber.class]) return nil; |
| 165 | 166 | if (![dict[@"truncated"] isKindOfClass:NSNumber.class]) return nil; |
| 166 | 167 | if (!dict[@"description"]) return nil; |
| 167 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 168 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 169 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 168 | 170 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 169 | 171 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 170 | 172 | if (!dict[@"user"]) return nil; |
Mphpdefault / TopLevel.php+8 −0
| @@ -206,6 +206,10 @@ class TopLevel { | ||
| 206 | 206 | */ |
| 207 | 207 | public static function fromCreatedAt(string $value): DateTime { |
| 208 | 208 | $tmp = new DateTime($value); |
| 209 | + $errors = DateTime::getLastErrors(); | |
| 210 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 211 | + throw new Exception('Invalid date-time'); | |
| 212 | + } | |
| 209 | 213 | if (!is_a($tmp, 'DateTime')) { |
| 210 | 214 | throw new Exception('Attribute Error:TopLevel::'); |
| 211 | 215 | } |
| @@ -708,6 +712,10 @@ class TopLevel { | ||
| 708 | 712 | */ |
| 709 | 713 | public static function fromUpdatedAt(string $value): DateTime { |
| 710 | 714 | $tmp = new DateTime($value); |
| 715 | + $errors = DateTime::getLastErrors(); | |
| 716 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 717 | + throw new Exception('Invalid date-time'); | |
| 718 | + } | |
| 711 | 719 | if (!is_a($tmp, 'DateTime')) { |
| 712 | 720 | throw new Exception('Attribute Error:TopLevel::'); |
| 713 | 721 | } |
Test case
3 generated files · +14 −4test/inputs/json/misc/80aff.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -208,7 +208,7 @@ namespace quicktype { | ||
| 208 | 208 | |
| 209 | 209 | inline void from_json(const json & j, Result& x) { |
| 210 | 210 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 211 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 211 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 212 | 212 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 213 | 213 | if (j.find("id") != j.end() && !j.at("id").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 214 | 214 | x.set_id(j.at("id").get<int64_t>()); |
| @@ -217,7 +217,7 @@ namespace quicktype { | ||
| 217 | 217 | x.set_name(j.at("name").get<std::string>()); |
| 218 | 218 | j.at("parent"); |
| 219 | 219 | x.set_parent(get_stack_optional<int64_t>(j, "parent")); |
| 220 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 220 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 221 | 221 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 222 | 222 | x.set_uri(j.at("uri").get<std::string>()); |
| 223 | 223 | } |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -229,7 +229,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 229 | 229 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 230 | 230 | { |
| 231 | 231 | if (self = [super init]) { |
| 232 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 232 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 233 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 233 | 234 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 234 | 235 | if (![dict[@"id"] isKindOfClass:NSNumber.class]) return nil; |
| 235 | 236 | if ([dict[@"id"] doubleValue] != [dict[@"id"] longLongValue]) return nil; |
| @@ -237,7 +238,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 237 | 238 | if ([dict[@"items"] doubleValue] != [dict[@"items"] longLongValue]) return nil; |
| 238 | 239 | if (![dict[@"name"] isKindOfClass:NSString.class]) return nil; |
| 239 | 240 | if (!dict[@"parent"]) return nil; |
| 240 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 241 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 242 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 241 | 243 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 242 | 244 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 243 | 245 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+8 −0
| @@ -539,6 +539,10 @@ class Result { | ||
| 539 | 539 | */ |
| 540 | 540 | public static function fromCreatedAt(string $value): DateTime { |
| 541 | 541 | $tmp = new DateTime($value); |
| 542 | + $errors = DateTime::getLastErrors(); | |
| 543 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 544 | + throw new Exception('Invalid date-time'); | |
| 545 | + } | |
| 542 | 546 | if (!is_a($tmp, 'DateTime')) { |
| 543 | 547 | throw new Exception('Attribute Error:Result::'); |
| 544 | 548 | } |
| @@ -791,6 +795,10 @@ class Result { | ||
| 791 | 795 | */ |
| 792 | 796 | public static function fromUpdatedAt(string $value): DateTime { |
| 793 | 797 | $tmp = new DateTime($value); |
| 798 | + $errors = DateTime::getLastErrors(); | |
| 799 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 800 | + throw new Exception('Invalid date-time'); | |
| 801 | + } | |
| 794 | 802 | if (!is_a($tmp, 'DateTime')) { |
| 795 | 803 | throw new Exception('Attribute Error:Result::'); |
| 796 | 804 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/88130.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/9929c.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +14 −4test/inputs/json/misc/9ac3b.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -237,7 +237,7 @@ namespace quicktype { | ||
| 237 | 237 | |
| 238 | 238 | inline void from_json(const json & j, Result& x) { |
| 239 | 239 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 240 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 240 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 241 | 241 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 242 | 242 | x.set_entity(j.at("entity").get<std::string>()); |
| 243 | 243 | x.set_first_name(j.at("first_name").get<std::string>()); |
| @@ -249,7 +249,7 @@ namespace quicktype { | ||
| 249 | 249 | x.set_status(j.at("status").get<Status>()); |
| 250 | 250 | j.at("title"); |
| 251 | 251 | x.set_title(get_stack_optional<Title>(j, "title")); |
| 252 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 252 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 253 | 253 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 254 | 254 | x.set_uri(j.at("uri").get<std::string>()); |
| 255 | 255 | } |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -286,7 +286,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 286 | 286 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 287 | 287 | { |
| 288 | 288 | if (self = [super init]) { |
| 289 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 289 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 290 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 290 | 291 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 291 | 292 | if (![dict[@"entity"] isKindOfClass:NSString.class]) return nil; |
| 292 | 293 | if (![dict[@"first_name"] isKindOfClass:NSString.class]) return nil; |
| @@ -296,7 +297,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 296 | 297 | if (!dict[@"position"]) return nil; |
| 297 | 298 | if (![dict[@"status"] isKindOfClass:NSString.class]) return nil; |
| 298 | 299 | if (!dict[@"title"]) return nil; |
| 299 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 300 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 301 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 300 | 302 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 301 | 303 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 302 | 304 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+8 −0
| @@ -551,6 +551,10 @@ class Result { | ||
| 551 | 551 | */ |
| 552 | 552 | public static function fromCreatedAt(string $value): DateTime { |
| 553 | 553 | $tmp = new DateTime($value); |
| 554 | + $errors = DateTime::getLastErrors(); | |
| 555 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 556 | + throw new Exception('Invalid date-time'); | |
| 557 | + } | |
| 554 | 558 | if (!is_a($tmp, 'DateTime')) { |
| 555 | 559 | throw new Exception('Attribute Error:Result::'); |
| 556 | 560 | } |
| @@ -1003,6 +1007,10 @@ class Result { | ||
| 1003 | 1007 | */ |
| 1004 | 1008 | public static function fromUpdatedAt(string $value): DateTime { |
| 1005 | 1009 | $tmp = new DateTime($value); |
| 1010 | + $errors = DateTime::getLastErrors(); | |
| 1011 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 1012 | + throw new Exception('Invalid date-time'); | |
| 1013 | + } | |
| 1006 | 1014 | if (!is_a($tmp, 'DateTime')) { |
| 1007 | 1015 | throw new Exception('Attribute Error:Result::'); |
| 1008 | 1016 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/a0496.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -239,7 +239,7 @@ namespace quicktype { | ||
| 239 | 239 | x.set_source_name(j.at("source_name").get<std::string>()); |
| 240 | 240 | x.set_to_date(j.at("to_date").get<std::string>()); |
| 241 | 241 | x.set_type(j.at("type").get<std::string>()); |
| 242 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 242 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 243 | 243 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 244 | 244 | x.set_urlize_name(j.at("urlize_name").get<std::string>()); |
| 245 | 245 | } |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -125,7 +125,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 125 | 125 | if (![dict[@"description"] isKindOfClass:NSString.class]) return nil; |
| 126 | 126 | if (![dict[@"to_date"] isKindOfClass:NSString.class]) return nil; |
| 127 | 127 | if (![dict[@"type"] isKindOfClass:NSString.class]) return nil; |
| 128 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 128 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 129 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 129 | 130 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 130 | 131 | if (![dict[@"urlize_name"] isKindOfClass:NSString.class]) return nil; |
| 131 | 132 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+4 −0
| @@ -841,6 +841,10 @@ class TopLevel { | ||
| 841 | 841 | */ |
| 842 | 842 | public static function fromUpdatedAt(string $value): DateTime { |
| 843 | 843 | $tmp = new DateTime($value); |
| 844 | + $errors = DateTime::getLastErrors(); | |
| 845 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 846 | + throw new Exception('Invalid date-time'); | |
| 847 | + } | |
| 844 | 848 | if (!is_a($tmp, 'DateTime')) { |
| 845 | 849 | throw new Exception('Attribute Error:TopLevel::'); |
| 846 | 850 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/a1eca.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
2 generated files · +5 −1test/inputs/json/misc/b4865.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -232,7 +232,7 @@ namespace quicktype { | ||
| 232 | 232 | x.set_reclat(get_stack_optional<std::string>(j, "reclat")); |
| 233 | 233 | if (j.find("reclong") != j.end() && j.at("reclong").is_null()) throw std::runtime_error("Unexpected null"); |
| 234 | 234 | x.set_reclong(get_stack_optional<std::string>(j, "reclong")); |
| 235 | - if (j.find("year") != j.end() && !std::regex_match(j.at("year").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 235 | + if (j.find("year") != j.end() && !std::regex_match(j.at("year").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"); | |
| 236 | 236 | if (j.find("year") != j.end() && j.at("year").is_null()) throw std::runtime_error("Unexpected null"); |
| 237 | 237 | x.set_year(get_stack_optional<std::string>(j, "year")); |
| 238 | 238 | } |
Mphpdefault / TopLevel.php+4 −0
| @@ -634,6 +634,10 @@ class TopLevel { | ||
| 634 | 634 | public static function fromYear(?string $value): ?DateTime { |
| 635 | 635 | if (!is_null($value)) { |
| 636 | 636 | $tmp = new DateTime($value); |
| 637 | + $errors = DateTime::getLastErrors(); | |
| 638 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 639 | + throw new Exception('Invalid date-time'); | |
| 640 | + } | |
| 637 | 641 | if (!is_a($tmp, 'DateTime')) { |
| 638 | 642 | throw new Exception('Attribute Error:TopLevel::'); |
| 639 | 643 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/cf0d8.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +14 −4test/inputs/json/misc/d23d5.json
Mcplusplusdefault / quicktype.hpp+2 −2
| @@ -205,11 +205,11 @@ namespace quicktype { | ||
| 205 | 205 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 206 | 206 | j.at("acronym"); |
| 207 | 207 | x.set_acronym(get_stack_optional<std::string>(j, "acronym")); |
| 208 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 208 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 209 | 209 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 210 | 210 | x.set_id(j.at("id").get<std::string>()); |
| 211 | 211 | x.set_name(j.at("name").get<std::string>()); |
| 212 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 212 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 213 | 213 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 214 | 214 | x.set_uri(j.at("uri").get<std::string>()); |
| 215 | 215 | } |
Mobjective-cdefault / QTTopLevel.m+4 −2
| @@ -228,11 +228,13 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 228 | 228 | { |
| 229 | 229 | if (self = [super init]) { |
| 230 | 230 | if (!dict[@"acronym"]) return nil; |
| 231 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 231 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 232 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 232 | 233 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 233 | 234 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 234 | 235 | if (![dict[@"name"] isKindOfClass:NSString.class]) return nil; |
| 235 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 236 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 237 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 236 | 238 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 237 | 239 | if (![dict[@"uri"] isKindOfClass:NSString.class]) return nil; |
| 238 | 240 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+8 −0
| @@ -593,6 +593,10 @@ class Result { | ||
| 593 | 593 | */ |
| 594 | 594 | public static function fromCreatedAt(string $value): DateTime { |
| 595 | 595 | $tmp = new DateTime($value); |
| 596 | + $errors = DateTime::getLastErrors(); | |
| 597 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 598 | + throw new Exception('Invalid date-time'); | |
| 599 | + } | |
| 596 | 600 | if (!is_a($tmp, 'DateTime')) { |
| 597 | 601 | throw new Exception('Attribute Error:Result::'); |
| 598 | 602 | } |
| @@ -741,6 +745,10 @@ class Result { | ||
| 741 | 745 | */ |
| 742 | 746 | public static function fromUpdatedAt(string $value): DateTime { |
| 743 | 747 | $tmp = new DateTime($value); |
| 748 | + $errors = DateTime::getLastErrors(); | |
| 749 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 750 | + throw new Exception('Invalid date-time'); | |
| 751 | + } | |
| 744 | 752 | if (!is_a($tmp, 'DateTime')) { |
| 745 | 753 | throw new Exception('Attribute Error:Result::'); |
| 746 | 754 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/dbfb3.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -716,7 +716,7 @@ namespace quicktype { | ||
| 716 | 716 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 717 | 717 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 718 | 718 | x.set_count(j.at("count").get<int64_t>()); |
| 719 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 719 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 720 | 720 | x.set_created(j.at("created").get<std::string>()); |
| 721 | 721 | x.set_lang(j.at("lang").get<std::string>()); |
| 722 | 722 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -244,7 +244,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 244 | 244 | if (self = [super init]) { |
| 245 | 245 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 246 | 246 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 247 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 247 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 248 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 248 | 249 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 249 | 250 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 250 | 251 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/df957.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -711,7 +711,7 @@ namespace quicktype { | ||
| 711 | 711 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 712 | 712 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 713 | 713 | x.set_count(j.at("count").get<int64_t>()); |
| 714 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 714 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 715 | 715 | x.set_created(j.at("created").get<std::string>()); |
| 716 | 716 | x.set_lang(j.at("lang").get<std::string>()); |
| 717 | 717 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -217,7 +217,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 217 | 217 | if (self = [super init]) { |
| 218 | 218 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 219 | 219 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 220 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 220 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 221 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 221 | 222 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 222 | 223 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 223 | 224 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
3 generated files · +7 −2test/inputs/json/misc/e2915.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -716,7 +716,7 @@ namespace quicktype { | ||
| 716 | 716 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 717 | 717 | if (j.find("count") != j.end() && !j.at("count").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 718 | 718 | x.set_count(j.at("count").get<int64_t>()); |
| 719 | - if (j.find("created") != j.end() && !std::regex_match(j.at("created").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 719 | + if (j.find("created") != j.end() && !std::regex_match(j.at("created").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"); | |
| 720 | 720 | x.set_created(j.at("created").get<std::string>()); |
| 721 | 721 | x.set_lang(j.at("lang").get<std::string>()); |
| 722 | 722 | x.set_results(j.at("results").get<Results>()); |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -242,7 +242,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 242 | 242 | if (self = [super init]) { |
| 243 | 243 | if (![dict[@"count"] isKindOfClass:NSNumber.class]) return nil; |
| 244 | 244 | if ([dict[@"count"] doubleValue] != [dict[@"count"] longLongValue]) return nil; |
| 245 | - if (dict[@"created"] && [dict[@"created"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 245 | + if (dict[@"created"] && [dict[@"created"] 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; | |
| 246 | + if (dict[@"created"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created"] substringToIndex:10]]) return nil; | |
| 246 | 247 | if (![dict[@"created"] isKindOfClass:NSString.class]) return nil; |
| 247 | 248 | if (![dict[@"lang"] isKindOfClass:NSString.class]) return nil; |
| 248 | 249 | if (![dict[@"results"] isKindOfClass:NSDictionary.class]) return nil; |
Mphpdefault / TopLevel.php+4 −0
| @@ -178,6 +178,10 @@ class Query { | ||
| 178 | 178 | */ |
| 179 | 179 | public static function fromCreated(string $value): DateTime { |
| 180 | 180 | $tmp = new DateTime($value); |
| 181 | + $errors = DateTime::getLastErrors(); | |
| 182 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 183 | + throw new Exception('Invalid date-time'); | |
| 184 | + } | |
| 181 | 185 | if (!is_a($tmp, 'DateTime')) { |
| 182 | 186 | throw new Exception('Attribute Error:Query::'); |
| 183 | 187 | } |
Test case
1 generated file · +4 −0test/inputs/json/priority/bug2590.json
Mphpdefault / TopLevel.php+4 −0
| @@ -140,6 +140,10 @@ class Invoice { | ||
| 140 | 140 | public static function fromCreatedAt(?string $value): ?DateTime { |
| 141 | 141 | if (!is_null($value)) { |
| 142 | 142 | $tmp = new DateTime($value); |
| 143 | + $errors = DateTime::getLastErrors(); | |
| 144 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 145 | + throw new Exception('Invalid date-time'); | |
| 146 | + } | |
| 143 | 147 | if (!is_a($tmp, 'DateTime')) { |
| 144 | 148 | throw new Exception('Attribute Error:Invoice::'); |
| 145 | 149 | } |
Test case
3 generated files · +7 −2test/inputs/json/priority/bug2663.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -63,7 +63,7 @@ namespace quicktype { | ||
| 63 | 63 | inline void from_json(const json & j, TopLevel& x) { |
| 64 | 64 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 65 | 65 | x.set_birthday(j.at("birthday").get<std::string>()); |
| 66 | - if (j.find("lastSeen") != j.end() && !std::regex_match(j.at("lastSeen").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 66 | + if (j.find("lastSeen") != j.end() && !std::regex_match(j.at("lastSeen").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"); | |
| 67 | 67 | x.set_last_seen(j.at("lastSeen").get<std::string>()); |
| 68 | 68 | x.set_name(j.at("name").get<std::string>()); |
| 69 | 69 | } |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -79,7 +79,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 79 | 79 | { |
| 80 | 80 | if (self = [super init]) { |
| 81 | 81 | if (![dict[@"birthday"] isKindOfClass:NSString.class]) return nil; |
| 82 | - if (dict[@"lastSeen"] && [dict[@"lastSeen"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 82 | + if (dict[@"lastSeen"] && [dict[@"lastSeen"] 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; | |
| 83 | + if (dict[@"lastSeen"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"lastSeen"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"lastSeen"] substringToIndex:10]]) return nil; | |
| 83 | 84 | if (![dict[@"lastSeen"] isKindOfClass:NSString.class]) return nil; |
| 84 | 85 | if (![dict[@"name"] isKindOfClass:NSString.class]) return nil; |
| 85 | 86 | [self setValuesForKeysWithDictionary:dict]; |
Mphpdefault / TopLevel.php+4 −0
| @@ -73,6 +73,10 @@ class TopLevel { | ||
| 73 | 73 | */ |
| 74 | 74 | public static function fromLastSeen(string $value): DateTime { |
| 75 | 75 | $tmp = new DateTime($value); |
| 76 | + $errors = DateTime::getLastErrors(); | |
| 77 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 78 | + throw new Exception('Invalid date-time'); | |
| 79 | + } | |
| 76 | 80 | if (!is_a($tmp, 'DateTime')) { |
| 77 | 81 | throw new Exception('Attribute Error:TopLevel::'); |
| 78 | 82 | } |
Test case
3 generated files · +7 −2test/inputs/json/priority/keywords.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -8380,7 +8380,7 @@ namespace quicktype { | ||
| 8380 | 8380 | |
| 8381 | 8381 | inline void from_json(const json & j, DateTime& x) { |
| 8382 | 8382 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 8383 | - if (j.find("DateTime") != j.end() && !std::regex_match(j.at("DateTime").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 8383 | + if (j.find("DateTime") != j.end() && !std::regex_match(j.at("DateTime").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"); | |
| 8384 | 8384 | x.set_date_time(j.at("DateTime").get<std::string>()); |
| 8385 | 8385 | } |
Mobjective-cdefault / QTTopLevel.m+2 −1
| @@ -5848,7 +5848,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 5848 | 5848 | - (instancetype)initWithJSONDictionary:(NSDictionary *)dict |
| 5849 | 5849 | { |
| 5850 | 5850 | if (self = [super init]) { |
| 5851 | - if (dict[@"DateTime"] && [dict[@"DateTime"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 5851 | + if (dict[@"DateTime"] && [dict[@"DateTime"] 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; | |
| 5852 | + if (dict[@"DateTime"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"DateTime"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"DateTime"] substringToIndex:10]]) return nil; | |
| 5852 | 5853 | if (![dict[@"DateTime"] isKindOfClass:NSString.class]) return nil; |
| 5853 | 5854 | [self setValuesForKeysWithDictionary:dict]; |
| 5854 | 5855 | } |
Mphpdefault / TopLevel.php+4 −0
| @@ -14963,6 +14963,10 @@ class DateTimeClass { | ||
| 14963 | 14963 | */ |
| 14964 | 14964 | public static function fromDateTime(string $value): DateTime { |
| 14965 | 14965 | $tmp = new DateTime($value); |
| 14966 | + $errors = DateTime::getLastErrors(); | |
| 14967 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 14968 | + throw new Exception('Invalid date-time'); | |
| 14969 | + } | |
| 14966 | 14970 | if (!is_a($tmp, 'DateTime')) { |
| 14967 | 14971 | throw new Exception('Attribute Error:DateTimeClass::'); |
| 14968 | 14972 | } |
Test case
3 generated files · +106 −28test/inputs/json/samples/github-events.json
Mcplusplusdefault / quicktype.hpp+14 −14
| @@ -1541,13 +1541,13 @@ namespace quicktype { | ||
| 1541 | 1541 | inline void from_json(const json & j, Comment& x) { |
| 1542 | 1542 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 1543 | 1543 | x.set_body(j.at("body").get<std::string>()); |
| 1544 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1544 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1545 | 1545 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1546 | 1546 | x.set_html_url(j.at("html_url").get<std::string>()); |
| 1547 | 1547 | if (j.find("id") != j.end() && !j.at("id").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1548 | 1548 | x.set_id(j.at("id").get<int64_t>()); |
| 1549 | 1549 | x.set_issue_url(j.at("issue_url").get<std::string>()); |
| 1550 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1550 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1551 | 1551 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1552 | 1552 | x.set_url(j.at("url").get<std::string>()); |
| 1553 | 1553 | x.set_user(j.at("user").get<User>()); |
| @@ -1619,7 +1619,7 @@ namespace quicktype { | ||
| 1619 | 1619 | x.set_closed_at(get_untyped(j, "closed_at")); |
| 1620 | 1620 | if (j.find("closed_issues") != j.end() && !j.at("closed_issues").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1621 | 1621 | x.set_closed_issues(j.at("closed_issues").get<int64_t>()); |
| 1622 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1622 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1623 | 1623 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1624 | 1624 | x.set_creator(j.at("creator").get<User>()); |
| 1625 | 1625 | x.set_description(j.at("description").get<std::string>()); |
| @@ -1635,7 +1635,7 @@ namespace quicktype { | ||
| 1635 | 1635 | x.set_open_issues(j.at("open_issues").get<int64_t>()); |
| 1636 | 1636 | x.set_state(j.at("state").get<std::string>()); |
| 1637 | 1637 | x.set_title(j.at("title").get<std::string>()); |
| 1638 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1638 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1639 | 1639 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1640 | 1640 | x.set_url(j.at("url").get<std::string>()); |
| 1641 | 1641 | } |
| @@ -1685,7 +1685,7 @@ namespace quicktype { | ||
| 1685 | 1685 | if (j.find("comments") != j.end() && !j.at("comments").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1686 | 1686 | x.set_comments(j.at("comments").get<int64_t>()); |
| 1687 | 1687 | x.set_comments_url(j.at("comments_url").get<std::string>()); |
| 1688 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1688 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1689 | 1689 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1690 | 1690 | x.set_events_url(j.at("events_url").get<std::string>()); |
| 1691 | 1691 | x.set_html_url(j.at("html_url").get<std::string>()); |
| @@ -1703,7 +1703,7 @@ namespace quicktype { | ||
| 1703 | 1703 | x.set_repository_url(j.at("repository_url").get<std::string>()); |
| 1704 | 1704 | x.set_state(j.at("state").get<std::string>()); |
| 1705 | 1705 | x.set_title(j.at("title").get<std::string>()); |
| 1706 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1706 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1707 | 1707 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1708 | 1708 | x.set_url(j.at("url").get<std::string>()); |
| 1709 | 1709 | x.set_user(j.at("user").get<User>()); |
| @@ -1748,7 +1748,7 @@ namespace quicktype { | ||
| 1748 | 1748 | x.set_compare_url(j.at("compare_url").get<std::string>()); |
| 1749 | 1749 | x.set_contents_url(j.at("contents_url").get<std::string>()); |
| 1750 | 1750 | x.set_contributors_url(j.at("contributors_url").get<std::string>()); |
| 1751 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1751 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1752 | 1752 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1753 | 1753 | x.set_default_branch(j.at("default_branch").get<std::string>()); |
| 1754 | 1754 | x.set_deployments_url(j.at("deployments_url").get<std::string>()); |
| @@ -1794,7 +1794,7 @@ namespace quicktype { | ||
| 1794 | 1794 | x.set_open_issues_count(j.at("open_issues_count").get<int64_t>()); |
| 1795 | 1795 | x.set_owner(j.at("owner").get<User>()); |
| 1796 | 1796 | x.set_pulls_url(j.at("pulls_url").get<std::string>()); |
| 1797 | - if (j.find("pushed_at") != j.end() && !std::regex_match(j.at("pushed_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1797 | + if (j.find("pushed_at") != j.end() && !std::regex_match(j.at("pushed_at").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"); | |
| 1798 | 1798 | x.set_pushed_at(j.at("pushed_at").get<std::string>()); |
| 1799 | 1799 | x.set_releases_url(j.at("releases_url").get<std::string>()); |
| 1800 | 1800 | x.set_repo_private(j.at("private").get<bool>()); |
| @@ -1811,7 +1811,7 @@ namespace quicktype { | ||
| 1811 | 1811 | x.set_tags_url(j.at("tags_url").get<std::string>()); |
| 1812 | 1812 | x.set_teams_url(j.at("teams_url").get<std::string>()); |
| 1813 | 1813 | x.set_trees_url(j.at("trees_url").get<std::string>()); |
| 1814 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1814 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 1815 | 1815 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 1816 | 1816 | x.set_url(j.at("url").get<std::string>()); |
| 1817 | 1817 | if (j.find("watchers") != j.end() && !j.at("watchers").is_number_integer()) throw std::runtime_error("Expected integer"); |
| @@ -1955,7 +1955,7 @@ namespace quicktype { | ||
| 1955 | 1955 | x.set_body(j.at("body").get<std::string>()); |
| 1956 | 1956 | if (j.find("changed_files") != j.end() && !j.at("changed_files").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1957 | 1957 | x.set_changed_files(j.at("changed_files").get<int64_t>()); |
| 1958 | - if (j.find("closed_at") != j.end() && !std::regex_match(j.at("closed_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1958 | + if (j.find("closed_at") != j.end() && !std::regex_match(j.at("closed_at").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"); | |
| 1959 | 1959 | x.set_closed_at(j.at("closed_at").get<std::string>()); |
| 1960 | 1960 | if (j.find("comments") != j.end() && !j.at("comments").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1961 | 1961 | x.set_comments(j.at("comments").get<int64_t>()); |
| @@ -1963,7 +1963,7 @@ namespace quicktype { | ||
| 1963 | 1963 | if (j.find("commits") != j.end() && !j.at("commits").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1964 | 1964 | x.set_commits(j.at("commits").get<int64_t>()); |
| 1965 | 1965 | x.set_commits_url(j.at("commits_url").get<std::string>()); |
| 1966 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1966 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 1967 | 1967 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 1968 | 1968 | if (j.find("deletions") != j.end() && !j.at("deletions").is_number_integer()) throw std::runtime_error("Expected integer"); |
| 1969 | 1969 | x.set_deletions(j.at("deletions").get<int64_t>()); |
| @@ -1980,7 +1980,7 @@ namespace quicktype { | ||
| 1980 | 1980 | x.set_mergeable(get_untyped(j, "mergeable")); |
| 1981 | 1981 | x.set_mergeable_state(j.at("mergeable_state").get<std::string>()); |
| 1982 | 1982 | x.set_merged(j.at("merged").get<bool>()); |
| 1983 | - if (j.find("merged_at") != j.end() && !std::regex_match(j.at("merged_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1983 | + if (j.find("merged_at") != j.end() && !std::regex_match(j.at("merged_at").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"); | |
| 1984 | 1984 | x.set_merged_at(j.at("merged_at").get<std::string>()); |
| 1985 | 1985 | x.set_merged_by(j.at("merged_by").get<User>()); |
| 1986 | 1986 | x.set_milestone(get_untyped(j, "milestone")); |
| @@ -1996,7 +1996,7 @@ namespace quicktype { | ||
| 1996 | 1996 | x.set_state(j.at("state").get<std::string>()); |
| 1997 | 1997 | x.set_statuses_url(j.at("statuses_url").get<std::string>()); |
| 1998 | 1998 | x.set_title(j.at("title").get<std::string>()); |
| 1999 | - if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 1999 | + if (j.find("updated_at") != j.end() && !std::regex_match(j.at("updated_at").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"); | |
| 2000 | 2000 | x.set_updated_at(j.at("updated_at").get<std::string>()); |
| 2001 | 2001 | x.set_url(j.at("url").get<std::string>()); |
| 2002 | 2002 | x.set_user(j.at("user").get<User>()); |
| @@ -2125,7 +2125,7 @@ namespace quicktype { | ||
| 2125 | 2125 | inline void from_json(const json & j, TopLevelElement& x) { |
| 2126 | 2126 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 2127 | 2127 | x.set_actor(j.at("actor").get<Actor>()); |
| 2128 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 2128 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 2129 | 2129 | x.set_created_at(j.at("created_at").get<std::string>()); |
| 2130 | 2130 | x.set_id(j.at("id").get<std::string>()); |
| 2131 | 2131 | if (j.find("org") != j.end() && j.at("org").is_null()) throw std::runtime_error("Unexpected null"); |
Mobjective-cdefault / QTTopLevel.m+28 −14
| @@ -194,7 +194,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 194 | 194 | { |
| 195 | 195 | if (self = [super init]) { |
| 196 | 196 | if (![dict[@"actor"] isKindOfClass:NSDictionary.class]) return nil; |
| 197 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 197 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 198 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 198 | 199 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 199 | 200 | if (![dict[@"id"] isKindOfClass:NSString.class]) return nil; |
| 200 | 201 | if (![dict[@"public"] isKindOfClass:NSNumber.class]) return nil; |
| @@ -415,13 +416,15 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 415 | 416 | { |
| 416 | 417 | if (self = [super init]) { |
| 417 | 418 | if (![dict[@"body"] isKindOfClass:NSString.class]) return nil; |
| 418 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 419 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 420 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 419 | 421 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 420 | 422 | if (![dict[@"html_url"] isKindOfClass:NSString.class]) return nil; |
| 421 | 423 | if (![dict[@"id"] isKindOfClass:NSNumber.class]) return nil; |
| 422 | 424 | if ([dict[@"id"] doubleValue] != [dict[@"id"] longLongValue]) return nil; |
| 423 | 425 | if (![dict[@"issue_url"] isKindOfClass:NSString.class]) return nil; |
| 424 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 426 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 427 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 425 | 428 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 426 | 429 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 427 | 430 | if (![dict[@"user"] isKindOfClass:NSDictionary.class]) return nil; |
| @@ -708,7 +711,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 708 | 711 | if (![dict[@"comments"] isKindOfClass:NSNumber.class]) return nil; |
| 709 | 712 | if ([dict[@"comments"] doubleValue] != [dict[@"comments"] longLongValue]) return nil; |
| 710 | 713 | if (![dict[@"comments_url"] isKindOfClass:NSString.class]) return nil; |
| 711 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 714 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 715 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 712 | 716 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 713 | 717 | if (![dict[@"events_url"] isKindOfClass:NSString.class]) return nil; |
| 714 | 718 | if (![dict[@"html_url"] isKindOfClass:NSString.class]) return nil; |
| @@ -723,7 +727,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 723 | 727 | if (![dict[@"repository_url"] isKindOfClass:NSString.class]) return nil; |
| 724 | 728 | if (![dict[@"state"] isKindOfClass:NSString.class]) return nil; |
| 725 | 729 | if (![dict[@"title"] isKindOfClass:NSString.class]) return nil; |
| 726 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 730 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 731 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 727 | 732 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 728 | 733 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 729 | 734 | if (![dict[@"user"] isKindOfClass:NSDictionary.class]) return nil; |
| @@ -873,7 +878,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 873 | 878 | if (!dict[@"closed_at"]) return nil; |
| 874 | 879 | if (![dict[@"closed_issues"] isKindOfClass:NSNumber.class]) return nil; |
| 875 | 880 | if ([dict[@"closed_issues"] doubleValue] != [dict[@"closed_issues"] longLongValue]) return nil; |
| 876 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 881 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 882 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 877 | 883 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 878 | 884 | if (![dict[@"creator"] isKindOfClass:NSDictionary.class]) return nil; |
| 879 | 885 | if (!dict[@"due_on"]) return nil; |
| @@ -888,7 +894,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 888 | 894 | if (![dict[@"state"] isKindOfClass:NSString.class]) return nil; |
| 889 | 895 | if (![dict[@"description"] isKindOfClass:NSString.class]) return nil; |
| 890 | 896 | if (![dict[@"title"] isKindOfClass:NSString.class]) return nil; |
| 891 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 897 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 898 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 892 | 899 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 893 | 900 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 894 | 901 | [self setValuesForKeysWithDictionary:dict]; |
| @@ -1052,7 +1059,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1052 | 1059 | if (![dict[@"body"] isKindOfClass:NSString.class]) return nil; |
| 1053 | 1060 | if (![dict[@"changed_files"] isKindOfClass:NSNumber.class]) return nil; |
| 1054 | 1061 | if ([dict[@"changed_files"] doubleValue] != [dict[@"changed_files"] longLongValue]) return nil; |
| 1055 | - if (dict[@"closed_at"] && [dict[@"closed_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1062 | + if (dict[@"closed_at"] && [dict[@"closed_at"] 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; | |
| 1063 | + if (dict[@"closed_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"closed_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"closed_at"] substringToIndex:10]]) return nil; | |
| 1056 | 1064 | if (![dict[@"closed_at"] isKindOfClass:NSString.class]) return nil; |
| 1057 | 1065 | if (![dict[@"comments"] isKindOfClass:NSNumber.class]) return nil; |
| 1058 | 1066 | if ([dict[@"comments"] doubleValue] != [dict[@"comments"] longLongValue]) return nil; |
| @@ -1060,7 +1068,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1060 | 1068 | if (![dict[@"commits"] isKindOfClass:NSNumber.class]) return nil; |
| 1061 | 1069 | if ([dict[@"commits"] doubleValue] != [dict[@"commits"] longLongValue]) return nil; |
| 1062 | 1070 | if (![dict[@"commits_url"] isKindOfClass:NSString.class]) return nil; |
| 1063 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1071 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 1072 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 1064 | 1073 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 1065 | 1074 | if (![dict[@"deletions"] isKindOfClass:NSNumber.class]) return nil; |
| 1066 | 1075 | if ([dict[@"deletions"] doubleValue] != [dict[@"deletions"] longLongValue]) return nil; |
| @@ -1077,7 +1086,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1077 | 1086 | if (![dict[@"merge_commit_sha"] isKindOfClass:NSString.class]) return nil; |
| 1078 | 1087 | if (!dict[@"mergeable"]) return nil; |
| 1079 | 1088 | if (![dict[@"mergeable_state"] isKindOfClass:NSString.class]) return nil; |
| 1080 | - if (dict[@"merged_at"] && [dict[@"merged_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1089 | + if (dict[@"merged_at"] && [dict[@"merged_at"] 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; | |
| 1090 | + if (dict[@"merged_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"merged_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"merged_at"] substringToIndex:10]]) return nil; | |
| 1081 | 1091 | if (![dict[@"merged_at"] isKindOfClass:NSString.class]) return nil; |
| 1082 | 1092 | if (![dict[@"merged_by"] isKindOfClass:NSDictionary.class]) return nil; |
| 1083 | 1093 | if (!dict[@"milestone"]) return nil; |
| @@ -1093,7 +1103,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1093 | 1103 | if (![dict[@"state"] isKindOfClass:NSString.class]) return nil; |
| 1094 | 1104 | if (![dict[@"statuses_url"] isKindOfClass:NSString.class]) return nil; |
| 1095 | 1105 | if (![dict[@"title"] isKindOfClass:NSString.class]) return nil; |
| 1096 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1106 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 1107 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 1097 | 1108 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 1098 | 1109 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 1099 | 1110 | if (![dict[@"user"] isKindOfClass:NSDictionary.class]) return nil; |
| @@ -1307,7 +1318,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1307 | 1318 | if (![dict[@"compare_url"] isKindOfClass:NSString.class]) return nil; |
| 1308 | 1319 | if (![dict[@"contents_url"] isKindOfClass:NSString.class]) return nil; |
| 1309 | 1320 | if (![dict[@"contributors_url"] isKindOfClass:NSString.class]) return nil; |
| 1310 | - if (dict[@"created_at"] && [dict[@"created_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1321 | + if (dict[@"created_at"] && [dict[@"created_at"] 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; | |
| 1322 | + if (dict[@"created_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"created_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"created_at"] substringToIndex:10]]) return nil; | |
| 1311 | 1323 | if (![dict[@"created_at"] isKindOfClass:NSString.class]) return nil; |
| 1312 | 1324 | if (![dict[@"default_branch"] isKindOfClass:NSString.class]) return nil; |
| 1313 | 1325 | if (![dict[@"deployments_url"] isKindOfClass:NSString.class]) return nil; |
| @@ -1353,7 +1365,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1353 | 1365 | if ([dict[@"open_issues_count"] doubleValue] != [dict[@"open_issues_count"] longLongValue]) return nil; |
| 1354 | 1366 | if (![dict[@"owner"] isKindOfClass:NSDictionary.class]) return nil; |
| 1355 | 1367 | if (![dict[@"pulls_url"] isKindOfClass:NSString.class]) return nil; |
| 1356 | - if (dict[@"pushed_at"] && [dict[@"pushed_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1368 | + if (dict[@"pushed_at"] && [dict[@"pushed_at"] 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; | |
| 1369 | + if (dict[@"pushed_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"pushed_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"pushed_at"] substringToIndex:10]]) return nil; | |
| 1357 | 1370 | if (![dict[@"pushed_at"] isKindOfClass:NSString.class]) return nil; |
| 1358 | 1371 | if (![dict[@"releases_url"] isKindOfClass:NSString.class]) return nil; |
| 1359 | 1372 | if (![dict[@"size"] isKindOfClass:NSNumber.class]) return nil; |
| @@ -1370,7 +1383,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 1370 | 1383 | if (![dict[@"teams_url"] isKindOfClass:NSString.class]) return nil; |
| 1371 | 1384 | if (![dict[@"description"] isKindOfClass:NSString.class]) return nil; |
| 1372 | 1385 | if (![dict[@"trees_url"] isKindOfClass:NSString.class]) return nil; |
| 1373 | - if (dict[@"updated_at"] && [dict[@"updated_at"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 1386 | + if (dict[@"updated_at"] && [dict[@"updated_at"] 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; | |
| 1387 | + if (dict[@"updated_at"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"updated_at"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"updated_at"] substringToIndex:10]]) return nil; | |
| 1374 | 1388 | if (![dict[@"updated_at"] isKindOfClass:NSString.class]) return nil; |
| 1375 | 1389 | if (![dict[@"url"] isKindOfClass:NSString.class]) return nil; |
| 1376 | 1390 | if (![dict[@"watchers"] isKindOfClass:NSNumber.class]) return nil; |
Mphpdefault / TopLevel.php+64 −0
| @@ -89,6 +89,10 @@ class TopLevel { | ||
| 89 | 89 | */ |
| 90 | 90 | public static function fromCreatedAt(string $value): DateTime { |
| 91 | 91 | $tmp = new DateTime($value); |
| 92 | + $errors = DateTime::getLastErrors(); | |
| 93 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 94 | + throw new Exception('Invalid date-time'); | |
| 95 | + } | |
| 92 | 96 | if (!is_a($tmp, 'DateTime')) { |
| 93 | 97 | throw new Exception('Attribute Error:TopLevel::'); |
| 94 | 98 | } |
| @@ -2082,6 +2086,10 @@ class Comment { | ||
| 2082 | 2086 | */ |
| 2083 | 2087 | public static function fromCreatedAt(string $value): DateTime { |
| 2084 | 2088 | $tmp = new DateTime($value); |
| 2089 | + $errors = DateTime::getLastErrors(); | |
| 2090 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2091 | + throw new Exception('Invalid date-time'); | |
| 2092 | + } | |
| 2085 | 2093 | if (!is_a($tmp, 'DateTime')) { |
| 2086 | 2094 | throw new Exception('Attribute Error:Comment::'); |
| 2087 | 2095 | } |
| @@ -2277,6 +2285,10 @@ class Comment { | ||
| 2277 | 2285 | */ |
| 2278 | 2286 | public static function fromUpdatedAt(string $value): DateTime { |
| 2279 | 2287 | $tmp = new DateTime($value); |
| 2288 | + $errors = DateTime::getLastErrors(); | |
| 2289 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 2290 | + throw new Exception('Invalid date-time'); | |
| 2291 | + } | |
| 2280 | 2292 | if (!is_a($tmp, 'DateTime')) { |
| 2281 | 2293 | throw new Exception('Attribute Error:Comment::'); |
| 2282 | 2294 | } |
| @@ -4299,6 +4311,10 @@ class Issue { | ||
| 4299 | 4311 | public static function fromClosedAt(?string $value): ?DateTime { |
| 4300 | 4312 | if (!is_null($value)) { |
| 4301 | 4313 | $tmp = new DateTime($value); |
| 4314 | + $errors = DateTime::getLastErrors(); | |
| 4315 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 4316 | + throw new Exception('Invalid date-time'); | |
| 4317 | + } | |
| 4302 | 4318 | if (!is_a($tmp, 'DateTime')) { |
| 4303 | 4319 | throw new Exception('Attribute Error:Issue::'); |
| 4304 | 4320 | } |
| @@ -4456,6 +4472,10 @@ class Issue { | ||
| 4456 | 4472 | */ |
| 4457 | 4473 | public static function fromCreatedAt(string $value): DateTime { |
| 4458 | 4474 | $tmp = new DateTime($value); |
| 4475 | + $errors = DateTime::getLastErrors(); | |
| 4476 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 4477 | + throw new Exception('Invalid date-time'); | |
| 4478 | + } | |
| 4459 | 4479 | if (!is_a($tmp, 'DateTime')) { |
| 4460 | 4480 | throw new Exception('Attribute Error:Issue::'); |
| 4461 | 4481 | } |
| @@ -5108,6 +5128,10 @@ class Issue { | ||
| 5108 | 5128 | */ |
| 5109 | 5129 | public static function fromUpdatedAt(string $value): DateTime { |
| 5110 | 5130 | $tmp = new DateTime($value); |
| 5131 | + $errors = DateTime::getLastErrors(); | |
| 5132 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 5133 | + throw new Exception('Invalid date-time'); | |
| 5134 | + } | |
| 5111 | 5135 | if (!is_a($tmp, 'DateTime')) { |
| 5112 | 5136 | throw new Exception('Attribute Error:Issue::'); |
| 5113 | 5137 | } |
| @@ -5923,6 +5947,10 @@ class Milestone { | ||
| 5923 | 5947 | */ |
| 5924 | 5948 | public static function fromCreatedAt(string $value): DateTime { |
| 5925 | 5949 | $tmp = new DateTime($value); |
| 5950 | + $errors = DateTime::getLastErrors(); | |
| 5951 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 5952 | + throw new Exception('Invalid date-time'); | |
| 5953 | + } | |
| 5926 | 5954 | if (!is_a($tmp, 'DateTime')) { |
| 5927 | 5955 | throw new Exception('Attribute Error:Milestone::'); |
| 5928 | 5956 | } |
| @@ -6073,6 +6101,10 @@ class Milestone { | ||
| 6073 | 6101 | public static function fromDueOn(?string $value): ?DateTime { |
| 6074 | 6102 | if (!is_null($value)) { |
| 6075 | 6103 | $tmp = new DateTime($value); |
| 6104 | + $errors = DateTime::getLastErrors(); | |
| 6105 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 6106 | + throw new Exception('Invalid date-time'); | |
| 6107 | + } | |
| 6076 | 6108 | if (!is_a($tmp, 'DateTime')) { |
| 6077 | 6109 | throw new Exception('Attribute Error:Milestone::'); |
| 6078 | 6110 | } |
| @@ -6465,6 +6497,10 @@ class Milestone { | ||
| 6465 | 6497 | */ |
| 6466 | 6498 | public static function fromUpdatedAt(string $value): DateTime { |
| 6467 | 6499 | $tmp = new DateTime($value); |
| 6500 | + $errors = DateTime::getLastErrors(); | |
| 6501 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 6502 | + throw new Exception('Invalid date-time'); | |
| 6503 | + } | |
| 6468 | 6504 | if (!is_a($tmp, 'DateTime')) { |
| 6469 | 6505 | throw new Exception('Attribute Error:Milestone::'); |
| 6470 | 6506 | } |
| @@ -7407,6 +7443,10 @@ class PayloadPullRequest { | ||
| 7407 | 7443 | */ |
| 7408 | 7444 | public static function fromClosedAt(string $value): DateTime { |
| 7409 | 7445 | $tmp = new DateTime($value); |
| 7446 | + $errors = DateTime::getLastErrors(); | |
| 7447 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 7448 | + throw new Exception('Invalid date-time'); | |
| 7449 | + } | |
| 7410 | 7450 | if (!is_a($tmp, 'DateTime')) { |
| 7411 | 7451 | throw new Exception('Attribute Error:PayloadPullRequest::'); |
| 7412 | 7452 | } |
| @@ -7649,6 +7689,10 @@ class PayloadPullRequest { | ||
| 7649 | 7689 | */ |
| 7650 | 7690 | public static function fromCreatedAt(string $value): DateTime { |
| 7651 | 7691 | $tmp = new DateTime($value); |
| 7692 | + $errors = DateTime::getLastErrors(); | |
| 7693 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 7694 | + throw new Exception('Invalid date-time'); | |
| 7695 | + } | |
| 7652 | 7696 | if (!is_a($tmp, 'DateTime')) { |
| 7653 | 7697 | throw new Exception('Attribute Error:PayloadPullRequest::'); |
| 7654 | 7698 | } |
| @@ -8319,6 +8363,10 @@ class PayloadPullRequest { | ||
| 8319 | 8363 | */ |
| 8320 | 8364 | public static function fromMergedAt(string $value): DateTime { |
| 8321 | 8365 | $tmp = new DateTime($value); |
| 8366 | + $errors = DateTime::getLastErrors(); | |
| 8367 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 8368 | + throw new Exception('Invalid date-time'); | |
| 8369 | + } | |
| 8322 | 8370 | if (!is_a($tmp, 'DateTime')) { |
| 8323 | 8371 | throw new Exception('Attribute Error:PayloadPullRequest::'); |
| 8324 | 8372 | } |
| @@ -8955,6 +9003,10 @@ class PayloadPullRequest { | ||
| 8955 | 9003 | */ |
| 8956 | 9004 | public static function fromUpdatedAt(string $value): DateTime { |
| 8957 | 9005 | $tmp = new DateTime($value); |
| 9006 | + $errors = DateTime::getLastErrors(); | |
| 9007 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 9008 | + throw new Exception('Invalid date-time'); | |
| 9009 | + } | |
| 8958 | 9010 | if (!is_a($tmp, 'DateTime')) { |
| 8959 | 9011 | throw new Exception('Attribute Error:PayloadPullRequest::'); |
| 8960 | 9012 | } |
| @@ -10490,6 +10542,10 @@ class BaseRepo { | ||
| 10490 | 10542 | */ |
| 10491 | 10543 | public static function fromCreatedAt(string $value): DateTime { |
| 10492 | 10544 | $tmp = new DateTime($value); |
| 10545 | + $errors = DateTime::getLastErrors(); | |
| 10546 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 10547 | + throw new Exception('Invalid date-time'); | |
| 10548 | + } | |
| 10493 | 10549 | if (!is_a($tmp, 'DateTime')) { |
| 10494 | 10550 | throw new Exception('Attribute Error:BaseRepo::'); |
| 10495 | 10551 | } |
| @@ -12428,6 +12484,10 @@ class BaseRepo { | ||
| 12428 | 12484 | */ |
| 12429 | 12485 | public static function fromPushedAt(string $value): DateTime { |
| 12430 | 12486 | $tmp = new DateTime($value); |
| 12487 | + $errors = DateTime::getLastErrors(); | |
| 12488 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 12489 | + throw new Exception('Invalid date-time'); | |
| 12490 | + } | |
| 12431 | 12491 | if (!is_a($tmp, 'DateTime')) { |
| 12432 | 12492 | throw new Exception('Attribute Error:BaseRepo::'); |
| 12433 | 12493 | } |
| @@ -13046,6 +13106,10 @@ class BaseRepo { | ||
| 13046 | 13106 | */ |
| 13047 | 13107 | public static function fromUpdatedAt(string $value): DateTime { |
| 13048 | 13108 | $tmp = new DateTime($value); |
| 13109 | + $errors = DateTime::getLastErrors(); | |
| 13110 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 13111 | + throw new Exception('Invalid date-time'); | |
| 13112 | + } | |
| 13049 | 13113 | if (!is_a($tmp, 'DateTime')) { |
| 13050 | 13114 | throw new Exception('Attribute Error:BaseRepo::'); |
| 13051 | 13115 | } |
Test case
2 generated files · +5 −1test/inputs/json/samples/null-safe.json
Mcplusplusdefault / quicktype.hpp+1 −1
| @@ -183,7 +183,7 @@ namespace quicktype { | ||
| 183 | 183 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 184 | 184 | if (j.find("address") != j.end() && j.at("address").is_null()) throw std::runtime_error("Unexpected null"); |
| 185 | 185 | x.set_address(get_stack_optional<Address>(j, "address")); |
| 186 | - if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 186 | + if (j.find("created_at") != j.end() && !std::regex_match(j.at("created_at").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"); | |
| 187 | 187 | if (j.find("created_at") != j.end() && j.at("created_at").is_null()) throw std::runtime_error("Unexpected null"); |
| 188 | 188 | x.set_created_at(get_stack_optional<std::string>(j, "created_at")); |
| 189 | 189 | x.set_name(j.at("name").get<std::string>()); |
Mphpdefault / TopLevel.php+4 −0
| @@ -201,6 +201,10 @@ class Item { | ||
| 201 | 201 | public static function fromCreatedAt(?string $value): ?DateTime { |
| 202 | 202 | if (!is_null($value)) { |
| 203 | 203 | $tmp = new DateTime($value); |
| 204 | + $errors = DateTime::getLastErrors(); | |
| 205 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 206 | + throw new Exception('Invalid date-time'); | |
| 207 | + } | |
| 204 | 208 | if (!is_a($tmp, 'DateTime')) { |
| 205 | 209 | throw new Exception('Attribute Error:Item::'); |
| 206 | 210 | } |
Test case
1 generated file · +4 −0test/inputs/schema/date-time-or-string.schema
Mschema-phpdefault / TopLevel.php+4 −0
| @@ -26,6 +26,10 @@ class TopLevel { | ||
| 26 | 26 | return Bar::from($value); /*enum*/ |
| 27 | 27 | } elseif (is_string($value)) { |
| 28 | 28 | $tmp = new DateTime($value); |
| 29 | + $errors = DateTime::getLastErrors(); | |
| 30 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 31 | + throw new Exception('Invalid date-time'); | |
| 32 | + } | |
| 29 | 33 | if (!is_a($tmp, 'DateTime')) { |
| 30 | 34 | throw new Exception('Attribute Error:TopLevel::'); |
| 31 | 35 | } |
Test case
3 generated files · +11 −2test/inputs/schema/date-time.schema
Mschema-cplusplusdefault / quicktype.hpp+1 −1
| @@ -146,7 +146,7 @@ namespace quicktype { | ||
| 146 | 146 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 147 | 147 | x.set_complex_union_array(j.at("complex-union-array").get<std::vector<ComplexUnionArrayElement>>()); |
| 148 | 148 | x.set_date(j.at("date").get<std::string>()); |
| 149 | - if (j.find("date-time") != j.end() && !std::regex_match(j.at("date-time").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 149 | + if (j.find("date-time") != j.end() && !std::regex_match(j.at("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"); | |
| 150 | 150 | x.set_date_time(j.at("date-time").get<std::string>()); |
| 151 | 151 | x.set_time(j.at("time").get<std::string>()); |
| 152 | 152 | x.set_union_array(j.at("union-array").get<std::vector<std::string>>()); |
Mschema-objective-cdefault / QTTopLevel.m+2 −1
| @@ -121,7 +121,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 121 | 121 | if (self = [super init]) { |
| 122 | 122 | if (![dict[@"complex-union-array"] isKindOfClass:NSArray.class]) return nil; |
| 123 | 123 | if (![dict[@"date"] isKindOfClass:NSString.class]) return nil; |
| 124 | - if (dict[@"date-time"] && [dict[@"date-time"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 124 | + if (dict[@"date-time"] && [dict[@"date-time"] 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; | |
| 125 | + if (dict[@"date-time"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"date-time"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"date-time"] substringToIndex:10]]) return nil; | |
| 125 | 126 | if (![dict[@"date-time"] isKindOfClass:NSString.class]) return nil; |
| 126 | 127 | if (![dict[@"time"] isKindOfClass:NSString.class]) return nil; |
| 127 | 128 | if (![dict[@"union-array"] isKindOfClass:NSArray.class]) return nil; |
Mschema-phpdefault / TopLevel.php+8 −0
| @@ -36,6 +36,10 @@ class TopLevel { | ||
| 36 | 36 | return ComplexUnionArray::from($value); /*enum*/ |
| 37 | 37 | } elseif (is_string($value)) { |
| 38 | 38 | $tmp = new DateTime($value); |
| 39 | + $errors = DateTime::getLastErrors(); | |
| 40 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 41 | + throw new Exception('Invalid date-time'); | |
| 42 | + } | |
| 39 | 43 | if (!is_a($tmp, 'DateTime')) { |
| 40 | 44 | throw new Exception('Attribute Error:TopLevel::'); |
| 41 | 45 | } |
| @@ -170,6 +174,10 @@ class TopLevel { | ||
| 170 | 174 | */ |
| 171 | 175 | public static function fromDateTime(string $value): DateTime { |
| 172 | 176 | $tmp = new DateTime($value); |
| 177 | + $errors = DateTime::getLastErrors(); | |
| 178 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 179 | + throw new Exception('Invalid date-time'); | |
| 180 | + } | |
| 173 | 181 | if (!is_a($tmp, 'DateTime')) { |
| 174 | 182 | throw new Exception('Attribute Error:TopLevel::'); |
| 175 | 183 | } |
Test case
3 generated files · +12 −3test/inputs/schema/optional-date-time.schema
Mschema-cplusplusdefault / quicktype.hpp+2 −2
| @@ -136,13 +136,13 @@ namespace quicktype { | ||
| 136 | 136 | if (!j.is_object()) throw std::runtime_error("Expected object"); |
| 137 | 137 | if (j.find("optional-date") != j.end() && j.at("optional-date").is_null()) throw std::runtime_error("Unexpected null"); |
| 138 | 138 | x.set_optional_date(get_stack_optional<std::string>(j, "optional-date")); |
| 139 | - if (j.find("optional-date-time") != j.end() && !std::regex_match(j.at("optional-date-time").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 139 | + if (j.find("optional-date-time") != j.end() && !std::regex_match(j.at("optional-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"); | |
| 140 | 140 | if (j.find("optional-date-time") != j.end() && j.at("optional-date-time").is_null()) throw std::runtime_error("Unexpected null"); |
| 141 | 141 | x.set_optional_date_time(get_stack_optional<std::string>(j, "optional-date-time")); |
| 142 | 142 | if (j.find("optional-time") != j.end() && j.at("optional-time").is_null()) throw std::runtime_error("Unexpected null"); |
| 143 | 143 | x.set_optional_time(get_stack_optional<std::string>(j, "optional-time")); |
| 144 | 144 | x.set_required_date(j.at("required-date").get<std::string>()); |
| 145 | - if (j.find("required-date-time") != j.end() && !std::regex_match(j.at("required-date-time").get<std::string>(), std::regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$"))) throw std::runtime_error("Expected date-time"); | |
| 145 | + if (j.find("required-date-time") != j.end() && !std::regex_match(j.at("required-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"); | |
| 146 | 146 | x.set_required_date_time(j.at("required-date-time").get<std::string>()); |
| 147 | 147 | x.set_required_time(j.at("required-time").get<std::string>()); |
| 148 | 148 | } |
Mschema-objective-cdefault / QTTopLevel.m+2 −1
| @@ -82,7 +82,8 @@ NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding enco | ||
| 82 | 82 | { |
| 83 | 83 | if (self = [super init]) { |
| 84 | 84 | if (![dict[@"required-date"] isKindOfClass:NSString.class]) return nil; |
| 85 | - if (dict[@"required-date-time"] && [dict[@"required-date-time"] rangeOfString:@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T" options:NSRegularExpressionSearch].location == NSNotFound) return nil; | |
| 85 | + if (dict[@"required-date-time"] && [dict[@"required-date-time"] 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; | |
| 86 | + if (dict[@"required-date-time"] && ![[[[NSISO8601DateFormatter new] stringFromDate:[[NSISO8601DateFormatter new] dateFromString:[[dict[@"required-date-time"] substringToIndex:10] stringByAppendingString:@"T00:00:00Z"]]] substringToIndex:10] isEqualToString:[dict[@"required-date-time"] substringToIndex:10]]) return nil; | |
| 86 | 87 | if (![dict[@"required-date-time"] isKindOfClass:NSString.class]) return nil; |
| 87 | 88 | if (![dict[@"required-time"] isKindOfClass:NSString.class]) return nil; |
| 88 | 89 | [self setValuesForKeysWithDictionary:dict]; |
Mschema-phpdefault / TopLevel.php+8 −0
| @@ -93,6 +93,10 @@ class TopLevel { | ||
| 93 | 93 | public static function fromOptionalDateTime(?string $value): ?DateTime { |
| 94 | 94 | if (!is_null($value)) { |
| 95 | 95 | $tmp = new DateTime($value); |
| 96 | + $errors = DateTime::getLastErrors(); | |
| 97 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 98 | + throw new Exception('Invalid date-time'); | |
| 99 | + } | |
| 96 | 100 | if (!is_a($tmp, 'DateTime')) { |
| 97 | 101 | throw new Exception('Attribute Error:TopLevel::'); |
| 98 | 102 | } |
| @@ -260,6 +264,10 @@ class TopLevel { | ||
| 260 | 264 | */ |
| 261 | 265 | public static function fromRequiredDateTime(string $value): DateTime { |
| 262 | 266 | $tmp = new DateTime($value); |
| 267 | + $errors = DateTime::getLastErrors(); | |
| 268 | + if ($errors && ($errors['warning_count'] || $errors['error_count'])) { | |
| 269 | + throw new Exception('Invalid date-time'); | |
| 270 | + } | |
| 263 | 271 | if (!is_a($tmp, 'DateTime')) { |
| 264 | 272 | throw new Exception('Attribute Error:TopLevel::'); |
| 265 | 273 | } |
No generated files match these filters.