summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/date.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-04-20 12:37:17 -0600
committerSimon Glass <sjg@chromium.org>2015-05-05 20:58:20 -0600
commit199e87c340bdd69a89e22f12e1201d67767e91a8 (patch)
treef7e7935465d4937cf550f49fde8d259d179b574c /drivers/rtc/date.c
parentc3ec646dde0428b96a67afd8c4c7b7db9dd4ca46 (diff)
downloadblackbird-obmc-uboot-199e87c340bdd69a89e22f12e1201d67767e91a8.tar.gz
blackbird-obmc-uboot-199e87c340bdd69a89e22f12e1201d67767e91a8.zip
dm: rtc: Rename gregorian day function
Change this function name to something more descriptive. Also return a failure code if it cannot calculate a correct value. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'drivers/rtc/date.c')
-rw-r--r--drivers/rtc/date.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/rtc/date.c b/drivers/rtc/date.c
index 15e6db06b2..2000565736 100644
--- a/drivers/rtc/date.c
+++ b/drivers/rtc/date.c
@@ -11,6 +11,7 @@
#include <common.h>
#include <command.h>
+#include <errno.h>
#include <rtc.h>
#if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
@@ -30,13 +31,15 @@ static int month_days[12] = {
/*
* This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
*/
-void GregorianDay(struct rtc_time * tm)
+int rtc_calc_weekday(struct rtc_time *tm)
{
int leapsToDate;
int lastYear;
int day;
int MonthOffset[] = { 0,31,59,90,120,151,181,212,243,273,304,334 };
+ if (tm->tm_year < 1753)
+ return -EINVAL;
lastYear=tm->tm_year-1;
/*
@@ -64,6 +67,8 @@ void GregorianDay(struct rtc_time * tm)
day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday;
tm->tm_wday=day%7;
+
+ return 0;
}
void to_tm(int tim, struct rtc_time * tm)
@@ -101,7 +106,7 @@ void to_tm(int tim, struct rtc_time * tm)
/*
* Determine the day of week
*/
- GregorianDay(tm);
+ rtc_calc_weekday(tm);
}
/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
OpenPOWER on IntegriCloud