]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/rtc/date.c
dm: rtc: Rename gregorian day function
[karo-tx-uboot.git] / drivers / rtc / date.c
index a83a7235ab619a333b41c3cd74eb63ee0648eb19..20005657360765e7e3c92a041ce25a0faef403e7 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2001
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -27,6 +11,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <errno.h>
 #include <rtc.h>
 
 #if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
@@ -36,8 +21,8 @@
 #define SECDAY                 86400L
 #define SECYR                  (SECDAY * 365)
 #define        leapyear(year)          ((year) % 4 == 0)
-#define        days_in_year(a)         (leapyear(a) ? 366 : 365)
-#define        days_in_month(a)        (month_days[(a) - 1])
+#define        days_in_year(a)         (leapyear(a) ? 366 : 365)
+#define        days_in_month(a)        (month_days[(a) - 1])
 
 static int month_days[12] = {
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
@@ -46,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;
 
        /*
@@ -80,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)
@@ -117,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.