30 #include <linux/time.h>
31 #include <linux/module.h>
39 return (year) % 4 == 0 && ((
year) % 100 != 0 || (year) % 400 == 0);
43 static long math_div(
long a,
long b)
45 return a / b - (a % b < 0);
49 static long leaps_between(
long y1,
long y2)
51 long leaps1 = math_div(y1 - 1, 4) - math_div(y1 - 1, 100)
52 + math_div(y1 - 1, 400);
53 long leaps2 = math_div(y2 - 1, 4) - math_div(y2 - 1, 100)
54 + math_div(y2 - 1, 400);
55 return leaps2 - leaps1;
59 static const unsigned short __mon_yday[2][13] = {
61 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
63 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
66 #define SECS_PER_HOUR (60 * 60)
67 #define SECS_PER_DAY (SECS_PER_HOUR * 24)
80 const unsigned short *
ip;
100 result->
tm_wday = (4 + days) % 7;
106 while (days < 0 || days >= (
__isleap(y) ? 366 : 365)) {
108 long yg = y + math_div(days, 365);
111 days -= (yg -
y) * 365 + leaps_between(y, yg);
120 for (y = 11; days < ip[
y]; y--)