mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Victor <andrew@sanpeople.com>
To: linux-kernel@vger.kernel.org
Cc: alessandro.zummo@towertech.it, akpm@osdl.org
Subject: [PATCH[ RTC: Add rtc_year_days() to calculate tm_yday
Date: 07 Jun 2006 20:26:09 +0200	[thread overview]
Message-ID: <1149704768.20154.95.camel@fuzzie.sanpeople.com> (raw)

RTC: Add exported function rtc_year_days() to calculate the tm_yday
value.


Signed-off-by: Andrew Victor <andrew@sanpeople.com>
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>


diff -urN -x CVS linux-2.6.17-rc6/drivers/rtc/rtc-lib.c linux-2.6.17-rc/drivers/rtc/rtc-lib.c
--- linux-2.6.17-rc6/drivers/rtc/rtc-lib.c	Tue Jun  6 10:28:05 2006
+++ linux-2.6.17-rc/drivers/rtc/rtc-lib.c	Wed Jun  7 11:27:49 2006
@@ -18,15 +18,34 @@
 	31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
 };
 
+static const unsigned short rtc_ydays[2][13] = {
+	/* Normal years */
+	{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
+	/* Leap years */
+	{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
+}; 
+
 #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);
 }
 EXPORT_SYMBOL(rtc_month_days);
 
+/* 
+ * The number of days since January 1. (0 to 365)
+ */
+int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
+{
+	return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
+}
+EXPORT_SYMBOL(rtc_year_days);
+
 /*
  * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
  */
diff -urN -x CVS linux-2.6.17-rc6/include/linux/rtc.h linux-2.6.17-rc/include/linux/rtc.h
--- linux-2.6.17-rc6/include/linux/rtc.h	Tue Jun  6 10:28:30 2006
+++ linux-2.6.17-rc/include/linux/rtc.h	Wed Jun  7 11:24:45 2006
@@ -102,6 +102,7 @@
 #include <linux/interrupt.h>
 
 extern int rtc_month_days(unsigned int month, unsigned int year);
+extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year);
 extern int rtc_valid_tm(struct rtc_time *tm);
 extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
 extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm);




             reply	other threads:[~2006-06-07 18:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-07 18:26 Andrew Victor [this message]
2006-06-07 19:33 ` Russell King
2006-06-07 22:48   ` H. Peter Anvin
2006-06-08  6:43   ` Andrew Victor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1149704768.20154.95.camel@fuzzie.sanpeople.com \
    --to=andrew@sanpeople.com \
    --cc=akpm@osdl.org \
    --cc=alessandro.zummo@towertech.it \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®