MCPcopy Index your code
hub / github.com/git/git / show_date_normal

Function show_date_normal

date.c:221–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local)
222{
223 struct {
224 unsigned int year:1,
225 date:1,
226 wday:1,
227 time:1,
228 seconds:1,
229 tz:1;
230 } hide = { 0 };
231
232 hide.tz = local || tz == human_tz;
233 hide.year = tm->tm_year == human_tm->tm_year;
234 if (hide.year) {
235 if (tm->tm_mon == human_tm->tm_mon) {
236 if (tm->tm_mday > human_tm->tm_mday) {
237 /* Future date: think timezones */
238 } else if (tm->tm_mday == human_tm->tm_mday) {
239 hide.date = hide.wday = 1;
240 } else if (tm->tm_mday + 5 > human_tm->tm_mday) {
241 /* Leave just weekday if it was a few days ago */
242 hide.date = 1;
243 }
244 }
245 }
246
247 /* Show "today" times as just relative times */
248 if (hide.wday) {
249 show_date_relative(time, buf);
250 return;
251 }
252
253 /*
254 * Always hide seconds for human-readable.
255 * Hide timezone if showing date.
256 * Hide weekday and time if showing year.
257 *
258 * The logic here is two-fold:
259 * (a) only show details when recent enough to matter
260 * (b) keep the maximum length "similar", and in check
261 */
262 if (human_tm->tm_year) {
263 hide.seconds = 1;
264 hide.tz |= !hide.date;
265 hide.wday = hide.time = !hide.year;
266 }
267
268 if (!hide.wday)
269 strbuf_addf(buf, "%.3s ", weekday_names[tm->tm_wday]);
270 if (!hide.date)
271 strbuf_addf(buf, "%.3s %d ", month_names[tm->tm_mon], tm->tm_mday);
272
273 /* Do we want AM/PM depending on locale? */
274 if (!hide.time) {
275 strbuf_addf(buf, "%02d:%02d", tm->tm_hour, tm->tm_min);
276 if (!hide.seconds)
277 strbuf_addf(buf, ":%02d", tm->tm_sec);
278 } else

Callers 1

show_dateFunction · 0.85

Calls 3

show_date_relativeFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_rtrimFunction · 0.85

Tested by

no test coverage detected