MCPcopy Create free account
hub / github.com/SmingHub/Sming / format

Method format

Sming/Core/DateTime.cpp:476–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476String DateTime::format(const char* sFormat, const ZoneInfo* zone) const
477{
478 if(sFormat == nullptr) {
479 return nullptr;
480 }
481
482 String sReturn;
483
484 char c;
485 while((c = *sFormat++) != '\0') {
486 if(c != '%') {
487 // Normal character
488 sReturn += c;
489 continue;
490 }
491
492 if(*sFormat == '\0') {
493 // Ignore % as last character
494 break;
495 }
496
497 c = *sFormat++;
498 char timesep{'\0'};
499 if(c == ':') {
500 timesep = c;
501 c = *sFormat++;
502 }
503 switch(c) {
504 // Timezone offset from UTC with or without ':' separator
505 case 'z':
506 if(zone) {
507 sReturn += zone->getOffsetString(timesep);
508 }
509 break;
510 // Timezone tag
511 case 'Z':
512 if(zone) {
513 sReturn += zone->tag;
514 }
515 break;
516 // Year (not implemented: EY, Oy, Ey, EC, G, g)
517 case 'Y': // Full year as a decimal number, e.g. 2018
518 sReturn += Year;
519 break;
520 case 'y': // Year, last 2 digits as a decimal number [00..99]
521 sReturn.concat(Year % 100, DEC, 2);
522 break;
523 case 'C': // Year, first 2 digits as a decimal number [00..99]
524 sReturn.concat(Year / 100, DEC, 2);
525 break;
526 // Month (not implemented: Om)
527 case 'b': // Abbreviated month name, e.g. Oct (always English)
528 case 'h': // Synonym of b
529 sReturn.concat(CStringArray(localeMonthNames)[Month], 3);
530 break;
531 case 'B': // Full month name, e.g. October (always English)
532 sReturn += CStringArray(localeMonthNames)[Month];
533 break;

Callers 11

showTimeFunction · 0.45
checkIsoTimesMethod · 0.45
roleFunction · 0.45
DocumentRoleFunction · 0.45
memanalyzer.pyFile · 0.45
memanalyzer.pyFile · 0.45
memanalyzer.pyFile · 0.45
onCommandMethod · 0.45
getStatLineMethod · 0.45
fileSystemFormatFunction · 0.45

Calls 3

CStringArrayClass · 0.85
getOffsetStringMethod · 0.80
concatMethod · 0.45

Tested by

no test coverage detected