aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/rtc/rtc-lib.c7
-rw-r--r--include/linux/rtc.h6
2 files changed, 9 insertions, 4 deletions
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index dd70bf73ce9d..773851f338b8 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -26,14 +26,13 @@ static const unsigned short rtc_ydays[2][13] = {
26}; 26};
27 27
28#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) 28#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
29#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
30 29
31/* 30/*
32 * The number of days in the month. 31 * The number of days in the month.
33 */ 32 */
34int rtc_month_days(unsigned int month, unsigned int year) 33int rtc_month_days(unsigned int month, unsigned int year)
35{ 34{
36 return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1); 35 return rtc_days_in_month[month] + (is_leap_year(year) && month == 1);
37} 36}
38EXPORT_SYMBOL(rtc_month_days); 37EXPORT_SYMBOL(rtc_month_days);
39 38
@@ -42,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days);
42 */ 41 */
43int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) 42int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
44{ 43{
45 return rtc_ydays[LEAP_YEAR(year)][month] + day-1; 44 return rtc_ydays[is_leap_year(year)][month] + day-1;
46} 45}
47EXPORT_SYMBOL(rtc_year_days); 46EXPORT_SYMBOL(rtc_year_days);
48 47
@@ -66,7 +65,7 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
66 - LEAPS_THRU_END_OF(1970 - 1); 65 - LEAPS_THRU_END_OF(1970 - 1);
67 if (days < 0) { 66 if (days < 0) {
68 year -= 1; 67 year -= 1;
69 days += 365 + LEAP_YEAR(year); 68 days += 365 + is_leap_year(year);
70 } 69 }
71 tm->tm_year = year - 1900; 70 tm->tm_year = year - 1900;
72 tm->tm_yday = days + 1; 71 tm->tm_yday = days + 1;
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 4046b75563c1..60f88a7fb13d 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -99,6 +99,7 @@ struct rtc_pll_info {
99 99
100#ifdef __KERNEL__ 100#ifdef __KERNEL__
101 101
102#include <linux/types.h>
102#include <linux/interrupt.h> 103#include <linux/interrupt.h>
103 104
104extern int rtc_month_days(unsigned int month, unsigned int year); 105extern int rtc_month_days(unsigned int month, unsigned int year);
@@ -232,6 +233,11 @@ int rtc_register(rtc_task_t *task);
232int rtc_unregister(rtc_task_t *task); 233int rtc_unregister(rtc_task_t *task);
233int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg); 234int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg);
234 235
236static inline bool is_leap_year(unsigned int year)
237{
238 return (!(year % 4) && (year % 100)) || !(year % 400);
239}
240
235#endif /* __KERNEL__ */ 241#endif /* __KERNEL__ */
236 242
237#endif /* _LINUX_RTC_H_ */ 243#endif /* _LINUX_RTC_H_ */