shithub: scc

Download patch

ref: ef9e03046d35d4d0a3a73316e4675470228ebc98
parent: 3ffe44ba0b84317b63bfcdbfe4bc1418f0ae59ca
author: Naveen Narayanan <[email protected]>
date: Tue Sep 29 06:29:57 EDT 2020

libc: Fix first() in strftime.c

We consider the days of the week to be circular in nature starting
with SUN - 0 through SAT - 6. Hence, we have to consider two use
cases:
1. When the difference between the respective day and the newyear
   doesn't wrap around Eg: day = WED newyear = TUE
2. When the difference between the respective day and the newyear
   wraps around Eg: day = TUE newyear = FRI

This patch fixes the algorithm by considering both usecases.

--- a/src/libc/time/strftime.c
+++ b/src/libc/time/strftime.c
@@ -25,7 +25,9 @@
 	ny = _newyear(year);
 	if (ny == day)
 		return 0;
-	return 7 - (ny + day);
+	if (day - ny < 0)
+		return 7 - (ny - day);
+	return day - ny;
 }