time.c (84a73014d86fd660822a20c032625e3afe99ca58) | time.c (00b912b0c88e690b1662067497182454357b18b0) |
---|---|
1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 988 unchanged lines hidden (view full) --- 997 ((year) % 100 != 0 || (year) % 400 == 0)) 998#define days_in_year(a) (leapyear(a) ? 366 : 365) 999#define days_in_month(a) (month_days[(a) - 1]) 1000 1001static int month_days[12] = { 1002 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 1003}; 1004 | 1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 988 unchanged lines hidden (view full) --- 997 ((year) % 100 != 0 || (year) % 400 == 0)) 998#define days_in_year(a) (leapyear(a) ? 366 : 365) 999#define days_in_month(a) (month_days[(a) - 1]) 1000 1001static int month_days[12] = { 1002 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 1003}; 1004 |
1005/* 1006 * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) 1007 */ 1008void GregorianDay(struct rtc_time * tm) 1009{ 1010 int leapsToDate; 1011 int lastYear; 1012 int day; 1013 int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; 1014 1015 lastYear = tm->tm_year - 1; 1016 1017 /* 1018 * Number of leap corrections to apply up to end of last year 1019 */ 1020 leapsToDate = lastYear / 4 - lastYear / 100 + lastYear / 400; 1021 1022 /* 1023 * This year is a leap year if it is divisible by 4 except when it is 1024 * divisible by 100 unless it is divisible by 400 1025 * 1026 * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 was 1027 */ 1028 day = tm->tm_mon > 2 && leapyear(tm->tm_year); 1029 1030 day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + 1031 tm->tm_mday; 1032 1033 tm->tm_wday = day % 7; 1034} 1035EXPORT_SYMBOL_GPL(GregorianDay); 1036 | |
1037void to_tm(int tim, struct rtc_time * tm) 1038{ 1039 register int i; 1040 register long hms, day; 1041 1042 day = tim / SECDAY; 1043 hms = tim % SECDAY; 1044 --- 14 unchanged lines hidden (view full) --- 1059 day -= days_in_month(i); 1060 days_in_month(FEBRUARY) = 28; 1061 tm->tm_mon = i; 1062 1063 /* Days are what is left over (+1) from all that. */ 1064 tm->tm_mday = day + 1; 1065 1066 /* | 1005void to_tm(int tim, struct rtc_time * tm) 1006{ 1007 register int i; 1008 register long hms, day; 1009 1010 day = tim / SECDAY; 1011 hms = tim % SECDAY; 1012 --- 14 unchanged lines hidden (view full) --- 1027 day -= days_in_month(i); 1028 days_in_month(FEBRUARY) = 28; 1029 tm->tm_mon = i; 1030 1031 /* Days are what is left over (+1) from all that. */ 1032 tm->tm_mday = day + 1; 1033 1034 /* |
1067 * Determine the day of week | 1035 * No-one uses the day of the week. |
1068 */ | 1036 */ |
1069 GregorianDay(tm); | 1037 tm->tm_wday = -1; |
1070} 1071EXPORT_SYMBOL(to_tm); 1072 1073/* 1074 * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit 1075 * result. 1076 */ 1077void div128_by_32(u64 dividend_high, u64 dividend_low, --- 50 unchanged lines hidden --- | 1038} 1039EXPORT_SYMBOL(to_tm); 1040 1041/* 1042 * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit 1043 * result. 1044 */ 1045void div128_by_32(u64 dividend_high, u64 dividend_low, --- 50 unchanged lines hidden --- |