[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-commit] [2310] Add time directory
From: |
Mike Rice |
Subject: |
[avr-libc-commit] [2310] Add time directory |
Date: |
Fri, 29 Mar 2013 09:46:19 +0000 |
Revision: 2310
http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2310
Author: swfltek
Date: 2013-03-29 09:46:19 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
Add time directory
Modified Paths:
--------------
trunk/avr-libc/devtools/Architecture.am
trunk/avr-libc/include/Makefile.am
trunk/avr-libc/include/util/Makefile.am
trunk/avr-libc/libc/Makefile.am
Added Paths:
-----------
trunk/avr-libc/libc/time/
trunk/avr-libc/libc/time/Files.am
trunk/avr-libc/libc/time/Makefile.am
trunk/avr-libc/libc/time/Rules.am
trunk/avr-libc/libc/time/asc_store.h
trunk/avr-libc/libc/time/asctime.c
trunk/avr-libc/libc/time/asctime_r.c
trunk/avr-libc/libc/time/ctime.c
trunk/avr-libc/libc/time/ctime_r.c
trunk/avr-libc/libc/time/daylight_seconds.c
trunk/avr-libc/libc/time/difftime.c
trunk/avr-libc/libc/time/equation_of_time.c
trunk/avr-libc/libc/time/fatfs_time.c
trunk/avr-libc/libc/time/gm_sidereal.c
trunk/avr-libc/libc/time/gmtime.c
trunk/avr-libc/libc/time/gmtime_r.c
trunk/avr-libc/libc/time/isLeap.c
trunk/avr-libc/libc/time/isotime.c
trunk/avr-libc/libc/time/isotime_r.c
trunk/avr-libc/libc/time/lm_sidereal.c
trunk/avr-libc/libc/time/localtime.c
trunk/avr-libc/libc/time/localtime_r.c
trunk/avr-libc/libc/time/mk_gmtime.c
trunk/avr-libc/libc/time/mktime.c
trunk/avr-libc/libc/time/month_length.c
trunk/avr-libc/libc/time/moon_phase.c
trunk/avr-libc/libc/time/set_dst.c
trunk/avr-libc/libc/time/set_position.c
trunk/avr-libc/libc/time/set_system_time.c
trunk/avr-libc/libc/time/set_zone.c
trunk/avr-libc/libc/time/solar_declination.c
trunk/avr-libc/libc/time/strftime.c
trunk/avr-libc/libc/time/sun_rise.c
trunk/avr-libc/libc/time/sun_set.c
trunk/avr-libc/libc/time/system_tick.c
trunk/avr-libc/libc/time/time.c
trunk/avr-libc/libc/time/time_private.h
trunk/avr-libc/libc/time/tm_store.h
trunk/avr-libc/libc/time/week_of_month.c
trunk/avr-libc/libc/time/week_of_year.c
Modified: trunk/avr-libc/devtools/Architecture.am
===================================================================
--- trunk/avr-libc/devtools/Architecture.am 2013-03-29 08:46:44 UTC (rev
2309)
+++ trunk/avr-libc/devtools/Architecture.am 2013-03-29 09:46:19 UTC (rev
2310)
@@ -36,7 +36,7 @@
AVR_TARGET_ASFLAGS = <<lib_asflags>>
AVR_INSTALL_DIR = <<install_dir>>
-VPATH =
$(top_srcdir)/libc/stdlib:$(top_srcdir)/libc/pmstring:$(top_srcdir)/libc/string:$(top_srcdir)/libc/misc:$(top_srcdir)/libc/stdio:$(top_srcdir)/libm/fplib
+VPATH =
$(top_srcdir)/libc/stdlib:$(top_srcdir)/libc/pmstring:$(top_srcdir)/libc/string:$(top_srcdir)/libc/misc:$(top_srcdir)/libc/stdio:$(top_srcdir)/libm/fplib:$(top_srcdir)/libc/time
if HAS_<<arh>>
@@ -73,6 +73,7 @@
include $(top_srcdir)/libc/misc/Rules.am
include $(top_srcdir)/libc/stdio/Rules.am
include $(top_srcdir)/libm/fplib/Rules.am
+include $(top_srcdir)/libc/time/Rules.am
nodist_libc_a_SOURCES = \
$(stdlib_a_c_sources) \
@@ -86,7 +87,8 @@
$(stdio_a_c_sources) \
$(stdio_a_asm_sources) \
$(libm_a_c_sources) \
- $(libm_a_asm_sources)
+ $(libm_a_asm_sources) \
+ $(time_a_c_sources)
nodist_libm_a_SOURCES = \
$(libm_a_c_sources) \
Modified: trunk/avr-libc/include/Makefile.am
===================================================================
--- trunk/avr-libc/include/Makefile.am 2013-03-29 08:46:44 UTC (rev 2309)
+++ trunk/avr-libc/include/Makefile.am 2013-03-29 09:46:19 UTC (rev 2310)
@@ -41,6 +41,7 @@
stdint.h \
stdio.h \
stdlib.h \
- string.h
+ string.h \
+ time.h
SUBDIRS = avr compat util
Modified: trunk/avr-libc/include/util/Makefile.am
===================================================================
--- trunk/avr-libc/include/util/Makefile.am 2013-03-29 08:46:44 UTC (rev
2309)
+++ trunk/avr-libc/include/util/Makefile.am 2013-03-29 09:46:19 UTC (rev
2310)
@@ -36,7 +36,9 @@
delay_basic.h \
setbaud.h \
parity.h \
- twi.h
+ twi.h \
+ eu_dst.h \
+ usa_dst.h
nodist_avr_HEADERS = \
delay.h
Modified: trunk/avr-libc/libc/Makefile.am
===================================================================
--- trunk/avr-libc/libc/Makefile.am 2013-03-29 08:46:44 UTC (rev 2309)
+++ trunk/avr-libc/libc/Makefile.am 2013-03-29 09:46:19 UTC (rev 2310)
@@ -29,6 +29,6 @@
# $Id$
#
-SUBDIRS = stdlib pmstring string misc stdio
-DIST_SUBDIRS = stdlib pmstring string misc stdio
+SUBDIRS = stdlib pmstring string misc stdio time
+DIST_SUBDIRS = stdlib pmstring string misc stdio time
Added: trunk/avr-libc/libc/time/Files.am
===================================================================
--- trunk/avr-libc/libc/time/Files.am (rev 0)
+++ trunk/avr-libc/libc/time/Files.am 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,68 @@
+# \xA92012 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$
+
+time_a_c_sources = \
+ asctime.c \
+ asctime_r.c \
+ ctime.c \
+ ctime_r.c \
+ daylight_seconds.c \
+ difftime.c \
+ equation_of_time.c \
+ fatfs_time.c \
+ gm_sidereal.c \
+ gmtime.c \
+ gmtime_r.c \
+ isLeap.c \
+ isotime.c \
+ isotime_r.c \
+ lm_sidereal.c \
+ localtime.c \
+ localtime_r.c \
+ mk_gmtime.c \
+ mktime.c \
+ month_length.c \
+ moon_phase.c \
+ set_dst.c \
+ set_position.c \
+ set_system_time.c \
+ set_zone.c \
+ solar_declination.c \
+ strftime.c \
+ sun_rise.c \
+ sun_set.c \
+ system_tick.c \
+ time.c \
+ week_of_month.c \
+ week_of_year.c
+
+time_a_extra_dist = \
+ asc_store.h \
+ time_private.h \
+ tm_store.h
Property changes on: trunk/avr-libc/libc/time/Files.am
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/Makefile.am
===================================================================
--- trunk/avr-libc/libc/time/Makefile.am (rev 0)
+++ trunk/avr-libc/libc/time/Makefile.am 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,34 @@
+# ©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 $(top_srcdir)/libc/time/Files.am
+
+EXTRA_DIST = \
+ $(time_a_c_sources) \
+ $(time_a_extra_dist)
Property changes on: trunk/avr-libc/libc/time/Makefile.am
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/Rules.am
===================================================================
--- trunk/avr-libc/libc/time/Rules.am (rev 0)
+++ trunk/avr-libc/libc/time/Rules.am 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,30 @@
+# ©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 $(top_srcdir)/libc/time/Files.am
Property changes on: trunk/avr-libc/libc/time/Rules.am
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/asc_store.h
===================================================================
--- trunk/avr-libc/libc/time/asc_store.h (rev 0)
+++ trunk/avr-libc/libc/time/asc_store.h 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,42 @@
+/* ©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$ */
+
+/*
+ Private allocation, shared between asctime() and isotime()
+*/
+#ifndef ASC_STOR_H
+#define ASC_STOR_H
+
+#include "time_private.h"
+
+char __asc_store[ASCTIME_BUFFER_SIZE];
+
+#endif
Property changes on: trunk/avr-libc/libc/time/asc_store.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/asctime.c
===================================================================
--- trunk/avr-libc/libc/time/asctime.c (rev 0)
+++ trunk/avr-libc/libc/time/asctime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,43 @@
+/*
+ * ©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$ */
+
+/*
+ Standard asctime(), we simply punt to the re-entrant version.
+*/
+
+#include <time.h>
+#include "time_private.h"
+#include "asc_store.h"
+char *
+asctime(const struct tm * timeptr)
+{
+ asctime_r(timeptr, __asc_store);
+ return __asc_store;
+}
Property changes on: trunk/avr-libc/libc/time/asctime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/asctime_r.c
===================================================================
--- trunk/avr-libc/libc/time/asctime_r.c (rev 0)
+++ trunk/avr-libc/libc/time/asctime_r.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,73 @@
+/*
+ * ©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$ */
+
+/*
+ Re-entrant version of asctime().
+
+*/
+#include "time_private.h"
+#include <time.h>
+#include <stdio.h>
+
+#ifdef __MEMX
+const __memx char ascformat[] = "%s %s %d %.2d:%.2d:%.2d %d";
+const __memx char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const __memx char ascdays[] = "SunMonTueWedThuFriSat";
+#define _SPR sprintf_P
+#else
+const char ascformat[] = "%s %s %d %.2d:%.2d:%.2d %d";
+const char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const char ascdays[] = "SunMonTueWedThuFriSat";
+#define _SPR sprintf
+#endif
+
+void
+asctime_r(const struct tm * timeptr, char *buffer)
+{
+ unsigned char i, mnth, day;
+ char d[4];
+ char m[4];
+
+ day = timeptr->tm_wday * 3;
+ mnth = timeptr->tm_mon * 3;
+ for (i = 0; i < 3; i++) {
+ m[i] = ascmonths[mnth++];
+ d[i] = ascdays[day++];
+ }
+ m[3] = d[3] = 0;
+
+ _SPR(buffer, ascformat, d, m, \
+ timeptr->tm_mday, \
+ timeptr->tm_hour, \
+ timeptr->tm_min, \
+ timeptr->tm_sec,
+ timeptr->tm_year + 1900 \
+ );
+}
Property changes on: trunk/avr-libc/libc/time/asctime_r.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/ctime.c
===================================================================
--- trunk/avr-libc/libc/time/ctime.c (rev 0)
+++ trunk/avr-libc/libc/time/ctime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,46 @@
+/*
+ * ©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$ */
+
+/*
+ Standard ctime(). We have to break down the time stamp, print it into
our
+ private buffer, and return the buffer.
+*/
+#include <time.h>
+#include "asc_store.h"
+
+char *
+ctime(const time_t * timeptr)
+{
+ struct tm calendar;
+
+ localtime_r(timeptr, &calendar);
+ asctime_r(&calendar, __asc_store);
+ return __asc_store;
+}
Property changes on: trunk/avr-libc/libc/time/ctime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/ctime_r.c
===================================================================
--- trunk/avr-libc/libc/time/ctime_r.c (rev 0)
+++ trunk/avr-libc/libc/time/ctime_r.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,43 @@
+/*
+ * ©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$ */
+
+/*
+ Re entrant version of ctime()
+*/
+#include <time.h>
+
+void
+ctime_r(const time_t * timeptr, char *buffer)
+{
+ struct tm calendar;
+
+ localtime_r(timeptr, &calendar);
+ asctime_r(&calendar, buffer);
+}
Property changes on: trunk/avr-libc/libc/time/ctime_r.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/daylight_seconds.c
===================================================================
--- trunk/avr-libc/libc/time/daylight_seconds.c (rev 0)
+++ trunk/avr-libc/libc/time/daylight_seconds.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,69 @@
+/*
+ * ©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$ */
+
+/*
+ Determine the amount of time the sun is above the horizon. At high
latitudes, this can be zero,
+ or >= ONE_DAY.
+*/
+
+#include <time.h>
+#include <math.h>
+#include "time_private.h"
+
+extern long _latitude;
+
+
+long
+daylight_seconds(time_t * timer)
+{
+ double l, d;
+ long n;
+
+ /* convert latitude to radians */
+ l = _latitude / 206264.806;
+
+ d = -solar_declination(timer);
+
+ d = tan(l) * tan(d);
+
+ if (d > 1.0)
+ d = 1.0;
+
+ if (d < -1.0)
+ d = -1.0;
+
+ d = acos(d);
+
+ d /= 3.112505;
+
+ n = ONE_DAY * d;
+
+ return n;
+}
Property changes on: trunk/avr-libc/libc/time/daylight_seconds.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/difftime.c
===================================================================
--- trunk/avr-libc/libc/time/difftime.c (rev 0)
+++ trunk/avr-libc/libc/time/difftime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,41 @@
+/*
+ * ©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$ */
+
+/*
+ The C90 standard specifies this returns a 'double. Since we do not have
a true double,
+ we return a work alike type.
+*/
+#include <time.h>
+
+int32_t
+difftime(time_t t1, time_t t2)
+{
+ return t1 - t2;
+}
Property changes on: trunk/avr-libc/libc/time/difftime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/equation_of_time.c
===================================================================
--- trunk/avr-libc/libc/time/equation_of_time.c (rev 0)
+++ trunk/avr-libc/libc/time/equation_of_time.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,81 @@
+/*
+ * ©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$ */
+
+/*
+ The so called Equation of Time. We determine the orbital position of
the mothership,
+ and solve a two term polynomial. More accurate equations are available
(more terms), but
+ without a true double there is little point in that.
+*/
+
+#include <time.h>
+#include "time_private.h"
+#include <math.h>
+
+int
+equation_of_time(time_t * timer)
+{
+ unsigned long s, p, y;
+ double d, lf, hf;
+
+ /* s = time since solstice */
+ s = *timer + 836160UL;
+
+ /* p = time since perihelion */
+ p = *timer - 191857UL;
+
+ /* limit to 1 tropical year */
+ y = tropical_year;
+ s %= y;
+ p %= y;
+
+ /* low frequency component has 1 year period */
+ lf = p;
+ lf /= y;
+
+ /* high frequency component has 1/2 year period */
+ y /= 2;
+ hf = s;
+ hf /= y;
+
+ /* convert years to radians */
+ d = 6.283185307179586;
+ hf *= d;
+ lf *= d;
+
+ /* hf has magnitude 592.2 */
+ hf = sin(hf) * 592.2;
+
+ /* lf has magnitude 451.8 */
+ lf = sin(lf) * 451.8;
+
+ d = lf + hf;
+
+ return -d;
+}
Property changes on: trunk/avr-libc/libc/time/equation_of_time.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/fatfs_time.c
===================================================================
--- trunk/avr-libc/libc/time/fatfs_time.c (rev 0)
+++ trunk/avr-libc/libc/time/fatfs_time.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,66 @@
+/*
+ * ©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$ */
+
+/*
+ Return a value suitable for use as a file system time stamp.
+*/
+
+#include <time.h>
+
+uint32_t
+fat_time(struct tm * timeptr)
+{
+ uint32_t ret;
+ uint32_t n;
+
+ n = timeptr->tm_year - 80;
+ n <<= 25;
+ ret = n;
+
+ n = timeptr->tm_mon + 1;
+ n <<= 21;
+ ret |= n;
+
+ n = timeptr->tm_mday;
+ n <<= 16;
+ ret |= n;
+
+ n = timeptr->tm_hour;
+ n <<= 11;
+ ret |= n;
+
+ n = timeptr->tm_min;
+ n <<= 5;
+ ret |= n;
+
+ ret |= (timeptr->tm_sec / 2);
+
+ return ret;
+}
Property changes on: trunk/avr-libc/libc/time/fatfs_time.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/gm_sidereal.c
===================================================================
--- trunk/avr-libc/libc/time/gm_sidereal.c (rev 0)
+++ trunk/avr-libc/libc/time/gm_sidereal.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,52 @@
+/*
+ * ©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$ */
+
+/*
+ Greenwich Mean Sidereal Time.
+*/
+
+#include <time.h>
+
+unsigned long
+gm_sidereal(const time_t * timer)
+{
+ unsigned long long tmp;
+
+ tmp = *timer * 3133555966ULL;
+ tmp /= 3125000000ULL;
+
+
+ /* add GMST at epoch */
+ tmp += 23991ULL;
+
+ /* mod by 1 day */
+ tmp %= 86400ULL;
+ return tmp;
+}
Property changes on: trunk/avr-libc/libc/time/gm_sidereal.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/gmtime.c
===================================================================
--- trunk/avr-libc/libc/time/gmtime.c (rev 0)
+++ trunk/avr-libc/libc/time/gmtime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,45 @@
+/*
+ * ©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$ */
+
+/*
+ Standard gmtime(). We convert binary time into calendar time in our
private struct tm object,
+ returning that object.
+*/
+
+#include <time.h>
+#include "tm_store.h"
+
+struct tm *
+gmtime(const time_t * timeptr)
+{
+
+ gmtime_r(timeptr, &__tm_store);
+ return &__tm_store;
+}
Property changes on: trunk/avr-libc/libc/time/gmtime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/gmtime_r.c
===================================================================
--- trunk/avr-libc/libc/time/gmtime_r.c (rev 0)
+++ trunk/avr-libc/libc/time/gmtime_r.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,136 @@
+/*
+ * ©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$ */
+
+/*
+ Re entrant version of gmtime(), this function converts 'binary' time
into 'calendar' time.
+*/
+
+#include <time.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+void
+gmtime_r(const time_t * timer, struct tm * timeptr)
+{
+ int32_t t;
+ ldiv_t lresult;
+ div_t result;
+ uint16_t days, w;
+ int16_t n, i, d, ly, years;
+
+ /* This first division must be done the long way */
+ days = *timer / 86400UL;
+ t = *timer % 86400UL;
+
+ /* Epoch was a Saturday */
+ w = days + 6;
+ n = w % 7;
+ timeptr->tm_wday = n;
+
+ /* extract second, minute, and hour */
+ lresult = ldiv(t, 60L);
+ timeptr->tm_sec = lresult.rem;
+
+ result = div(lresult.quot, 60);
+ timeptr->tm_min = result.rem;
+ timeptr->tm_hour = result.quot;
+
+ /* map our place in the 100 and 4 year leap cycles. */
+ lresult = ldiv((long) days, 36525L);
+ years = 100 * lresult.quot;
+
+ lresult = ldiv(lresult.rem, 1461L);
+ years += 4 * lresult.quot;
+ d = lresult.rem;
+
+ /*
+ * 'd' is number of days into current 4 year cycle, 0 to 1460. years
+ * is evenly divisible by 4, and WILL be a leap year, unless it
+ * equals 100
+ */
+
+ ly = 1;
+ if (years == 100)
+ ly = 0;
+
+ n = 364 + ly;
+
+ if (d > n) {
+ d -= ly;
+ ly = 0;
+ result = div(d, 365);
+ years += result.quot;
+ d = result.rem;
+ }
+ timeptr->tm_year = 100 + years;
+ timeptr->tm_yday = d;
+
+ /* special case January */
+ if (d < 31) {
+ timeptr->tm_mon = 0;
+ timeptr->tm_mday = d;
+ }
+ /* special case February */
+ else {
+ d -= 31;
+ n = 28;
+ if (ly)
+ n = 29;
+ if (d < n) {
+ timeptr->tm_mon = 1;
+ timeptr->tm_mday = d;
+ } else {
+
+ d = d - n + 30;
+ result = div(d, 61);
+ i = result.quot;
+ d = result.rem;
+
+ n = 30;
+ if (i > 2)
+ n = 31;
+
+ i *= 2;
+ if (d >= n) {
+ i++;
+ d -= n;
+ }
+ timeptr->tm_mon = i + 1;
+ timeptr->tm_mday = d;
+ }
+ }
+
+ /* tm_mday is 1 based */
+ timeptr->tm_mday++;
+
+ /* gmt is never in DST */
+ timeptr->tm_isdst = 0;
+
+}
Property changes on: trunk/avr-libc/libc/time/gmtime_r.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/isLeap.c
===================================================================
--- trunk/avr-libc/libc/time/isLeap.c (rev 0)
+++ trunk/avr-libc/libc/time/isLeap.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,57 @@
+/*
+ * ©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$ */
+
+/*
+ Returns 0 if the given year is not a leap year, otherwise 1.
+*/
+
+#include <stdlib.h>
+
+unsigned char
+is_leap_year(int year)
+{
+ div_t d;
+
+ /* year must be divisible by 4 to be a leap year */
+ if (year & 3)
+ return 0;
+
+ d = div(year, 100);
+
+ /* if theres a remainder, year is not divisible by 100 or 400 */
+ if (d.rem)
+ return 1;
+
+ /* if the quotient is divisible by 4, then year is divisible by 400 */
+ if ((d.quot & 3) == 0)
+ return 1;
+
+ return 0;
+}
Property changes on: trunk/avr-libc/libc/time/isLeap.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/isotime.c
===================================================================
--- trunk/avr-libc/libc/time/isotime.c (rev 0)
+++ trunk/avr-libc/libc/time/isotime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,43 @@
+/*
+ * ©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$ */
+
+/*
+ This function returns ISO8601 formatted time, in our private buffer.
+*/
+
+#include <time.h>
+#include "asc_store.h"
+
+char *
+isotime(struct tm * tmptr)
+{
+ isotime_r(tmptr, __asc_store);
+ return __asc_store;
+}
Property changes on: trunk/avr-libc/libc/time/isotime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/isotime_r.c
===================================================================
--- trunk/avr-libc/libc/time/isotime_r.c (rev 0)
+++ trunk/avr-libc/libc/time/isotime_r.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,84 @@
+/*
+ * ©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$ */
+
+/*
+ Re entrant version of isotime(), which prints the date and time in ISO
8601 format.
+*/
+
+#include <stdlib.h>
+#include <time.h>
+
+char *
+__printem(int i, char *buffer)
+{
+ int n = 0;
+
+ if (i < 10)
+ *buffer++ = '0';
+ itoa(i, buffer, 10);
+
+ do {
+ n++;
+ i /= 10;
+ } while (i);
+
+ return buffer + n;
+}
+
+void
+isotime_r(struct tm * tmptr, char *buffer)
+{
+ int i;
+
+ i = tmptr->tm_year + 1900;
+ buffer = __printem(i, buffer);
+ *buffer++ = '-';
+
+ i = tmptr->tm_mon + 1;
+ buffer = __printem(i, buffer);
+ *buffer++ = '-';
+
+ i = tmptr->tm_mday;
+ buffer = __printem(i, buffer);
+ *buffer++ = ' ';
+
+ i = tmptr->tm_hour;
+ buffer = __printem(i, buffer);
+ *buffer++ = ':';
+
+ i = tmptr->tm_min;
+ buffer = __printem(i, buffer);
+ *buffer++ = ':';
+
+ i = tmptr->tm_sec;
+ buffer = __printem(i, buffer);
+
+ *buffer++ = 0;
+}
Property changes on: trunk/avr-libc/libc/time/isotime_r.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/lm_sidereal.c
===================================================================
--- trunk/avr-libc/libc/time/lm_sidereal.c (rev 0)
+++ trunk/avr-libc/libc/time/lm_sidereal.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,47 @@
+/*
+ * ©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$ */
+
+/*
+ Local Mean Sidereal Time. See gm_sidereal() for for info.
+*/
+#include <time.h>
+
+extern long _longitude;
+
+unsigned long
+lm_sidereal(const time_t * timer)
+{
+ long n;
+
+ n = gm_sidereal(timer) + _longitude / 15L;
+ n += 86400L;
+ n %= 86400L;
+ return n;
+}
Property changes on: trunk/avr-libc/libc/time/lm_sidereal.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/localtime.c
===================================================================
--- trunk/avr-libc/libc/time/localtime.c (rev 0)
+++ trunk/avr-libc/libc/time/localtime.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,43 @@
+/*
+ * ©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$ */
+
+/*
+ Standard localtime() function.
+*/
+
+#include "tm_store.h"
+#include <time.h>
+
+struct tm *
+localtime(const time_t * timer)
+{
+ localtime_r(timer, &__tm_store);
+ return &__tm_store;
+}
Property changes on: trunk/avr-libc/libc/time/localtime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/localtime_r.c
===================================================================
--- trunk/avr-libc/libc/time/localtime_r.c (rev 0)
+++ trunk/avr-libc/libc/time/localtime_r.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,57 @@
+/*
+ * ©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$ */
+
+/*
+ Re entrant version of localtime(). Given a binary UTC time stamp, add
the time
+ zone and Daylight savings offset, then break it down into calendar time.
+*/
+
+#include "time_private.h"
+#include <time.h>
+
+void
+localtime_r(const time_t * timer, struct tm * timeptr)
+{
+ time_t lt;
+ int16_t dst;
+
+ dst = -1;
+
+ if (_dst_ptr)
+ dst = _dst_ptr(timer, &_utc_offset);
+
+ lt = *timer + _utc_offset;
+
+ if (dst > 0)
+ lt += dst;
+
+ gmtime_r(<, timeptr);
+ timeptr->tm_isdst = dst;
+}
Property changes on: trunk/avr-libc/libc/time/localtime_r.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/mk_gmtime.c
===================================================================
--- trunk/avr-libc/libc/time/mk_gmtime.c (rev 0)
+++ trunk/avr-libc/libc/time/mk_gmtime.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,107 @@
+/*
+ * ©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$ */
+
+/*
+ Basically the inverse of gmtime_r(). We assume the values in timeptr
represent
+ UTC, thus time zone and DST do not apply.
+
+ Unlike mktime(), we do not attempt to 'normalize' timeptr... saves some
cpu cycles.
+*/
+
+#include <time.h>
+
+time_t
+mk_gmtime(struct tm * timeptr)
+{
+
+ time_t ret;
+ long tmp;
+ int n, m, d, leaps;
+
+ /* n = years since epoch */
+ n = timeptr->tm_year - 100;
+
+ /* compute leap days prior to timeptr */
+ leaps = 0;
+ if (n) {
+ m = n - 1;
+ leaps = m / 4;
+ leaps -= m / 100;
+ leaps++;
+ }
+ /* compute days elapsed since EPOCH to the beginning of the year */
+ tmp = 365L * n + leaps;
+
+ m = timeptr->tm_mday - 1;
+ d = 0;
+
+ /* Special case January */
+ if (timeptr->tm_mon == 0) {
+ d += m;
+ }
+ /* Special case February */
+ else if (timeptr->tm_mon == 1) {
+ n = m + 31;
+ d += n;
+ } else {
+ d += 29;
+ if (is_leap_year(timeptr->tm_year + 1900))
+ d++;
+
+ m = timeptr->tm_mon - 1;
+
+ n = m / 2;
+ m -= n * 2;
+
+ n *= 61;
+ d += n;
+
+ if (m) {
+ d += 30;
+ if (timeptr->tm_mon > 6)
+ d++;
+ }
+ d += timeptr->tm_mday - 1;
+ }
+
+ tmp += d;
+
+ /* convert days into seconds */
+ ret = 86400LL * tmp;
+
+ /* add time of day */
+ tmp = 3600L * timeptr->tm_hour;
+ tmp += 60L * timeptr->tm_min;
+ tmp += timeptr->tm_sec;
+
+ ret += tmp;
+
+ return ret;
+}
Property changes on: trunk/avr-libc/libc/time/mk_gmtime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/mktime.c
===================================================================
--- trunk/avr-libc/libc/time/mktime.c (rev 0)
+++ trunk/avr-libc/libc/time/mktime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,58 @@
+/*
+ * ©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$ */
+
+/*
+ Standard mktime(). The provided broken down Local 'calendar' time is
converted into
+ a binary time stamp. The process is then reversed to 'normalize'
timeptr.
+*/
+
+#include <time.h>
+#include "time_private.h"
+
+time_t
+mktime(struct tm * timeptr)
+{
+ time_t ret;
+
+ ret = mk_gmtime(timeptr);
+
+ if (timeptr->tm_isdst < 0) {
+ if (_dst_ptr)
+ timeptr->tm_isdst = _dst_ptr(&ret, &_utc_offset);
+ }
+ if (timeptr->tm_isdst > 0)
+ ret -= timeptr->tm_isdst;
+
+ ret -= _utc_offset;
+
+ localtime_r(&ret, timeptr);
+
+ return ret;
+}
Property changes on: trunk/avr-libc/libc/time/mktime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/month_length.c
===================================================================
--- trunk/avr-libc/libc/time/month_length.c (rev 0)
+++ trunk/avr-libc/libc/time/month_length.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,51 @@
+/*
+ * ©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$ */
+
+/*
+ Return the length of a month in days, given the year and month in
question.
+ The month parameter must be '1 based', ranging from 1 to 12.
+*/
+
+#include <time.h>
+
+char
+month_length(int year, char month)
+{
+ char ret;
+
+ if (month == 2) {
+ ret = 28;
+ if (is_leap_year(year))
+ ret++;
+ } else {
+ ret = 30 + ((month + month / 8) & 1);
+ }
+ return ret;
+}
Property changes on: trunk/avr-libc/libc/time/month_length.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/moon_phase.c
===================================================================
--- trunk/avr-libc/libc/time/moon_phase.c (rev 0)
+++ trunk/avr-libc/libc/time/moon_phase.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,58 @@
+/*
+ * ©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$ */
+
+/*
+ Return an approximation to the phase of the moon. Higher accuracy may
be obtained
+ with a 4 term polynomial, but due to the limitations of our 'double',
this simple
+ version is about as good, and much faster.
+*/
+
+#include <time.h>
+
+int8_t
+moon_phase(time_t * gmt)
+{
+ uint32_t t;
+ int32_t n;
+
+ /* refer to first new moon of the epoch */
+ t = *gmt - 1744800UL;
+
+ /* constrain to 1 lunar cycle */
+ n = t % 2551443UL;
+
+ /* offset by 1/2 lunar cycle */
+ n -= 1275721L;
+
+ /* scale to range - 100...+ 100 */
+ n /= 12757L;
+
+ return n;
+}
Property changes on: trunk/avr-libc/libc/time/moon_phase.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/set_dst.c
===================================================================
--- trunk/avr-libc/libc/time/set_dst.c (rev 0)
+++ trunk/avr-libc/libc/time/set_dst.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,41 @@
+/*
+ * ©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$ */
+
+/*
+ Set the dst function pointer.
+*/
+
+#include "time_private.h"
+
+void
+set_dst(int (*d) (const time_t *, int32_t *))
+{
+ _dst_ptr = d;
+}
Property changes on: trunk/avr-libc/libc/time/set_dst.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/set_position.c
===================================================================
--- trunk/avr-libc/libc/time/set_position.c (rev 0)
+++ trunk/avr-libc/libc/time/set_position.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,44 @@
+/*
+ * ©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$ */
+
+/*
+ Set the geographic position of the observer. Both parameters are in
seconds, with
+ North latitude and East longitude being positive values.
+*/
+
+long _latitude;
+long _longitude;
+
+void
+set_position(long lat, long lon)
+{
+ _latitude = lat;
+ _longitude = lon;
+}
Property changes on: trunk/avr-libc/libc/time/set_position.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/set_system_time.c
===================================================================
--- trunk/avr-libc/libc/time/set_system_time.c (rev 0)
+++ trunk/avr-libc/libc/time/set_system_time.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,57 @@
+/*
+ * ©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$ */
+
+/*
+ * Set the system time. The values passed are assumed to represent local
+ * standard time, such as would be obtained from the typical Real Time Clock
+ * integrated circuit. It is necessary for this to be atomic, as the value may
be
+ * incremented at interrupt time.
+ */
+
+#include <time.h>
+extern volatile time_t __system_time;
+
+void
+set_system_time(struct tm * tmptr)
+{
+ time_t t;
+
+ t = mktime(tmptr);
+ asm volatile(
+ "in __tmp_reg__, __SREG__" "\n\t"
+ "cli" "\n\t"
+ ::
+ );
+ __system_time = t;
+ asm volatile(
+ "out __SREG__, __tmp_reg__" "\n\t"
+ ::
+ );
+}
Property changes on: trunk/avr-libc/libc/time/set_system_time.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/set_zone.c
===================================================================
--- trunk/avr-libc/libc/time/set_zone.c (rev 0)
+++ trunk/avr-libc/libc/time/set_zone.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,41 @@
+/*
+ * ©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$ */
+
+/*
+ Set the system time zone. The parameter is seconds offset from UTC.
+*/
+
+#include "time_private.h"
+
+void
+set_zone(long z)
+{
+ _utc_offset = z;
+}
Property changes on: trunk/avr-libc/libc/time/set_zone.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/solar_declination.c
===================================================================
--- trunk/avr-libc/libc/time/solar_declination.c
(rev 0)
+++ trunk/avr-libc/libc/time/solar_declination.c 2013-03-29 09:46:19 UTC
(rev 2310)
@@ -0,0 +1,58 @@
+/*
+ * ©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$ */
+
+/*
+ Basic Solar declination calculation.
+*/
+
+#include <time.h>
+#include "time_private.h"
+#include <math.h>
+
+double
+solar_declination(time_t * timer)
+{
+ unsigned long i, y;
+ double d;
+
+ /* what is our orbital position? */
+ y = tropical_year;
+ i = *timer % y;
+
+ /* convert position to radians */
+ d = i;
+ d /= y;
+ d *= 6.283185307179586;
+
+ /* compute result */
+ d = 0.006918 - 0.409092627750149 * cos(d) + 0.070257 * sin(d);
+
+ return d;
+}
Property changes on: trunk/avr-libc/libc/time/solar_declination.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/strftime.c
===================================================================
--- trunk/avr-libc/libc/time/strftime.c (rev 0)
+++ trunk/avr-libc/libc/time/strftime.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,306 @@
+/*
+ * ©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$ */
+
+/*
+ Standard strftime(). This is a memory hungry monster.
+*/
+
+#include <stdio.h>
+#include "time_private.h"
+
+#ifdef __MEMX
+
+const __memx char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday
Friday Saturday ";
+const __memx char strfmonths[] = "January February March April May June July
August September October November December ";
+
+#else
+
+const char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday
Friday Saturday ";
+const char strfmonths[] = "January February March April May June July
August September October November December ";
+
+#endif
+
+
+
+#ifdef __MEMX
+
+unsigned char
+pgm_copystring(const char __memx * p, unsigned char i, char *b, unsigned char
l)
+{
+
+#else
+
+unsigned char
+pgm_copystring(const char *p, unsigned char i, char *b, unsigned char l)
+{
+
+#endif
+
+ unsigned char ret, c;
+
+ ret = 0;
+ while (i) {
+ c = *p++;
+ if (c == ' ')
+ i--;
+ }
+
+ c = *p++;
+ while (c != ' ' && l--) {
+ *b++ = c;
+ ret++;
+ c = *p++;
+ }
+ *b = 0;
+ return ret;
+}
+
+size_t
+strftime(char *buffer, size_t limit, const char *pattern, const struct tm *
timeptr)
+{
+ unsigned int count, length;
+ int d, w;
+ char c;
+ char _store[26];
+
+ count = length = 0;
+ while (count < limit) {
+ c = *pattern++;
+ if (c == '%') {
+ c = *pattern++;
+ if (c == 'E' || c == 'O')
+ c = *pattern++;
+ //we implement only the 'C' locale
+ switch (c) {
+ case ('%'):
+ _store[0] = c;
+ length = 1;
+ break;
+
+ case ('a'):
+ length = pgm_copystring(strfwkdays,
timeptr->tm_wday, _store, 3);
+ break;
+
+ case ('A'):
+ length = pgm_copystring(strfwkdays,
timeptr->tm_wday, _store, 255);
+ break;
+
+ case ('b'):
+ case ('h'):
+ length = pgm_copystring(strfmonths,
timeptr->tm_mon, _store, 3);
+ break;
+
+ case ('B'):
+ length = pgm_copystring(strfmonths,
timeptr->tm_mon, _store, 255);
+ break;
+
+ case ('c'):
+ length = sprintf(_store, "%u/%u/%u
%.2u:%.2u:%.2u", \
+ timeptr->tm_mon + 1, \
+ timeptr->tm_mday, \
+ timeptr->tm_year + 1900, \
+ timeptr->tm_hour, \
+ timeptr->tm_min, \
+ timeptr->tm_sec
+ );
+ break;
+
+ case ('C'):
+ d = timeptr->tm_year + 1900;
+ d %= 100;
+ length = sprintf(_store, "%.2d", d);
+ break;
+
+ case ('d'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_mday);
+ break;
+
+ case ('D'):
+ length = sprintf(_store, "%.2u/%.2u/%.2u", \
+ timeptr->tm_mon + 1, \
+ timeptr->tm_mday, \
+ timeptr->tm_year + 1900 \
+ );
+ break;
+
+ case ('e'):
+ length = sprintf(_store, "%2d",
timeptr->tm_mday);
+ break;
+
+ case ('F'):
+ length = sprintf(_store, "%d-%.2d-%-2d", \
+ timeptr->tm_year + 1900, \
+ timeptr->tm_mon + 1, \
+ timeptr->tm_mday \
+ );
+ break;
+
+ case ('H'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_hour);
+ break;
+
+ case ('I'):
+ d = timeptr->tm_hour;
+ if (d > 12)
+ d -= 12;
+ length = sprintf(_store, "%.2u", d);
+ break;
+
+ case ('j'):
+ length = sprintf(_store, "%.3u",
timeptr->tm_yday + 1);
+ break;
+
+ case ('m'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_mon + 1);
+ break;
+
+ case ('M'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_min);
+ break;
+
+ case ('n'):
+ _store[0] = 10;
+ length = 1;
+ break;
+
+ case ('p'):
+ length = 2;
+ _store[0] = 'A';
+ if (timeptr->tm_hour > 11)
+ _store[0] = 'P';
+ _store[1] = 'M';
+ _store[2] = 0;
+ break;
+
+ case ('r'):
+ length = sprintf(_store, "%2d:%.2d:%.2d", \
+ (timeptr->tm_hour % 12) + 1, \
+ timeptr->tm_min, \
+ timeptr->tm_sec \
+ );
+ break;
+
+ case ('R'):
+ length = sprintf(_store, "%d:%.2d",
timeptr->tm_hour, timeptr->tm_min);
+ break;
+
+ case ('S'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_sec);
+ length = 2;
+ break;
+
+ case ('t'):
+ _store[0] = 9;
+ length = 1;
+ break;
+
+ case ('T'):
+ length = sprintf(_store, "%.2d:%.2d:%.2d", \
+ timeptr->tm_hour, \
+ timeptr->tm_min, \
+ timeptr->tm_sec \
+ );
+ break;
+
+ case ('u'):
+ w = timeptr->tm_wday;
+ if (w == 0)
+ w = 7;
+ length = sprintf(_store, "%d", w);
+ break;
+
+ case ('U'):
+ length = sprintf(_store, "%.2u",
week_of_year(timeptr, 0));
+ break;
+
+ case ('w'):
+ length = sprintf(_store, "%u",
timeptr->tm_wday);
+ break;
+
+ case ('W'):
+ w = week_of_year(timeptr, 1);
+ length = sprintf(_store, "%.2u", w);
+ break;
+
+ case ('x'):
+ length = sprintf(_store, "%.2u/%.2u/%.2u",
timeptr->tm_mon + 1, timeptr->tm_mday, timeptr->tm_year + 1900);
+ break;
+
+ case ('X'):
+ length = sprintf(_store, "%.2u:%.2u:%.2u",
timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
+ break;
+
+ case ('y'):
+ length = sprintf(_store, "%.2u",
timeptr->tm_year % 100);
+ break;
+
+ case ('Y'):
+ length = sprintf(_store, "%u", timeptr->tm_year
+ 1900);
+ break;
+
+ case ('z'):
+ d = _utc_offset / 60;
+ w = timeptr->tm_isdst / 60;
+ if (w > 0)
+ d += w;
+ w = abs(d % 60);
+ d = d / 60;
+ length = sprintf(_store, "%+.2d%.2d", d, w);
+ break;
+
+ default:
+ length = 1;
+ _store[0] = '?';
+ _store[1] = 0;
+ break;
+ }
+
+ if ((length + count) < limit) {
+ count += length;
+ for (d = 0; d < length; d++) {
+ *buffer++ = _store[d];
+ }
+ } else {
+ *buffer = 0;
+ return count;
+ }
+
+ } else { /* copy a literal */
+ *buffer = c;
+ buffer++;
+ count++;
+ if (c == 0)
+ return count;
+ }
+ }
+
+ *buffer = 0;
+ return count;
+}
Property changes on: trunk/avr-libc/libc/time/strftime.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/sun_rise.c
===================================================================
--- trunk/avr-libc/libc/time/sun_rise.c (rev 0)
+++ trunk/avr-libc/libc/time/sun_rise.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,56 @@
+/*
+ * ©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$ */
+
+/*
+ Return the approximate time of sun rise.
+*/
+
+#include <time.h>
+extern long _longitude;
+
+time_t
+sun_rise(time_t * timer)
+{
+ long n;
+ time_t t;
+
+ t = *timer % 86400UL;
+ t = *timer - t;
+ t += 43200L;
+ t -= equation_of_time(timer);
+
+ n = daylight_seconds(timer) / 2L;
+ t -= n;
+
+ n = _longitude / 15L;
+ t -= n;
+
+ return t;
+}
Property changes on: trunk/avr-libc/libc/time/sun_rise.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/sun_set.c
===================================================================
--- trunk/avr-libc/libc/time/sun_set.c (rev 0)
+++ trunk/avr-libc/libc/time/sun_set.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,56 @@
+/*
+ * ©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$ */
+
+/*
+ Return the approximate time of sun set.
+*/
+
+#include <time.h>
+extern long _longitude;
+
+time_t
+sun_set(time_t * timer)
+{
+ long n;
+ time_t t;
+
+ t = *timer % 86400UL;
+ t = *timer - t;
+ t += 43200L;
+ t -= equation_of_time(timer);
+
+ n = daylight_seconds(timer) / 2L;
+ t += n;
+
+ n = _longitude / 15L;
+ t -= n;
+
+ return t;
+}
Property changes on: trunk/avr-libc/libc/time/sun_set.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/system_tick.c
===================================================================
--- trunk/avr-libc/libc/time/system_tick.c (rev 0)
+++ trunk/avr-libc/libc/time/system_tick.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,54 @@
+/*
+ * ©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$ */
+
+/*
+ This function is to be called at a 1 Hz rate to maintain the system
time. Though
+ probably it will only be called at interrupt time, we make it atomic
just to be
+ safe.
+*/
+
+#include <time.h>
+extern volatile time_t __system_time;
+
+void
+system_tick()
+{
+
+ asm volatile(
+ "in __tmp_reg__, __SREG__" "\n\t"
+ "cli" "\n\t"
+ ::
+ );
+ __system_time++;
+ asm volatile(
+ "out __SREG__, __tmp_reg__" "\n\t"
+ ::
+ );
+}
Property changes on: trunk/avr-libc/libc/time/system_tick.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/time.c
===================================================================
--- trunk/avr-libc/libc/time/time.c (rev 0)
+++ trunk/avr-libc/libc/time/time.c 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,59 @@
+/*
+ * ©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$ */
+
+/*
+ Standard time() function. Copying from __system_time must be atomic,
since it
+ may be incremented at interrupt time.
+*/
+#include <time.h>
+#include <inttypes.h>
+
+
+volatile time_t __system_time;
+
+time_t
+time(time_t * timer)
+{
+ time_t ret;
+
+ asm volatile(
+ "in __tmp_reg__, __SREG__" "\n\t"
+ "cli" "\n\t"
+ ::
+ );
+ ret = __system_time;
+ asm volatile(
+ "out __SREG__, __tmp_reg__" "\n\t"
+ ::
+ );
+ if (timer)
+ *timer = ret;
+ return ret;
+}
Property changes on: trunk/avr-libc/libc/time/time.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/time_private.h
===================================================================
--- trunk/avr-libc/libc/time/time_private.h (rev 0)
+++ trunk/avr-libc/libc/time/time_private.h 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,47 @@
+/* ©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$ */
+
+#ifndef TIME_PRIVATE_H
+#define TIME_PRIVATE_H
+
+#include <inttypes.h>
+#include <time.h>
+
+#define ASCTIME_BUFFER_SIZE 26
+
+#define tropical_year 31556926 /* seconds */
+
+int (*_dst_ptr)(const time_t*, int32_t*);
+
+long _utc_offset;
+
+
+#endif
\ No newline at end of file
Property changes on: trunk/avr-libc/libc/time/time_private.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/tm_store.h
===================================================================
--- trunk/avr-libc/libc/time/tm_store.h (rev 0)
+++ trunk/avr-libc/libc/time/tm_store.h 2013-03-29 09:46:19 UTC (rev 2310)
@@ -0,0 +1,40 @@
+/* ©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$ */
+
+/*
+ Private allocation, used by gmtime() and localtime()
+*/
+#ifndef TM_STORE_H
+#define TM_STORE_H
+
+struct tm __tm_store;
+
+#endif
\ No newline at end of file
Property changes on: trunk/avr-libc/libc/time/tm_store.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/week_of_month.c
===================================================================
--- trunk/avr-libc/libc/time/week_of_month.c (rev 0)
+++ trunk/avr-libc/libc/time/week_of_month.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,58 @@
+/*
+ * ©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$ */
+
+/*
+ Return the week of month, where 'base' represents the day of week
considered as
+ the beginning day. In the USA, the week is generally considered to be
Sunday
+ (base = 0), while in Europe it is generally considered to be Monday
(base = 1).
+
+ Return value ranges from 0 to 5.
+*/
+
+#include <time.h>
+
+uint8_t
+week_of_month(const struct tm * calendar, uint8_t base)
+{
+ int w;
+
+ /* zero base the day of month */
+ w = calendar->tm_mday - 1;
+
+ /* find most recent base day */
+ w = w - calendar->tm_wday + base;
+
+ /* if negative, we are in week 0 */
+ if (w < 0)
+ return 0;
+
+ return w / 7 + 1;
+
+}
Property changes on: trunk/avr-libc/libc/time/week_of_month.c
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/avr-libc/libc/time/week_of_year.c
===================================================================
--- trunk/avr-libc/libc/time/week_of_year.c (rev 0)
+++ trunk/avr-libc/libc/time/week_of_year.c 2013-03-29 09:46:19 UTC (rev
2310)
@@ -0,0 +1,54 @@
+/*
+ * ©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$ */
+
+/*
+ Return the week of year, where 'base' represents the day of week
considered as
+ the beginning day. In the USA, the week is generally considered to be
Sunday
+ (base = 0), while in Europe it is generally considered to be Monday
(base = 1).
+
+ Return value ranges from 0 to 5.
+*/
+
+#include <time.h>
+
+uint8_t
+week_of_year(const struct tm * timeptr, uint8_t base)
+{
+ int w;
+
+ /* find most recent base day */
+ w = timeptr->tm_yday - timeptr->tm_wday + base;
+
+ /* if negative, we are in week 0 */
+ if (w < 0)
+ return 0;
+
+ return w / 7 + 1;
+}
Property changes on: trunk/avr-libc/libc/time/week_of_year.c
___________________________________________________________________
Added: svn:executable
+ *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-commit] [2310] Add time directory,
Mike Rice <=