MCPcopy Create free account
hub / github.com/bytedance/bolt / tryParseTimeString

Function tryParseTimeString

bolt/type/TimestampConversion.cpp:394–498  ·  view source on GitHub ↗

String format is hh:mm:ss.microseconds (microseconds are optional). ISO 8601

Source from the content-addressed store, hash-verified

392// String format is hh:mm:ss.microseconds (microseconds are optional).
393// ISO 8601
394bool tryParseTimeString(
395 const char* buf,
396 size_t len,
397 size_t& pos,
398 int64_t& result,
399 int32_t mode) {
400 int32_t hour = -1, min = -1, sec = -1, micros = -1;
401 pos = 0;
402
403 if (len == 0) {
404 return false;
405 }
406
407 // Skip leading spaces.
408 while (pos < len && characterIsSpace(buf[pos])) {
409 pos++;
410 }
411
412 if (pos >= len) {
413 return false;
414 }
415
416 if (!characterIsDigit(buf[pos])) {
417 return false;
418 }
419
420 if (!parseDoubleDigit(buf, len, pos, hour)) {
421 return false;
422 }
423 if (hour < 0 || hour >= 24) {
424 return false;
425 }
426
427 // No minute and second.
428 if ((mode & ParseMode::kNonStandardCast) && pos == len) {
429 result = fromTime(hour, 0, 0, 0);
430 return true;
431 }
432
433 if (pos >= len) {
434 return false;
435 }
436
437 // Fetch the separator.
438 int sep = buf[pos++];
439 if (sep != ':') {
440 // Invalid separator.
441 return false;
442 }
443
444 if (!parseDoubleDigit(buf, len, pos, min)) {
445 return false;
446 }
447 if (min < 0 || min >= 60) {
448 return false;
449 }
450
451 // No second.

Callers 3

tryParseTimestampStringFunction · 0.85
fromTimestampStringFunction · 0.85

Calls 4

characterIsSpaceFunction · 0.85
parseDoubleDigitFunction · 0.85
fromTimeFunction · 0.85
characterIsDigitFunction · 0.70

Tested by

no test coverage detected