[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-commit] [2391] Deleted function iso_weeknum().
From: |
Mike Rice |
Subject: |
[avr-libc-commit] [2391] Deleted function iso_weeknum(). |
Date: |
Fri, 03 May 2013 20:53:06 +0000 |
Revision: 2391
http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2391
Author: swfltek
Date: 2013-05-03 20:53:06 +0000 (Fri, 03 May 2013)
Log Message:
-----------
Deleted function iso_weeknum(). Added function iso_week_date() and its
re-entrant counterpart, and modified strftime to use iso_week_date_r().
Modified Paths:
--------------
trunk/avr-libc/include/time.h
trunk/avr-libc/libc/time/Files.am
trunk/avr-libc/libc/time/strftime.c
Added Paths:
-----------
trunk/avr-libc/libc/time/iso_week_date.c
trunk/avr-libc/libc/time/iso_week_date_r.c
Removed Paths:
-------------
trunk/avr-libc/libc/time/iso_weeknum.c
Modified: trunk/avr-libc/include/time.h
===================================================================
--- trunk/avr-libc/include/time.h 2013-05-03 16:13:03 UTC (rev 2390)
+++ trunk/avr-libc/include/time.h 2013-05-03 20:53:06 UTC (rev 2391)
@@ -373,21 +373,34 @@
uint8_t week_of_year(const struct tm * timeptr, uint8_t start);
/**
- Return the ISO 8601 week of year. Returned values are...
+ Return the calendar week of month, where the first week is considered
to begin on the
+ day of week specified by 'start'. The returned value may range from
zero to 5.
+ */
+ uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
- 0 : The final week of the previous year.
- 1 ... 53 : The week number in the current year.
- 54 : The first week of the following year.
+ /**
+ Structure which represents a date as a year, week number of that year,
and day of week.
+ See http://en.wikipedia.org/wiki/ISO_week_date for more information.
*/
- uint8_t iso_weeknum(const struct tm * timeptr);
+ struct week_date{
+ int year;
+ int week;
+ int day;
+ };
/**
- Return the calendar week of month, where the first week is considered
to begin on the
- day of week specified by 'start'. The returned value may range from
zero to 5.
+ Return a week_date structure with the ISO_8601 week based date
corresponding to the given
+ year and day of year. See http://en.wikipedia.org/wiki/ISO_week_date
for more
+ information.
*/
- uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
+ struct week_date * iso_week_date( int year, int yday);
/**
+ Re-entrant version of iso-week_date.
+ */
+ void iso_week_date_r( int year, int yday, struct week_date *);
+
+ /**
Convert a Y2K time stamp into a FAT file system time stamp.
*/
uint32_t fatfs_time(const struct tm * timeptr);
Modified: trunk/avr-libc/libc/time/Files.am
===================================================================
--- trunk/avr-libc/libc/time/Files.am 2013-05-03 16:13:03 UTC (rev 2390)
+++ trunk/avr-libc/libc/time/Files.am 2013-05-03 20:53:06 UTC (rev 2391)
@@ -43,7 +43,8 @@
gmtime_r.c \
isLeap.c \
isotime.c \
- iso_weeknum.c \
+ iso_week_date.c \
+ iso_week_date_r.c \
isotime_r.c \
lm_sidereal.c \
localtime.c \
Added: trunk/avr-libc/libc/time/iso_week_date.c
===================================================================
--- trunk/avr-libc/libc/time/iso_week_date.c (rev 0)
+++ trunk/avr-libc/libc/time/iso_week_date.c 2013-05-03 20:53:06 UTC (rev
2391)
@@ -0,0 +1,43 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $ID$ */
+
+#include <time.h>
+
+extern char *__asc_store;
+
+struct week_date *
+iso_week_date(int y, int yday)
+{
+ struct week_date *iso;
+
+ iso = (struct week_date *) __asc_store;
+ iso_week_date_r(y, yday, iso);
+ return iso;
+}
Property changes on: trunk/avr-libc/libc/time/iso_week_date.c
___________________________________________________________________
Added: svn:keywords:id
+
Added: trunk/avr-libc/libc/time/iso_week_date_r.c
===================================================================
--- trunk/avr-libc/libc/time/iso_week_date_r.c (rev 0)
+++ trunk/avr-libc/libc/time/iso_week_date_r.c 2013-05-03 20:53:06 UTC (rev
2391)
@@ -0,0 +1,95 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $ID$ */
+
+/*
+ Compute the ISO 8601 week date corresponding to the given year and day of
year.
+*/
+
+#include <time.h>
+
+void
+iso_week_date_r(int y, int yday, struct week_date * iso)
+{
+ uint16_t years, n, wday;
+ int weeknum;
+
+ iso->year = y;
+
+ /* compute days elapsed since epoch */
+ years = y - 2000;
+ n = 365 * years + yday;
+ if (years) {
+ n++; /* epoch was a leap year */
+ n += (years - 1) / 4;
+ if (years > 100)
+ n--;
+ }
+
+ /* compute ISO8601 day of week (1 ... 7, Monday = 1) */
+ wday = n + 6; /* epoch was a Saturday */
+ wday %= 7;
+ if (wday == 0)
+ wday = 7;
+
+ iso->day = wday;
+
+ /* compute tentative week number */
+ weeknum = yday + 11 - wday;
+ weeknum /= 7;
+
+ /* if 53, it could be week 1 of the following year */
+ if (weeknum == 53) {
+
+ /* determine final yday of this year, 364 or 365 */
+ n = 364 + is_leap_year(y);
+
+ /* compute yday of this weeks Thursday */
+ wday--; /* revert to zero based week */
+ yday -= wday; /* yday of this weeks Monday */
+ yday += 3; /* yday of this weeks Thursday */
+
+ /*
+ * If this weeks Thursday is not in this year, its week 1 of
+ * the following year
+ */
+ if (yday > (int) n) {
+ iso->year++;
+ weeknum = 1;
+ }
+ }
+ iso->week = weeknum;
+
+ /* if zero, it is final week of previous year */
+ if (weeknum == 0) {
+ y = y - 1;
+ iso_week_date_r(y, 364 + is_leap_year(y), iso);
+ iso->day = wday;
+ }
+}
Property changes on: trunk/avr-libc/libc/time/iso_week_date_r.c
___________________________________________________________________
Added: svn:keywords:id
+
Deleted: trunk/avr-libc/libc/time/iso_weeknum.c
===================================================================
--- trunk/avr-libc/libc/time/iso_weeknum.c 2013-05-03 16:13:03 UTC (rev
2390)
+++ trunk/avr-libc/libc/time/iso_weeknum.c 2013-05-03 20:53:06 UTC (rev
2391)
@@ -1,67 +0,0 @@
-/*
- * (c)2012 Michael Duane Rice All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer. Redistributions in binary
- * form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials
- * provided with the distribution. Neither the name of the copyright holders
- * nor the names of contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* $Id$ */
-
-/*
- Compute the ISO 8601 week number of the year.
- We return 0 if the week is the final one of the previous year.
- We return 54 if the week is the first week of the following year.
- Otherwise we return week numbers 1 to 53
-*/
-
-#include <time.h>
-
-uint8_t
-iso_weeknum(const struct tm * timestruct)
-{
- int d, w;
-
- /* convert to a MONDAY based week */
- d = timestruct->tm_wday;
- if (d == 0)
- d = 7;
-
- /* compute tentative ISO 8601 week number */
- w = timestruct->tm_yday + 11 - d;
- w /= 7;
-
- /*
- * handle the special case where week 53 may actually be week 1 of
- * the following year
- */
- if (w == 53) {
- /* week 53 must include its thursday in the same year */
- d = timestruct->tm_mday - 1;
- d -= timestruct->tm_wday;
- d += THURSDAY;
- if (d > 30)
- w++; /* signal first week of the following year */
- }
- return w;
-}
Modified: trunk/avr-libc/libc/time/strftime.c
===================================================================
--- trunk/avr-libc/libc/time/strftime.c 2013-05-03 16:13:03 UTC (rev 2390)
+++ trunk/avr-libc/libc/time/strftime.c 2013-05-03 20:53:06 UTC (rev 2391)
@@ -90,7 +90,7 @@
int d, w;
char c;
char _store[26];
- struct tm tm_temp;
+ struct week_date wd;
count = length = 0;
while (count < limit) {
@@ -161,20 +161,13 @@
case ('g'):
case ('G'):
- d = timeptr->tm_year + 1900;
- w = iso_weeknum(timeptr);
- if (w == 0)
- d--;
- if (w == 54)
- d++;
+ iso_week_date_r(timeptr->tm_year + 1900,
timeptr->tm_yday, &wd);
+ if (c == 'g') {
+ length = sprintf(_store, "%.2d", wd.year % 100);
+ } else {
+ length = sprintf(_store, "%.4d", wd.year);
+ }
- if (c == 'g') {
- d %= 100;
- length = sprintf(_store, "%.2d", d);
- } else {
- length = sprintf(_store, "%.4d", d);
- }
-
break;
case ('H'):
@@ -259,19 +252,8 @@
break;
case ('V'):
- w = iso_weeknum(timeptr);
- if (w == 0){
- /* we need the week number of the final
week of the previous year */
- tm_temp.tm_year = timeptr->tm_year - 1;
- tm_temp.tm_mon = 11;
- tm_temp.tm_mday = 31;
- tm_temp.tm_hour = tm_temp.tm_min =
tm_temp.tm_sec = 0;
- mktime(&tm_temp);
- w = iso_weeknum(&tm_temp);
- }
- if (w == 54)
- w = 1;
- length = sprintf(_store, "%.2u", w);
+ iso_week_date_r(timeptr->tm_year + 1900,
timeptr->tm_yday, &wd);
+ length = sprintf(_store, "%.2u", wd.week);
break;
case ('w'):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-commit] [2391] Deleted function iso_weeknum().,
Mike Rice <=