MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / format

Method format

src/common/TimeZoneUtil.cpp:544–584  ·  view source on GitHub ↗

Format a time zone to string, as offset or region.

Source from the content-addressed store, hash-verified

542
543// Format a time zone to string, as offset or region.
544unsigned TimeZoneUtil::format(char* buffer, size_t bufferSize, USHORT timeZone, bool fallback, SLONG offset)
545{
546 char* p = buffer;
547
548 if (fallback)
549 {
550 if (offset == NO_OFFSET)
551 p += fb_utils::snprintf(p, bufferSize - (p - buffer), "%s", GMT_FALLBACK);
552 else
553 {
554 if (offset != 0)
555 *p++ = offset < 0 ? '-' : '+';
556
557 if (offset < 0)
558 offset = -offset;
559
560 int minutes = offset % 60;
561 offset /= 60;
562 p += fb_utils::snprintf(p, bufferSize - (p - buffer), "%02d:%02d", offset, minutes);
563 }
564 }
565 else if (isOffset(timeZone))
566 {
567 SSHORT displacement = offsetZoneToDisplacement(timeZone);
568
569 *p++ = displacement < 0 ? '-' : '+';
570
571 if (displacement < 0)
572 displacement = -displacement;
573
574 p += fb_utils::snprintf(p, bufferSize - 1, "%2.2d:%2.2d", displacement / 60, displacement % 60);
575 }
576 else
577 {
578 strncpy(buffer, getDesc(timeZone)->getAsciiName(), bufferSize);
579
580 p += strlen(buffer);
581 }
582
583 return p - buffer;
584}
585
586// Returns if the offsets are valid.
587bool TimeZoneUtil::isValidOffset(int sign, unsigned tzh, unsigned tzm)

Callers 6

gen_csvMethod · 0.80
runMethod · 0.80
__str__Method · 0.80
__str__Method · 0.80
__str__Method · 0.80
__str__Method · 0.80

Calls 5

isOffsetFunction · 0.85
offsetZoneToDisplacementFunction · 0.85
getDescFunction · 0.85
getAsciiNameMethod · 0.80
snprintfFunction · 0.70

Tested by

no test coverage detected