lib/date: Make rtc_mktime and mktime64 Y2038-ready

We currently overflow due to wrong types used internally in rtc_mktime,
on all platforms, and we return a too small type on 32-bit.

One consumer that directly benefits from this is mktime64. Many others
may still store the result in a wrong type.

While at it, drop the redundant cast of mon in rtc_mktime (obsoleted by
714209832db1).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
diff --git a/lib/date.c b/lib/date.c
index c589d9e..e3d2245 100644
--- a/lib/date.c
+++ b/lib/date.c
@@ -71,19 +71,16 @@
  * -year / 100 + year / 400 terms, and add 10.]
  *
  * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines where long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
  */
-unsigned long rtc_mktime(const struct rtc_time *tm)
+time64_t rtc_mktime(const struct rtc_time *tm)
 {
 	int mon = tm->tm_mon;
 	int year = tm->tm_year;
-	int days, hours;
+	unsigned long days;
+	time64_t hours;
 
 	mon -= 2;
-	if (0 >= (int)mon) {	/* 1..12 -> 11, 12, 1..10 */
+	if (0 >= mon) {		/* 1..12 -> 11, 12, 1..10 */
 		mon += 12;	/* Puts Feb last since it has leap day */
 		year -= 1;
 	}
@@ -109,5 +106,5 @@
 	time.tm_min = min;
 	time.tm_sec = sec;
 
-	return (time64_t)rtc_mktime((const struct rtc_time *)&time);
+	return rtc_mktime((const struct rtc_time *)&time);
 }