MCPcopy Create free account
hub / github.com/GothenburgBitFactory/timewarrior / initializeInformalTime

Method initializeInformalTime

src/DatetimeParser.cpp:2516–2616  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// 8am 8a 8:30am 8:30a 8:30 8:30:00 \d+ [ : \d{2} ] [ am | a | pm | p ] [ ! && ! && !: && !+ && !- ]

Source from the content-addressed store, hash-verified

2514// \d+ [ : \d{2} ] [ am | a | pm | p ] [ !<alpha> && !<digit> && !: && !+ && !- ]
2515//
2516bool DatetimeParser::initializeInformalTime (Pig& pig)
2517{
2518 auto checkpoint = pig.cursor ();
2519
2520 int digit = 0;
2521 bool needDesignator = true; // Require am/pm.
2522 bool haveDesignator = false; // Provided am/pm.
2523 if (pig.getDigit (digit))
2524 {
2525 int hours = digit;
2526 if (pig.getDigit (digit))
2527 hours = 10 * hours + digit;
2528
2529 int minutes = 0;
2530 int seconds = 0;
2531 if (pig.skip (':'))
2532 {
2533 if (! pig.getDigit2 (minutes))
2534 {
2535 pig.restoreTo (checkpoint);
2536 return false;
2537 }
2538
2539 if (pig.skip (':'))
2540 {
2541 if (! pig.getDigits (seconds))
2542 {
2543 pig.restoreTo (checkpoint);
2544 return false;
2545 }
2546 }
2547
2548 needDesignator = false;
2549 }
2550
2551 if (pig.skipLiteral ("am") ||
2552 pig.skipLiteral ("a"))
2553 {
2554 haveDesignator = true;
2555 if (hours == 12)
2556 hours = 0;
2557 }
2558
2559 else if (pig.skipLiteral ("pm") ||
2560 pig.skipLiteral ("p"))
2561 {
2562 // Note: '12pm is an exception:
2563 // 12am = 0h
2564 // 11am = 11h + 12h
2565 // 12pm = 12h
2566 // 1pm = 1h + 12h
2567 if (hours != 12)
2568 hours += 12;
2569
2570 haveDesignator = true;
2571 }
2572
2573 // Informal time needs to be terminated.

Callers

nothing calls this directly

Calls 1

skipMethod · 0.80

Tested by

no test coverage detected