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

Function dumptime

zdump.c:1166–1208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1164}
1165
1166static void
1167dumptime(register const struct tm *timeptr)
1168{
1169 static const char wday_name[][4] = {
1170 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1171 };
1172 static const char mon_name[][4] = {
1173 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1174 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1175 };
1176 register int lead;
1177 register int trail;
1178 int DIVISOR = 10;
1179
1180 /*
1181 ** The packaged localtime_rz and gmtime_r never put out-of-range
1182 ** values in tm_wday or tm_mon, but since this code might be compiled
1183 ** with other (perhaps experimental) versions, paranoia is in order.
1184 */
1185 printf("%s %s%3d %.2d:%.2d:%.2d ",
1186 ((0 <= timeptr->tm_wday
1187 && timeptr->tm_wday < sizeof wday_name / sizeof wday_name[0])
1188 ? wday_name[timeptr->tm_wday] : "???"),
1189 ((0 <= timeptr->tm_mon
1190 && timeptr->tm_mon < sizeof mon_name / sizeof mon_name[0])
1191 ? mon_name[timeptr->tm_mon] : "???"),
1192 timeptr->tm_mday, timeptr->tm_hour,
1193 timeptr->tm_min, timeptr->tm_sec);
1194 trail = timeptr->tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR;
1195 lead = timeptr->tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR +
1196 trail / DIVISOR;
1197 trail %= DIVISOR;
1198 if (trail < 0 && lead > 0) {
1199 trail += DIVISOR;
1200 --lead;
1201 } else if (lead < 0 && trail > 0) {
1202 trail -= DIVISOR;
1203 ++lead;
1204 }
1205 if (lead == 0)
1206 printf("%d", trail);
1207 else printf("%d%d", lead, ((trail < 0) ? -trail : trail));
1208}

Callers 1

showFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected