1#ifndef RITSUKO_IS_DATE_TIME_HPP
2#define RITSUKO_IS_DATE_TIME_HPP
24 for (
size_t p = 0; p < 4; ++p) {
25 if (!std::isdigit(ptr[p])) {
34 for (
size_t p = 5; p <= 6; ++p) {
35 if (!std::isdigit(ptr[p])) {
43 }
else if (ptr[5] !=
'0') {
51 for (
size_t p = 8; p <= 9; ++p) {
52 if (!std::isdigit(ptr[p])) {
60 }
else if (ptr[8] >
'3') {
73inline bool is_date(
const char* ptr,
size_t len) {
83inline bool okay_hours(
const char* ptr,
size_t offset) {
84 for (
size_t i = 0; i < 2; ++i) {
85 if (!std::isdigit(ptr[offset + i])) {
90 if (ptr[offset] ==
'2') {
91 if (ptr[offset + 1] >
'4') {
94 }
else if (ptr[offset] >
'2') {
101inline bool okay_minutes(
const char* ptr,
size_t offset) {
102 for (
size_t i = 0; i < 2; ++i) {
103 if (!std::isdigit(ptr[offset + i])) {
108 if (ptr[offset] >
'5') {
115inline bool okay_seconds(
const char* ptr,
size_t offset) {
116 for (
size_t i = 0; i < 2; ++i) {
117 if (!std::isdigit(ptr[offset + i])) {
122 if (ptr[offset] ==
'6') {
123 if (ptr[offset + 1] >
'0') {
126 }
else if (ptr[offset] >
'5') {
153 if (!okay_hours(ptr, 1)) {
159 if (!okay_minutes(ptr, 4)) {
165 if (!okay_seconds(ptr, 7)) {
170 bool zero_fraction =
true;
172 constexpr size_t start = 10;
173 size_t counter = start;
174 while (counter < len && std::isdigit(ptr[counter])) {
175 if (ptr[counter] !=
'0') {
176 zero_fraction =
false;
180 if (counter == start) {
183 shift = counter - start + 1;
187 if (ptr[1] ==
'2' && ptr[2] ==
'4') {
188 if (ptr[4] !=
'0' || ptr[5] !=
'0' || ptr[7] !=
'0' || ptr[8] !=
'0' || !zero_fraction) {
194 if (ptr[7] ==
'6' && ptr[8] ==
'0') {
195 if (!zero_fraction) {
201 size_t tz_start = 9 + shift;
202 if (tz_start >= len) {
205 if (ptr[tz_start] ==
'Z') {
206 return (len == tz_start + 1);
209 if (len != tz_start + 6) {
212 if (ptr[tz_start] !=
'+' && ptr[tz_start] !=
'-') {
215 if (!okay_hours(ptr, tz_start + 1)) {
218 if (ptr[tz_start + 3] !=
':') {
221 if (!okay_minutes(ptr, tz_start + 4)) {
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
bool is_date_prefix(const char *ptr)
Definition is_date_time.hpp:23
bool is_rfc3339(const char *ptr, size_t len)
Definition is_date_time.hpp:237
bool is_rfc3339_suffix(const char *ptr, size_t len)
Definition is_date_time.hpp:147
bool is_date(const char *ptr, size_t len)
Definition is_date_time.hpp:73