Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 139226
b: refs/heads/master
c: 78d89ef
h: refs/heads/master
v: v3
  • Loading branch information
Andrew Morton authored and Linus Torvalds committed Apr 1, 2009
1 parent 8988266 commit 3cf3cda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 47367a3ba425d70467af0009782098235ddbf204
refs/heads/master: 78d89ef40c2ff7265df077e20c4d76be7d415204
7 changes: 3 additions & 4 deletions trunk/drivers/rtc/rtc-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ static const unsigned short rtc_ydays[2][13] = {
};

#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))

/*
* The number of days in the month.
*/
int rtc_month_days(unsigned int month, unsigned int year)
{
return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1);
return rtc_days_in_month[month] + (is_leap_year(year) && month == 1);
}
EXPORT_SYMBOL(rtc_month_days);

Expand All @@ -42,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days);
*/
int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
{
return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
return rtc_ydays[is_leap_year(year)][month] + day-1;
}
EXPORT_SYMBOL(rtc_year_days);

Expand All @@ -66,7 +65,7 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
- LEAPS_THRU_END_OF(1970 - 1);
if (days < 0) {
year -= 1;
days += 365 + LEAP_YEAR(year);
days += 365 + is_leap_year(year);
}
tm->tm_year = year - 1900;
tm->tm_yday = days + 1;
Expand Down
6 changes: 6 additions & 0 deletions trunk/include/linux/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct rtc_pll_info {

#ifdef __KERNEL__

#include <linux/types.h>
#include <linux/interrupt.h>

extern int rtc_month_days(unsigned int month, unsigned int year);
Expand Down Expand Up @@ -232,6 +233,11 @@ int rtc_register(rtc_task_t *task);
int rtc_unregister(rtc_task_t *task);
int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg);

static inline bool is_leap_year(unsigned int year)
{
return (!(year % 4) && (year % 100)) || !(year % 400);
}

#endif /* __KERNEL__ */

#endif /* _LINUX_RTC_H_ */

0 comments on commit 3cf3cda

Please sign in to comment.