MCPcopy Create free account
hub / github.com/eggert/tz / format_utc_offset

Function format_utc_offset

zdump.c:935–959  ·  view source on GitHub ↗

Store into BUF, of size SIZE, a formatted UT offset for the localtime *TM corresponding to time T. Use ISO 8601 format +HHMMSS, or -HHMMSS for timestamps west of Greenwich; use the format -00 for unknown UT offsets. If the hour needs more than two digits to represent, extend the length of HH as needed. Otherwise, omit SS if SS is zero, and omit MM too if MM is also zero. Re

Source from the content-addressed store, hash-verified

933 the length that the string would have been if it had fit; do not
934 overrun the output buffer. */
935static int
936format_utc_offset(char *buf, ptrdiff_t size, struct tm const *tm, time_t t)
937{
938 long off = gmtoff(tm, &t, NULL);
939 char sign = ((off < 0
940 || (off == 0
941 && (*abbr(tm) == '-' || strcmp(abbr(tm), "zzz") == 0)))
942 ? '-' : '+');
943 long hh;
944 int mm, ss;
945 if (off < 0)
946 {
947 if (off == LONG_MIN)
948 return -1;
949 off = -off;
950 }
951 ss = off % 60;
952 mm = off / 60 % 60;
953 hh = off / 60 / 60;
954 return (ss || 100 <= hh
955 ? snprintf(buf, size, "%c%02ld%02d%02d", sign, hh, mm, ss)
956 : mm
957 ? snprintf(buf, size, "%c%02ld%02d", sign, hh, mm)
958 : snprintf(buf, size, "%c%02ld", sign, hh));
959}
960
961/* Store into BUF (of size SIZE) a quoted string representation of P.
962 If the representation's length is less than SIZE, return the

Callers 1

istrftimeFunction · 0.85

Calls 2

gmtoffFunction · 0.85
abbrFunction · 0.85

Tested by

no test coverage detected