]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
switch to avr-libc 1.8.1 time library
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Dec 2014 22:25:55 +0000 (23:25 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Dec 2014 22:25:55 +0000 (23:25 +0100)
56 files changed:
avr/Tupfile
avr/cmd_date.c
avr/date.c [deleted file]
avr/pcf8583.c
include/rtc.h
include/time.h [new symlink]
time/Files.am [new file with mode: 0644]
time/Makefile [new file with mode: 0644]
time/Makefile.am [new file with mode: 0644]
time/Makefile.in [new file with mode: 0644]
time/Rules.am [new file with mode: 0644]
time/asc_store.c [new file with mode: 0644]
time/asctime.c [new file with mode: 0644]
time/asctime_r.c [new file with mode: 0644]
time/ctime.c [new file with mode: 0644]
time/ctime_r.c [new file with mode: 0644]
time/daylight_seconds.c [new file with mode: 0644]
time/difftime.c [new file with mode: 0644]
time/dst_pointer.c [new file with mode: 0644]
time/ephemera_common.h [new file with mode: 0644]
time/equation_of_time.c [new file with mode: 0644]
time/fatfs_time.c [new file with mode: 0644]
time/geo_location.c [new file with mode: 0644]
time/gm_sidereal.c [new file with mode: 0644]
time/gmtime.c [new file with mode: 0644]
time/gmtime_r.c [new file with mode: 0644]
time/isLeap.c [new file with mode: 0644]
time/iso_week_date.c [new file with mode: 0644]
time/iso_week_date_r.c [new file with mode: 0644]
time/isotime.c [new file with mode: 0644]
time/isotime_r.c [new file with mode: 0644]
time/lm_sidereal.c [new file with mode: 0644]
time/localtime.c [new file with mode: 0644]
time/localtime_r.c [new file with mode: 0644]
time/mk_gmtime.c [new file with mode: 0644]
time/mktime.c [new file with mode: 0644]
time/month_length.c [new file with mode: 0644]
time/moon_phase.c [new file with mode: 0644]
time/print_lz.c [new file with mode: 0644]
time/set_dst.c [new file with mode: 0644]
time/set_position.c [new file with mode: 0644]
time/set_system_time.c [new file with mode: 0644]
time/set_zone.c [new file with mode: 0644]
time/solar_declination.c [new file with mode: 0644]
time/solar_noon.c [new file with mode: 0644]
time/strftime.c [new file with mode: 0644]
time/sun_rise.c [new file with mode: 0644]
time/sun_set.c [new file with mode: 0644]
time/system_tick.S [new file with mode: 0644]
time/system_time.c [new file with mode: 0644]
time/time.c [new file with mode: 0644]
time/time.h [new file with mode: 0644]
time/tm_store.c [new file with mode: 0644]
time/utc_offset.c [new file with mode: 0644]
time/week_of_month.c [new file with mode: 0644]
time/week_of_year.c [new file with mode: 0644]

index 1c0f7ed425b555e765d6b057bc44ccdffe376c5c..6c406493579f87cc659329f45da62a199fd87f41 100644 (file)
@@ -8,11 +8,15 @@ SRC           = main.c
 SRC            += cli.c cli_readline.c command.c command_tbl.c
 SRC            += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c
 SRC            += cmd_sd.c cmd_fat.c
-SRC            += env.c xmalloc.c date.c con-utils.c print-utils.c getopt-min.c
+SRC            += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c
 SRC            += timer.c serial.c i2c.c pcf8583.c mmc.c
 SRC            += background.c z180-serv.c z80-if.c gpio.c
 SRC            += $(FATFS) $(TOP)/fatfs/src/option/unicode.c
 
+#TODO: time lib
+SRC            += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c
+SRC            += ../time/print_lz.c ../time/isLeap.c
+
 SRC_Z          = ../z180/hdrom.c
 
 #TARGETS       = $(PROG).elf
index 337d720e450b038698a40b9fa1189d63b919df36..3beebee498a6df16a3794762af81c0ee226022e5 100644 (file)
@@ -8,73 +8,13 @@
 /*
  * RTC, Date & Time support: get and set date & time
  */
-#include <common.h>
+#include "common.h"
 #include <string.h>
-#include <command.h>
-#include <rtc.h>
-#include <i2c.h>
+#include "time.h"
+#include "rtc.h"
+#include "command.h"
 
 
-static const FLASH char * const FLASH weekdays[] = {
-               FSTR("Mon"),
-               FSTR("Tues"),
-               FSTR("Wednes"),
-               FSTR("Thurs"),
-               FSTR("Fri"),
-               FSTR("Satur"),
-               FSTR("Sun")
-};
-
-int mk_date (const char *, struct rtc_time *);
-
-command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct rtc_time tm;
-       int rcode = CMD_RET_SUCCESS;
-
-       (void) cmdtp; (void) flag;
-
-       switch (argc) {
-       case 2:                 /* set date & time */
-               /* initialize tm with current time */
-               rcode = rtc_get (&tm);
-
-               if(!rcode) {
-                       /* insert new date & time */
-                       if (mk_date (argv[1], &tm) != 0) {
-                               my_puts_P(PSTR("## Bad date format\n"));
-                               break;
-                       }
-                       /* and write to RTC */
-                       rcode = rtc_set (&tm);
-                       if(rcode)
-                               my_puts_P(PSTR("## Set date failed\n"));
-               } else {
-                       my_puts_P(PSTR("## Get date failed\n"));
-               }
-               /* FALL TROUGH */
-       case 1:                 /* get date & time */
-               rcode = rtc_get (&tm);
-
-               if (rcode) {
-                       my_puts_P(PSTR("## Get date failed\n"));
-                       break;
-               }
-               printf_P(PSTR("Date: %4d-%02d-%02d ("),
-                       tm.tm_year, tm.tm_mon, tm.tm_mday);
-               my_puts_P( (tm.tm_wday<0 || tm.tm_wday>6) ?
-                               PSTR("unknown ") : weekdays[tm.tm_wday]);
-               printf_P(PSTR("day)    Time: %2d:%02d:%02d\n"),
-                       tm.tm_hour, tm.tm_min, tm.tm_sec);
-               break;
-
-       default:
-               rcode = CMD_RET_USAGE;
-       }
-
-       return rcode;
-}
-
 /*
  * simple conversion of two-digit string with error checking
  */
@@ -103,7 +43,7 @@ static int cnvrt2 (const char *str, int *valp)
  * Some basic checking for valid values is done, but this will not catch
  * all possible error conditions.
  */
-int mk_date (const char *datestr, struct rtc_time *tmp)
+int mk_date (const char *datestr, struct tm *tmp)
 {
        int len, val;
        char *ptr;
@@ -129,36 +69,36 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
                tmp->tm_sec = 0;
        }
 
-       if (len == 12) {                /* MMDDhhmmCCYY */
+       if (len == 12) {                        /* MMDDhhmmCCYY */
                int year, century;
 
                if (cnvrt2 (datestr+ 8, &century) ||
                    cnvrt2 (datestr+10, &year) ) {
                        return (-1);
                }
-               tmp->tm_year = 100 * century + year;
+               tmp->tm_year = 100 * century + year - 1900;
        } else if (len == 10) {         /* MMDDhhmmYY   */
                int year, century;
 
-               century = tmp->tm_year / 100;
+               century = (tmp->tm_year + 1900) / 100;
                if (cnvrt2 (datestr+ 8, &year))
                        return (-1);
-               tmp->tm_year = 100 * century + year;
+               tmp->tm_year = 100 * century + year -1900;
        }
 
        switch (len) {
-       case 8:                 /* MMDDhhmm     */
+       case 8:                                 /* MMDDhhmm     */
                /* fall thru */
-       case 10:                /* MMDDhhmmYY   */
+       case 10:                                /* MMDDhhmmYY   */
                /* fall thru */
-       case 12:                /* MMDDhhmmCCYY */
+       case 12:                                /* MMDDhhmmCCYY */
                if (cnvrt2 (datestr+0, &val) ||
                    val > 12) {
                        break;
                }
-               tmp->tm_mon  = val;
+               tmp->tm_mon  = val - 1;
                if (cnvrt2 (datestr+2, &val) ||
-                   val > ((tmp->tm_mon==2) ? 29 : 31)) {
+                   val > ((tmp->tm_mon==2-1) ? 29 : 31)) {
                        break;
                }
                tmp->tm_mday = val;
@@ -175,9 +115,6 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
                }
                tmp->tm_min  = val;
 
-               /* calculate day of week */
-               GregorianDay (tmp);
-
                return (0);
        default:
                break;
@@ -185,3 +122,53 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
 
        return (-1);
 }
+
+command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct tm t;
+       char buf[30];
+       int rcode = CMD_RET_SUCCESS;
+
+       (void) cmdtp; (void) flag;
+
+       switch (argc) {
+       case 2:                 /* set date & time */
+               /* initialize t with current time */
+               rcode = rtc_get (&t);
+
+               if(!rcode) {
+                       /* insert new date & time */
+                       if (mk_date (argv[1], &t) != 0) {
+                               my_puts_P(PSTR("## Bad date format\n"));
+                               break;
+                       }
+
+                       time_t time;
+                       time = mk_gmtime(&t);
+                       gmtime_r(&time, &t);
+
+                       /* and write to RTC */
+                       rcode = rtc_set (&t);
+                       if(rcode)
+                               my_puts_P(PSTR("## Set date failed\n"));
+               } else {
+                       my_puts_P(PSTR("## Get date failed\n"));
+               }
+               /* FALL TROUGH */
+       case 1:                 /* get date & time */
+               rcode = rtc_get (&t);
+
+               if (rcode) {
+                       my_puts_P(PSTR("## Get date failed\n"));
+                       break;
+               }
+               asctime_r(&t, buf);
+               printf_P(PSTR("%s\n"), buf);
+               break;
+
+       default:
+               rcode = CMD_RET_USAGE;
+       }
+
+       return rcode;
+}
diff --git a/avr/date.c b/avr/date.c
deleted file mode 100644 (file)
index 5caee2f..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Date & Time support for RTC
- */
-
-#include <common.h>
-#include <command.h>
-#include <rtc.h>
-
-
-#define FEBRUARY               2
-#define        STARTOFTIME             1970
-#define SECDAY                 86400L
-#define SECYR                  (SECDAY * 365)
-#define        leapyear(year)          ((year) % 4 == 0)
-#define        days_in_year(a)         (leapyear(a) ? 366 : 365)
-#define        days_in_month(a)        (month_days[(a) - 1])
-
-
-static const FLASH int MonthOffset[] = {
-       0,31,59,90,120,151,181,212,243,273,304,334
-};
-
-/*
- * This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
- */
-void GregorianDay(struct rtc_time * tm)
-{
-       int leapsToDate;
-       int lastYear;
-       int day;
-
-       lastYear=tm->tm_year-1;
-
-       /*
-        * Number of leap corrections to apply up to end of last year
-        */
-       leapsToDate = lastYear/4 - lastYear/100 + lastYear/400;
-
-       /*
-        * This year is a leap year if it is divisible by 4 except when it is
-        * divisible by 100 unless it is divisible by 400
-        *
-        * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be
-        */
-       if((tm->tm_year%4==0) &&
-          ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) &&
-          (tm->tm_mon>2)) {
-               /*
-                * We are past Feb. 29 in a leap year
-                */
-               day=1;
-       } else {
-               day=0;
-       }
-
-       day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday;
-
-       tm->tm_wday=day%7;
-}
-
-void to_tm(unsigned long tim, struct rtc_time * tm)
-{
-       char month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
-       register int    i;
-       register long   hms, day;
-
-       day = tim / SECDAY;
-       hms = tim % SECDAY;
-
-       /* Hours, minutes, seconds are easy */
-       tm->tm_hour = hms / 3600;
-       tm->tm_min = (hms % 3600) / 60;
-       tm->tm_sec = (hms % 3600) % 60;
-
-       /* Number of years in days */
-       for (i = STARTOFTIME; day >= days_in_year(i); i++) {
-               day -= days_in_year(i);
-       }
-       tm->tm_year = i;
-
-       /* Number of months in days left */
-       if (leapyear(tm->tm_year)) {
-               days_in_month(FEBRUARY) = 29;
-       }
-       for (i = 1; day >= days_in_month(i); i++) {
-               day -= days_in_month(i);
-       }
-       days_in_month(FEBRUARY) = 28;
-       tm->tm_mon = i;
-
-       /* Days are what is left over (+1) from all that. */
-       tm->tm_mday = day + 1;
-
-       /*
-        * Determine the day of week
-        */
-       GregorianDay(tm);
-}
-
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
- * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
- * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
- *
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
- */
-unsigned long
-mktime (unsigned int year, unsigned int mon,
-       unsigned int day, unsigned int hour,
-       unsigned int min, unsigned int sec)
-{
-       if (0 >= (int) (mon -= 2)) {    /* 1..12 -> 11,12,1..10 */
-               mon += 12;              /* Puts Feb last since it has leap day */
-               year -= 1;
-       }
-
-       return (((
-               (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
-                       year*365 - 719499
-           )*24 + hour /* now have hours */
-         )*60 + min /* now have minutes */
-       )*60 + sec; /* finally seconds */
-}
index af1331dad7a6fcdb82cab02f604830847f24fe7d..7e9d749be0e8dc1a5dc437f16068303a7df79c57 100644 (file)
@@ -4,10 +4,11 @@
 
 #include "common.h"
 #include <stdlib.h>
-#include "debug.h"
-#include "command.h"
+#include "time.h"
 #include "rtc.h"
 #include "i2c.h"
+#include "command.h"
+#include "debug.h"
 
 #define  DEBUG_RTC 0
 
@@ -34,17 +35,17 @@ static uint_fast8_t bcd2bin(uint8_t val)
 static uint8_t bin2bcd (uint_fast8_t val)
 {
        div_t d = div(val, 10);
-       
+
        return (d.quot << 4) | d.rem;
 }
 
 
-int rtc_get (struct rtc_time *tmp)
+int rtc_get (struct tm *tmp)
 {
        int rel = 0;
        uint8_t rtcbuf[NR_OF_REGS];
-       uint16_t year;
-       
+       int16_t year;
+
        i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, rtcbuf, NR_OF_REGS);
        i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0x10, 1, (uint8_t *) &year, 2);
 
@@ -56,12 +57,12 @@ int rtc_get (struct rtc_time *tmp)
        tmp->tm_min  = bcd2bin (rtcbuf[REG_MIN]    & 0x7F);
        tmp->tm_hour = bcd2bin (rtcbuf[REG_HOUR]   & 0x3F);
        tmp->tm_mday = bcd2bin (rtcbuf[REG_YRDATE] & 0x3F);
-       tmp->tm_mon  = bcd2bin (rtcbuf[REG_WDMON]  & 0x1F);
+       tmp->tm_mon  = bcd2bin (rtcbuf[REG_WDMON]  & 0x1F) - 1;
        while (year%4 < (rtcbuf[REG_YRDATE]>>6)) {
                year++;
                /* TODO: update RTC ram */
        }
-       tmp->tm_year  = year; 
+       tmp->tm_year  = year;
        tmp->tm_wday = rtcbuf[REG_WDMON] >> 5;
        tmp->tm_yday = 0;
        tmp->tm_isdst= 0;
@@ -74,7 +75,7 @@ int rtc_get (struct rtc_time *tmp)
        return rel;
 }
 
-int rtc_set (struct rtc_time *tmp)
+int rtc_set (struct tm *tmp)
 {
        uint8_t rtcbuf[NR_OF_REGS];
 
@@ -84,7 +85,7 @@ int rtc_set (struct rtc_time *tmp)
 
        rtcbuf[REG_CS] = 0x84;
        rtcbuf[REG_CSEC] = 0x00;
-       rtcbuf[REG_WDMON ] = bin2bcd(tmp->tm_mon) | ((tmp->tm_wday) << 5);
+       rtcbuf[REG_WDMON ] = (bin2bcd(tmp->tm_mon) + 1) | ((tmp->tm_wday) << 5);
        rtcbuf[REG_YRDATE] = ((tmp->tm_year % 4) << 6) | bin2bcd(tmp->tm_mday);
        rtcbuf[REG_HOUR  ] = bin2bcd(tmp->tm_hour);
        rtcbuf[REG_MIN   ] = bin2bcd(tmp->tm_min);
index 51ee4243f1e8d07d52b063c11f04368993ae0de7..69466605fac647cfefb1ad23b79c89c315348a6c 100644 (file)
@@ -1,48 +1,10 @@
-/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
 /*
  * Generic RTC interface.
  */
 #ifndef _RTC_H_
 #define _RTC_H_
 
-
-/*
- * The struct used to pass data from the generic interface code to
- * the hardware dependend low-level code ande vice versa. Identical
- * to struct rtc_time used by the Linux kernel.
- *
- * Note that there are small but significant differences to the
- * common "struct time":
- *
- *             struct time:            struct rtc_time:
- * tm_mon      0 ... 11                1 ... 12
- * tm_year     years since 1900        years since 0
- */
-
-struct rtc_time {
-       int tm_sec;
-       int tm_min;
-       int tm_hour;
-       int tm_mday;
-       int tm_mon;
-       int tm_year;
-       int tm_wday;
-       int tm_yday;
-       int tm_isdst;
-};
-
-int rtc_get (struct rtc_time *);
-int rtc_set (struct rtc_time *);
-
-void GregorianDay (struct rtc_time *);
-void to_tm (unsigned long, struct rtc_time *);
-unsigned long mktime (unsigned int, unsigned int, unsigned int,
-                     unsigned int, unsigned int, unsigned int);
+int rtc_get (struct tm *);
+int rtc_set (struct tm *);
 
 #endif /* _RTC_H_ */
diff --git a/include/time.h b/include/time.h
new file mode 120000 (symlink)
index 0000000..b9ae22c
--- /dev/null
@@ -0,0 +1 @@
+../time/time.h
\ No newline at end of file
diff --git a/time/Files.am b/time/Files.am
new file mode 100644 (file)
index 0000000..26bfc62
--- /dev/null
@@ -0,0 +1,77 @@
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+time_a_c_sources = \
+       asc_store.c \
+       asctime.c \
+       asctime_r.c \
+       ctime.c \
+       ctime_r.c \
+       daylight_seconds.c \
+       difftime.c \
+       dst_pointer.c \
+       equation_of_time.c \
+       fatfs_time.c \
+       geo_location.c \
+       gm_sidereal.c \
+       gmtime.c \
+       gmtime_r.c \
+       isLeap.c \
+       isotime.c \
+       iso_week_date.c \
+       iso_week_date_r.c \
+       isotime_r.c \
+       lm_sidereal.c \
+       localtime.c \
+       localtime_r.c \
+       mk_gmtime.c \
+       mktime.c \
+       month_length.c \
+       moon_phase.c \
+       print_lz.c \
+       set_dst.c \
+       set_position.c \
+       set_system_time.c \
+       set_zone.c \
+       solar_declination.c \
+       solar_noon.c \
+       strftime.c \
+       sun_rise.c \
+       sun_set.c \
+       system_time.c \
+       time.c \
+       tm_store.c \
+       utc_offset.c \
+       week_of_month.c \
+       week_of_year.c
+
+time_a_asm_sources = \
+       system_tick.S
+
+time_a_extra_dist = \
+       ephemera_common.h
diff --git a/time/Makefile b/time/Makefile
new file mode 100644 (file)
index 0000000..ea8d363
--- /dev/null
@@ -0,0 +1,529 @@
+# Makefile.in generated by automake 1.14 from Makefile.am.
+# libc/time/Makefile.  Generated from Makefile.in by configure.
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+
+# Â©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: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs  ]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/avr-libc
+pkgincludedir = $(includedir)/avr-libc
+pkglibdir = $(libdir)/avr-libc
+pkglibexecdir = $(libexecdir)/avr-libc
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = x86_64-unknown-linux-gnu
+host_triplet = avr-unknown-none
+DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \
+       $(srcdir)/Makefile.am
+subdir = libc/time
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_$(V))
+am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY))
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
+am__v_at_1 = 
+SOURCES =
+DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing aclocal-1.14
+AMTAR = $${TAR-tar}
+AM_DEFAULT_VERBOSITY = 1
+AR = avr-ar
+AS = avr-as
+ASDEBUG = 
+AUTOCONF = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoconf
+AUTOHEADER = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoheader
+AUTOMAKE = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing automake-1.14
+AVR_LIBC_MAJOR = 1
+AVR_LIBC_MINOR = 8
+AVR_LIBC_RELDATE = 20140811
+AVR_LIBC_REVISION = 1
+AVR_LIBC_USER_MANUAL = avr-libc-user-manual-1.8.1
+AVR_LIBC_VERSION = 1.8.1
+AVR_LIBC_VERSION_NUMERIC = 10801
+AWK = gawk
+CC = avr-gcc
+CCAS = avr-gcc
+CCASDEPMODE = depmode=gcc3
+CCASFLAGS = 
+CCDEPMODE = depmode=gcc3
+CDEBUG = 
+CFLAGS = 
+CPPFLAGS = 
+CYGPATH_W = echo
+DEFS = -DHAVE_CONFIG_H
+DEPDIR = .deps
+DOCSDIR = 
+DOC_INST_DIR = ${DESTDIR}${datadir}/doc/avr-libc-$(VERSION)
+ECHO_C = 
+ECHO_N = -n
+ECHO_T = 
+EXEEXT = 
+FNO_JUMP_TABLES = -fno-jump-tables
+HAS_DELAY_CYCLES = 1
+INSTALL = /usr/bin/install -c
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALL_DOX_HTML = install-dox-html
+INSTALL_DOX_MAN = install-dox-man
+INSTALL_DOX_PDF = install-dox-pdf
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
+LDFLAGS = 
+LIBOBJS = 
+LIBS = 
+LN_S = ln -s
+LTLIBOBJS = 
+MAKEINFO = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing makeinfo
+MKDIR_P = /bin/mkdir -p
+OBJEXT = o
+PACKAGE = avr-libc
+PACKAGE_BUGREPORT = avr-libc-dev@nongnu.org
+PACKAGE_NAME = avr-libc
+PACKAGE_STRING = avr-libc 1.8.1
+PACKAGE_TARNAME = avr-libc
+PACKAGE_URL = 
+PACKAGE_VERSION = 1.8.1
+PATH_SEPARATOR = :
+PNGTOPNM = pngtopnm
+PNMTOPNG = pnmtopng
+RANLIB = avr-ranlib
+SET_MAKE = 
+SHELL = /bin/bash
+STRIP = avr-strip
+TARGET_DOX_HTML = dox-html
+TARGET_DOX_PDF = dox-pdf
+VERSION = 1.8.1
+abs_builddir = /home/leo/src/avr/avr-libc-1.8.1/libc/time
+abs_srcdir = /home/leo/src/avr/avr-libc-1.8.1/libc/time
+abs_top_builddir = /home/leo/src/avr/avr-libc-1.8.1
+abs_top_srcdir = /home/leo/src/avr/avr-libc-1.8.1
+ac_ct_CC = 
+am__include = include
+am__leading_dot = .
+am__quote = 
+am__tar = $${TAR-tar} chof - "$$tardir"
+am__untar = $${TAR-tar} xf -
+bindir = ${exec_prefix}/bin
+build = x86_64-unknown-linux-gnu
+build_alias = x86_64-unknown-linux-gnu
+build_cpu = x86_64
+build_os = linux-gnu
+build_vendor = unknown
+builddir = .
+datadir = ${datarootdir}
+datarootdir = ${prefix}/share
+docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}
+dvidir = ${docdir}
+exec_prefix = ${prefix}
+host = avr-unknown-none
+host_alias = avr
+host_cpu = avr
+host_os = none
+host_vendor = unknown
+htmldir = ${docdir}
+includedir = ${prefix}/include
+infodir = ${datarootdir}/info
+install_sh = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/install-sh
+libdir = ${exec_prefix}/lib
+libexecdir = ${exec_prefix}/libexec
+localedir = ${datarootdir}/locale
+localstatedir = ${prefix}/var
+mandir = ${datarootdir}/man
+mkdir_p = $(MKDIR_P)
+oldincludedir = /usr/include
+pdfdir = ${docdir}
+prefix = /usr/local
+program_transform_name = s,x,x,
+psdir = ${docdir}
+sbindir = ${exec_prefix}/sbin
+sharedstatedir = ${prefix}/com
+srcdir = .
+sysconfdir = ${prefix}/etc
+target_alias = 
+top_build_prefix = ../../
+top_builddir = ../..
+top_srcdir = ../..
+time_a_c_sources = \
+       asc_store.c \
+       asctime.c \
+       asctime_r.c \
+       ctime.c \
+       ctime_r.c \
+       daylight_seconds.c \
+       difftime.c \
+       dst_pointer.c \
+       equation_of_time.c \
+       fatfs_time.c \
+       geo_location.c \
+       gm_sidereal.c \
+       gmtime.c \
+       gmtime_r.c \
+       isLeap.c \
+       isotime.c \
+       iso_week_date.c \
+       iso_week_date_r.c \
+       isotime_r.c \
+       lm_sidereal.c \
+       localtime.c \
+       localtime_r.c \
+       mk_gmtime.c \
+       mktime.c \
+       month_length.c \
+       moon_phase.c \
+       print_lz.c \
+       set_dst.c \
+       set_position.c \
+       set_system_time.c \
+       set_zone.c \
+       solar_declination.c \
+       solar_noon.c \
+       strftime.c \
+       sun_rise.c \
+       sun_set.c \
+       system_time.c \
+       time.c \
+       tm_store.c \
+       utc_offset.c \
+       week_of_month.c \
+       week_of_year.c
+
+time_a_asm_sources = \
+       system_tick.S
+
+time_a_extra_dist = \
+       ephemera_common.h
+
+EXTRA_DIST = \
+       $(time_a_c_sources) \
+       $(time_a_asm_sources) \
+       $(time_a_extra_dist)
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign libc/time/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+$(top_srcdir)/libc/time/Files.am:
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+tags TAGS:
+
+ctags CTAGS:
+
+cscope cscopelist:
+
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+       -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
+       ctags-am distclean distclean-generic distdir dvi dvi-am html \
+       html-am info info-am install install-am install-data \
+       install-data-am install-dvi install-dvi-am install-exec \
+       install-exec-am install-html install-html-am install-info \
+       install-info-am install-man install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
+       installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+       pdf-am ps ps-am tags-am uninstall uninstall-am
+
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/time/Makefile.am b/time/Makefile.am
new file mode 100644 (file)
index 0000000..c8a121f
--- /dev/null
@@ -0,0 +1,35 @@
+# Â©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: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+
+include $(top_srcdir)/libc/time/Files.am
+
+EXTRA_DIST = \
+       $(time_a_c_sources) \
+       $(time_a_asm_sources) \
+       $(time_a_extra_dist)
diff --git a/time/Makefile.in b/time/Makefile.in
new file mode 100644 (file)
index 0000000..868aa89
--- /dev/null
@@ -0,0 +1,529 @@
+# Makefile.in generated by automake 1.14 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# Â©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: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $
+VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs  ]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \
+       $(srcdir)/Makefile.am
+subdir = libc/time
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
+SOURCES =
+DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AS = @AS@
+ASDEBUG = @ASDEBUG@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AVR_LIBC_MAJOR = @AVR_LIBC_MAJOR@
+AVR_LIBC_MINOR = @AVR_LIBC_MINOR@
+AVR_LIBC_RELDATE = @AVR_LIBC_RELDATE@
+AVR_LIBC_REVISION = @AVR_LIBC_REVISION@
+AVR_LIBC_USER_MANUAL = @AVR_LIBC_USER_MANUAL@
+AVR_LIBC_VERSION = @AVR_LIBC_VERSION@
+AVR_LIBC_VERSION_NUMERIC = @AVR_LIBC_VERSION_NUMERIC@
+AWK = @AWK@
+CC = @CC@
+CCAS = @CCAS@
+CCASDEPMODE = @CCASDEPMODE@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CDEBUG = @CDEBUG@
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOCSDIR = @DOCSDIR@
+DOC_INST_DIR = @DOC_INST_DIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EXEEXT = @EXEEXT@
+FNO_JUMP_TABLES = @FNO_JUMP_TABLES@
+HAS_DELAY_CYCLES = @HAS_DELAY_CYCLES@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_DOX_HTML = @INSTALL_DOX_HTML@
+INSTALL_DOX_MAN = @INSTALL_DOX_MAN@
+INSTALL_DOX_PDF = @INSTALL_DOX_PDF@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PNGTOPNM = @PNGTOPNM@
+PNMTOPNG = @PNMTOPNG@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+TARGET_DOX_HTML = @TARGET_DOX_HTML@
+TARGET_DOX_PDF = @TARGET_DOX_PDF@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+time_a_c_sources = \
+       asc_store.c \
+       asctime.c \
+       asctime_r.c \
+       ctime.c \
+       ctime_r.c \
+       daylight_seconds.c \
+       difftime.c \
+       dst_pointer.c \
+       equation_of_time.c \
+       fatfs_time.c \
+       geo_location.c \
+       gm_sidereal.c \
+       gmtime.c \
+       gmtime_r.c \
+       isLeap.c \
+       isotime.c \
+       iso_week_date.c \
+       iso_week_date_r.c \
+       isotime_r.c \
+       lm_sidereal.c \
+       localtime.c \
+       localtime_r.c \
+       mk_gmtime.c \
+       mktime.c \
+       month_length.c \
+       moon_phase.c \
+       print_lz.c \
+       set_dst.c \
+       set_position.c \
+       set_system_time.c \
+       set_zone.c \
+       solar_declination.c \
+       solar_noon.c \
+       strftime.c \
+       sun_rise.c \
+       sun_set.c \
+       system_time.c \
+       time.c \
+       tm_store.c \
+       utc_offset.c \
+       week_of_month.c \
+       week_of_year.c
+
+time_a_asm_sources = \
+       system_tick.S
+
+time_a_extra_dist = \
+       ephemera_common.h
+
+EXTRA_DIST = \
+       $(time_a_c_sources) \
+       $(time_a_asm_sources) \
+       $(time_a_extra_dist)
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign libc/time/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+$(top_srcdir)/libc/time/Files.am:
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+tags TAGS:
+
+ctags CTAGS:
+
+cscope cscopelist:
+
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+       -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
+       ctags-am distclean distclean-generic distdir dvi dvi-am html \
+       html-am info info-am install install-am install-data \
+       install-data-am install-dvi install-dvi-am install-exec \
+       install-exec-am install-html install-html-am install-info \
+       install-info-am install-man install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
+       installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+       pdf-am ps ps-am tags-am uninstall uninstall-am
+
+ # (C)2012 Michael Duane Rice All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are
+ # met:
+ #
+ # Redistributions of source code must retain the above copyright notice, this
+ # list of conditions and the following disclaimer. Redistributions in binary
+ # form must reproduce the above copyright notice, this list of conditions
+ # and the following disclaimer in the documentation and/or other materials
+ # provided with the distribution. Neither the name of the copyright holders
+ # nor the names of contributors may be used to endorse or promote products
+ # derived from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/time/Rules.am b/time/Rules.am
new file mode 100644 (file)
index 0000000..a2c0929
--- /dev/null
@@ -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: Rules.am 2321 2013-04-02 00:12:48Z swfltek $
+
+include $(top_srcdir)/libc/time/Files.am
diff --git a/time/asc_store.c b/time/asc_store.c
new file mode 100644 (file)
index 0000000..1839ec6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asc_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+/*
+       Private allocation, shared between asctime() and isotime()
+*/
+
+#include <time.h>
+
+char            __store[26];
+
+char           *__asc_store = __store;
diff --git a/time/asctime.c b/time/asctime.c
new file mode 100644 (file)
index 0000000..38c6ea9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asctime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Standard asctime(), we simply punt to the re-entrant version.
+*/
+
+#include <time.h>
+
+extern char    *__asc_store;
+
+char           *
+asctime(const struct tm * timeptr)
+{
+       asctime_r(timeptr, __asc_store);
+       return __asc_store;
+}
diff --git a/time/asctime_r.c b/time/asctime_r.c
new file mode 100644 (file)
index 0000000..f85336d
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: asctime_r.c 2357 2013-04-21 16:25:30Z swfltek $ */
+
+/*
+       Re-entrant version of asctime().
+
+*/
+#include <time.h>
+#include <stdlib.h>
+
+#ifdef __MEMX
+const __memx char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const __memx char ascdays[] = "SunMonTueWedThuFriSat";
+#else
+const char      ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+const char      ascdays[] = "SunMonTueWedThuFriSat";
+#endif
+
+extern void __print_lz(int , char *, char );
+
+void
+asctime_r(const struct tm * timeptr, char *buffer)
+{
+       unsigned char   i, m, d;
+       div_t result;
+
+       d = timeptr->tm_wday * 3;
+       m = timeptr->tm_mon * 3;
+       for (i = 0; i < 3; i++) {
+           buffer[i] = ascdays[d++];
+           buffer[i+4] = ascmonths[m++];
+       }
+       buffer[3]=buffer[7]=' ';
+       buffer += 8;
+
+       __print_lz(timeptr->tm_mday,buffer,' ');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_hour,buffer,':');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_min,buffer,':');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_sec,buffer,' ');
+       buffer += 3;
+
+       result = div(timeptr->tm_year + 1900 , 100);
+
+       __print_lz(result.quot,buffer,' ');
+       buffer += 2;
+
+       __print_lz(result.rem,buffer,0);
+
+}
diff --git a/time/ctime.c b/time/ctime.c
new file mode 100644 (file)
index 0000000..f17b873
--- /dev/null
@@ -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: ctime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Standard ctime(). We have to break down the time stamp, print it into our
+       private buffer, and return the buffer.
+*/
+#include <time.h>
+
+extern char    *__asc_store;
+
+char           *
+ctime(const time_t * timeptr)
+{
+       struct tm       calendar;
+
+       localtime_r(timeptr, &calendar);
+       asctime_r(&calendar, __asc_store);
+       return __asc_store;
+}
diff --git a/time/ctime_r.c b/time/ctime_r.c
new file mode 100644 (file)
index 0000000..4bb3633
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: ctime_r.c 2315 2013-03-29 21:24:31Z joerg_wunsch $ */
+
+/*
+       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);
+}
diff --git a/time/daylight_seconds.c b/time/daylight_seconds.c
new file mode 100644 (file)
index 0000000..97df585
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: daylight_seconds.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+    Determine the amount of time the sun is above the horizon. At high latitudes, around the
+    solstices, this can be zero or greater than ONE_DAY.
+
+*/
+
+#include <time.h>
+#include <math.h>
+
+extern long     __latitude;
+
+long
+daylight_seconds(const time_t * timer)
+{
+    double          l, d;
+    long            n;
+
+    /* convert latitude to radians */
+    l = __latitude / 206264.806;
+
+    d = -solar_declination(timer);
+
+    /* partial 'Sunrise Equation' */
+    d = tan(l) * tan(d);
+
+    /* magnitude of d may exceed 1.0 at near solstices */
+    if (d > 1.0)
+        d = 1.0;
+
+    if (d < -1.0)
+        d = -1.0;
+
+    /* derive hour angle */
+    d = acos(d);
+
+    /* but for atmospheric refraction, this would be d /= M_PI */
+    d /= 3.112505;
+
+    n = ONE_DAY * d;
+
+    return n;
+}
diff --git a/time/difftime.c b/time/difftime.c
new file mode 100644 (file)
index 0000000..95b24e9
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: difftime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       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;
+}
diff --git a/time/dst_pointer.c b/time/dst_pointer.c
new file mode 100644 (file)
index 0000000..5eda185
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: dst_pointer.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+#include <inttypes.h>
+#include <time.h>
+
+int             (*__dst_ptr) (const time_t *, int32_t *);
diff --git a/time/ephemera_common.h b/time/ephemera_common.h
new file mode 100644 (file)
index 0000000..9583f89
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: ephemera_common.h 2345 2013-04-11 23:58:48Z swfltek $ */
+
+#ifndef EPHEMERA_PRIVATE_H
+#define EPHEMERA_PRIVATE_H
+
+#define TROP_YEAR 31556925
+#define ANOM_YEAR 31558433
+#define INCLINATION 0.409105176667471    /* Earths axial tilt at the epoch */
+#define PERIHELION 31316400    /* perihelion of 1999, 03 jan 13:00 UTC */
+#define SOLSTICE 836160        /* winter solstice of 1999, 22 Dec 07:44 UTC */
+#define TWO_PI 6.283185307179586
+#define TROP_CYCLE 5022440.6025
+#define ANOM_CYCLE 5022680.6082
+#define DELTA_V 0.03342044    /* 2x orbital eccentricity */
+
+#endif
diff --git a/time/equation_of_time.c b/time/equation_of_time.c
new file mode 100644 (file)
index 0000000..a527c83
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: equation_of_time.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+    The so called Equation of Time.
+
+    The eccentricity of Earths orbit contributes about 7.7 minutes of variation to the result. It
+    has a period of 1 anomalous year, with zeroes at perihelion and aphelion.
+
+    The tilt of Earths rotational axis (obliquity) contributes about 9.9 minutes of variation. It
+    has a period of 1/2 tropical year, with zeroes at solstices and equinoxes. The time of Earths
+    arrival at these events is influenced by the eccentricity, which causes it to progress along its
+    orbital path faster as it approaches perihelion, imposing a 'modulation' on the tropical phase.
+
+    The algorithm employed computes the orbital position with respect to perihelion, deriving
+    from that a 'velocity correction factor'. The orbital position with respect to the winter solstice
+    is then computed, as modulated by that factor. The individual contributions of the obliquity and the
+    eccentricity components are then summed, and returned as an integer value in seconds.
+
+*/
+
+#include <time.h>
+#include <math.h>
+#include "ephemera_common.h"
+
+int
+equation_of_time(const time_t * timer)
+{
+    int32_t         s, p;
+    double          pf, sf, dV;
+
+    /* compute orbital position relative to perihelion */
+    p = *timer % ANOM_YEAR;
+    p += PERIHELION;
+    pf = p;
+    pf /= ANOM_CYCLE;
+    pf = sin(pf);
+
+    /* Derive a velocity correction factor from the perihelion angle */
+    dV = pf * DELTA_V;
+
+    /* compute approximate position relative to solstice */
+    s = *timer % TROP_YEAR;
+    s += SOLSTICE;
+    s *= 2;
+    sf = s;
+    sf /= TROP_CYCLE;
+
+    /* modulate to derive actual position */
+    sf += dV;
+    sf = sin(sf);
+
+    /* compute contributions */
+    sf *= 592.2;
+    pf *= 459.6;
+    s = pf + sf;
+    return -s;
+
+}
diff --git a/time/fatfs_time.c b/time/fatfs_time.c
new file mode 100644 (file)
index 0000000..9ed49a5
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: fatfs_time.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+       Return a value suitable for use as a file system time stamp.
+*/
+
+#include <time.h>
+
+uint32_t
+fat_time(const 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;
+}
diff --git a/time/geo_location.c b/time/geo_location.c
new file mode 100644 (file)
index 0000000..84bd7a8
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: geo_location.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+long            __latitude;
+long            __longitude;
diff --git a/time/gm_sidereal.c b/time/gm_sidereal.c
new file mode 100644 (file)
index 0000000..b0984aa
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gm_sidereal.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+    Greenwich Mean Sidereal Time. A sidereal second is somewhat shorter than a standard second,
+    about 1.002737909350795 sidereal seconds per standard second.
+
+    We resort to fixed point math due to the insufficient resolution of a 'double', using...
+
+        timestamp * ( 1.002737909350795 << 31 )
+        --------------------------------------- + Te
+                        1 << 31
+
+    Where Te is the sidereal time at the epoch.
+
+*/
+
+#include <time.h>
+#include <stdint.h>
+
+unsigned long
+gm_sidereal(const time_t * timer)
+{
+    uint64_t        tmp;
+
+    tmp = *timer;
+    tmp *= 0x8059B740;
+    tmp /= 0x80000000;
+    tmp += (uint64_t) 23991;
+
+    tmp %= ONE_DAY;
+    return tmp;
+}
diff --git a/time/gmtime.c b/time/gmtime.c
new file mode 100644 (file)
index 0000000..f3d0b2e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gmtime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Standard gmtime(). We convert binary time into calendar time in our private struct tm object,
+       returning that object.
+*/
+
+#include <time.h>
+
+extern struct tm __tm_store;
+
+struct tm      *
+gmtime(const time_t * timeptr)
+{
+       gmtime_r(timeptr, &__tm_store);
+       return &__tm_store;
+}
diff --git a/time/gmtime_r.c b/time/gmtime_r.c
new file mode 100644 (file)
index 0000000..22658ea
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: gmtime_r.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/* Re entrant version of gmtime(). */
+
+#include <time.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+void
+gmtime_r(const time_t * timer, struct tm * timeptr)
+{
+    int32_t         fract;
+    ldiv_t          lresult;
+    div_t           result;
+    uint16_t        days, n, leapyear, years;
+
+    /* break down timer into whole and fractional parts of 1 day */
+    days = *timer / 86400UL;
+    fract = *timer % 86400UL;
+
+    /*
+            Extract hour, minute, and second from the fractional day
+        */
+    lresult = ldiv(fract, 60L);
+    timeptr->tm_sec = lresult.rem;
+    result = div(lresult.quot, 60);
+    timeptr->tm_min = result.rem;
+    timeptr->tm_hour = result.quot;
+
+    /* Determine day of week ( the epoch was a Saturday ) */
+    n = days + SATURDAY;
+    n %= 7;
+    timeptr->tm_wday = n;
+
+    /*
+        * Our epoch year has the property of being at the conjunction of all three 'leap cycles',
+        * 4, 100, and 400 years ( though we can ignore the 400 year cycle in this library).
+        *
+        * Using this property, we can easily 'map' the time stamp into the leap cycles, quickly
+        * deriving the year and day of year, along with the fact of whether it is a leap year.
+        */
+
+    /* map into a 100 year cycle */
+    lresult = ldiv((long) days, 36525L);
+    years = 100 * lresult.quot;
+
+    /* map into a 4 year cycle */
+    lresult = ldiv(lresult.rem, 1461L);
+    years += 4 * lresult.quot;
+    days = lresult.rem;
+    if (years > 100)
+        days++;
+
+    /*
+         * 'years' is now at the first year of a 4 year leap cycle, which will always be a leap year,
+         * unless it is 100. 'days' is now an index into that cycle.
+         */
+    leapyear = 1;
+    if (years == 100)
+        leapyear = 0;
+
+    /* compute length, in days, of first year of this cycle */
+    n = 364 + leapyear;
+
+    /*
+     * if the number of days remaining is greater than the length of the
+     * first year, we make one more division.
+     */
+    if (days > n) {
+        days -= leapyear;
+        leapyear = 0;
+        result = div(days, 365);
+        years += result.quot;
+        days = result.rem;
+    }
+    timeptr->tm_year = 100 + years;
+    timeptr->tm_yday = days;
+
+    /*
+            Given the year, day of year, and leap year indicator, we can break down the
+            month and day of month. If the day of year is less than 59 (or 60 if a leap year), then
+            we handle the Jan/Feb month pair as an exception.
+        */
+    n = 59 + leapyear;
+    if (days < n) {
+        /* special case: Jan/Feb month pair */
+        result = div(days, 31);
+        timeptr->tm_mon = result.quot;
+        timeptr->tm_mday = result.rem;
+    } else {
+        /*
+            The remaining 10 months form a regular pattern of 31 day months alternating with 30 day
+            months, with a 'phase change' between July and August (153 days after March 1).
+            We proceed by mapping our position into either March-July or August-December.
+            */
+        days -= n;
+        result = div(days, 153);
+        timeptr->tm_mon = 2 + result.quot * 5;
+
+        /* map into a 61 day pair of months */
+        result = div(result.rem, 61);
+        timeptr->tm_mon += result.quot * 2;
+
+        /* map into a month */
+        result = div(result.rem, 31);
+        timeptr->tm_mon += result.quot;
+        timeptr->tm_mday = result.rem;
+    }
+
+    /*
+            Cleanup and return
+        */
+    timeptr->tm_isdst = 0;  /* gmt is never in DST */
+    timeptr->tm_mday++; /* tm_mday is 1 based */
+
+}
diff --git a/time/isLeap.c b/time/isLeap.c
new file mode 100644 (file)
index 0000000..3c846aa
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isLeap.c 2325 2013-04-02 21:22:16Z swfltek $ */
+
+/*
+    Return 1 if 'year' is a leap year, else 0.
+*/
+
+#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;
+
+    /* If theres a remainder after division by 100, year is not divisible by 100 or 400 */
+    d = div(year, 100);
+    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;
+}
diff --git a/time/iso_week_date.c b/time/iso_week_date.c
new file mode 100644 (file)
index 0000000..efbf841
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: iso_week_date.c 2394 2013-05-04 10:26:24Z swfltek $ */
+
+/*
+    Compute the ISO 8601 week date corresponding to the given year and day of year.
+    See http://en.wikipedia.org/wiki/ISO_week_date for a full description.
+
+    See iso_week_date_r.c for implementation details.
+
+*/
+
+#include <time.h>
+
+extern char    *__asc_store;
+
+struct week_date *
+iso_week_date(int y, int yday)
+{
+    struct week_date *iso;
+
+    iso = (struct week_date *) __asc_store;
+    iso_week_date_r(y, yday, iso);
+    return iso;
+}
diff --git a/time/iso_week_date_r.c b/time/iso_week_date_r.c
new file mode 100644 (file)
index 0000000..ac1feb4
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: iso_week_date_r.c 2394 2013-05-04 10:26:24Z swfltek $ */
+
+/*
+    Compute the ISO 8601 week date corresponding to the given year and day of year.
+    See http://en.wikipedia.org/wiki/ISO_week_date for a full description. To summarize:
+
+        Weeks are numbered from 1 to 53.
+        Week days are numbered 1 to 7, beginning with Monday as day 1.
+
+        The first week of the year contains the first Thursday in that year.
+        Dates prior to week 1 belong to the final week of the previous year.
+
+        The final week of the year contains the last Thursday in that year.
+        Dates after the final week belong to week 1 of the following year.
+
+*/
+
+#include <time.h>
+
+void
+iso_week_date_r(int y, int yday, struct week_date * iso)
+{
+    uint16_t        years, n, wday;
+    int             weeknum;
+    int isLeap;
+
+    iso->year = y;
+
+    isLeap = is_leap_year(y);
+
+    /* compute days elapsed since epoch */
+    years = y - 2000;
+    n = 365 * years + yday;
+    if (years) {
+        n++;        /* epoch was a leap year */
+        n += years / 4;
+        n -= isLeap;
+        if (years > 100)
+            n--;
+    }
+
+    /* compute ISO8601 day of week (1 ... 7, Monday = 1) */
+    wday = n + 6; /* epoch was a Saturday */
+    wday %= 7;
+    if (wday == 0)
+        wday = 7;
+
+    iso->day = wday;
+
+    /* compute tentative week number */
+    weeknum = yday + 11 - wday;
+    weeknum /= 7;
+
+    /* if 53, it could be week 1 of the following year */
+    if (weeknum == 53) {
+        /*
+            The final week must include its Thursday in the year. We determine the yday of this
+            weeks Thursday, and test whether it exceeds this years length.
+        */
+
+        /* determine final yday of this year, 364 or 365 */
+        n = 364 + isLeap;
+
+        /* compute yday of this weeks Thursday */
+        wday--;       /* convert to zero based week, Monday = 0 */
+        yday -= wday; /* yday of this weeks Monday */
+        yday += 3;    /* yday of this weeks Thursday */
+
+        /* Is this weeks Thursday included in the year? */
+        if (yday > (int) n) {
+            iso->year++;
+            weeknum = 1;
+        }
+    }
+    iso->week = weeknum;
+
+    /*
+        If zero, it is the final week of the previous year.
+        We determine that by asking for the week number of Dec 31.
+    */
+    if (weeknum == 0) {
+        y = y - 1;
+        iso_week_date_r(y, 364 + is_leap_year(y), iso);
+        iso->day = wday;
+    }
+}
diff --git a/time/isotime.c b/time/isotime.c
new file mode 100644 (file)
index 0000000..a257815
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isotime.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+       This function returns ISO8601 formatted time, in our private buffer.
+*/
+
+#include <time.h>
+
+extern char    *__asc_store;
+
+char           *
+isotime(const struct tm * tmptr)
+{
+       isotime_r(tmptr, __asc_store);
+       return __asc_store;
+}
diff --git a/time/isotime_r.c b/time/isotime_r.c
new file mode 100644 (file)
index 0000000..5636a7f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: isotime_r.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+       Re entrant version of isotime(),  which prints the date and time in ISO 8601 format.
+*/
+
+#include <stdlib.h>
+#include <time.h>
+
+extern void __print_lz(int , char *, char );
+
+void
+isotime_r(const struct tm * tmptr, char *buffer)
+{
+       int             i;
+
+       i = tmptr->tm_year + 1900;
+       __print_lz(i/100, buffer, '-');
+       buffer+=2;
+       __print_lz(i%100, buffer,'-');
+       buffer+=3;
+
+       i = tmptr->tm_mon + 1;
+       __print_lz(i, buffer,'-');
+       buffer+=3;
+
+       i = tmptr->tm_mday;
+       __print_lz(i, buffer,' ');
+       buffer+=3;
+
+       i = tmptr->tm_hour;
+       __print_lz(i, buffer,':');
+       buffer+=3;
+
+       i = tmptr->tm_min;
+       __print_lz(i, buffer,':');
+       buffer+=3;
+
+       i = tmptr->tm_sec;
+       __print_lz(i, buffer,0);
+
+}
diff --git a/time/lm_sidereal.c b/time/lm_sidereal.c
new file mode 100644 (file)
index 0000000..ad34fac
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: lm_sidereal.c 2326 2013-04-02 21:23:41Z swfltek $ */
+
+/*
+    Local Mean Sidereal Time. See gm_sidereal() 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 += ONE_DAY;
+    n %= ONE_DAY;
+    return n;
+}
diff --git a/time/localtime.c b/time/localtime.c
new file mode 100644 (file)
index 0000000..0e18967
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: localtime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Standard localtime() function.
+*/
+
+#include <time.h>
+
+extern struct tm __tm_store;
+
+struct tm      *
+localtime(const time_t * timer)
+{
+       localtime_r(timer, &__tm_store);
+       return &__tm_store;
+}
diff --git a/time/localtime_r.c b/time/localtime_r.c
new file mode 100644 (file)
index 0000000..0bd1a02
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: localtime_r.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       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.h>
+
+extern long     __utc_offset;
+
+extern int      (*__dst_ptr) (const time_t *, int32_t *);
+
+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(&lt, timeptr);
+       timeptr->tm_isdst = dst;
+}
diff --git a/time/mk_gmtime.c b/time/mk_gmtime.c
new file mode 100644 (file)
index 0000000..7f2b9b9
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: mk_gmtime.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+    'Break down' a y2k time stamp into the elements of struct tm.
+    Unlike mktime(), this function does not 'normalize' the elements of timeptr.
+
+*/
+
+#include <time.h>
+
+time_t
+mk_gmtime(const struct tm * timeptr)
+{
+
+    time_t          ret;
+    uint32_t        tmp;
+    int             n, m, d, leaps;
+
+    /*
+        Determine elapsed whole days since the epoch to the beginning of this year. Since our epoch is
+        at a conjunction of the leap cycles, we can do this rather quickly.
+        */
+    n = timeptr->tm_year - 100;
+    leaps = 0;
+    if (n) {
+        m = n - 1;
+        leaps = m / 4;
+        leaps -= m / 100;
+        leaps++;
+    }
+    tmp = 365UL * n + leaps;
+
+    /*
+                Derive the day of year from month and day of month. We use the pattern of 31 day months
+                followed by 30 day months to our advantage, but we must 'special case' Jan/Feb, and
+                account for a 'phase change' between July and August (153 days after March 1).
+            */
+    d = timeptr->tm_mday - 1;   /* tm_mday is one based */
+
+    /* handle Jan/Feb as a special case */
+    if (timeptr->tm_mon < 2) {
+        if (timeptr->tm_mon)
+            d += 31;
+
+    } else {
+        n = 59 + is_leap_year(timeptr->tm_year + 1900);
+        d += n;
+        n = timeptr->tm_mon - MARCH;
+
+        /* account for phase change */
+        if (n > (JULY - MARCH))
+            d += 153;
+        n %= 5;
+
+        /*
+         * n is now an index into a group of alternating 31 and 30
+         * day months... 61 day pairs.
+         */
+        m = n / 2;
+        m *= 61;
+        d += m;
+
+        /*
+         * if n is odd, we are in the second half of the
+         * month pair
+         */
+        if (n & 1)
+            d += 31;
+    }
+
+    /* Add day of year to elapsed days, and convert to seconds */
+    tmp += d;
+    tmp *= ONE_DAY;
+    ret = tmp;
+
+    /* compute 'fractional' day */
+    tmp = timeptr->tm_hour;
+    tmp *= ONE_HOUR;
+    tmp += timeptr->tm_min * 60UL;
+    tmp += timeptr->tm_sec;
+
+    ret += tmp;
+
+    return ret;
+}
diff --git a/time/mktime.c b/time/mktime.c
new file mode 100644 (file)
index 0000000..1600202
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: mktime.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       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>
+
+extern long     __utc_offset;
+
+extern int      (*__dst_ptr) (const time_t *, int32_t *);
+
+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;
+}
diff --git a/time/month_length.c b/time/month_length.c
new file mode 100644 (file)
index 0000000..0f2f091
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: month_length.c 2358 2013-04-23 22:30:20Z swfltek $ */
+
+/*
+    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>
+
+uint8_t
+month_length(int year, uint8_t month)
+{
+    if (month == 2)
+        return 28 + is_leap_year(year);
+
+    /* 'knuckles' algorithm */
+    if (month > 7)
+        month++;
+    return 30 + (month & 1);
+}
diff --git a/time/moon_phase.c b/time/moon_phase.c
new file mode 100644 (file)
index 0000000..5fb5826
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: moon_phase.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+    Return an approximation to the phase of the moon. Since no attempt is made to account for
+    Sol, Jupiter or Venus, it will often be off by several hours.
+*/
+
+#include <time.h>
+#include <math.h>
+
+int8_t
+moon_phase(const time_t * timestamp)
+{
+       uint32_t        t;
+       int32_t         n;
+       double          mc;
+
+       /* refer to first new moon of the epoch */
+       t = *timestamp - 1744800UL;
+
+       /* constrain to 1 lunar cycle */
+       n = t % 2551443UL;
+
+       /* offset by 1/2 lunar cycle */
+       n -= 1275721L;
+       mc = n;
+       mc /= 1275721.0;
+       mc *= M_PI;
+       mc = cos(mc) * sin(mc);
+       mc *= 12.5;
+
+       /* scale to range - 100...+ 100 */
+       n /= 12757L;
+       n -= mc;
+
+       return n;
+}
diff --git a/time/print_lz.c b/time/print_lz.c
new file mode 100644 (file)
index 0000000..95c81bd
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: print_lz.c 2357 2013-04-21 16:25:30Z swfltek $ */
+
+/* print 2 digit integer with leading zero: auxillary function for isotime and asctime */
+
+#include <stdlib.h>
+
+void
+__print_lz(int i, char *buffer, char s)
+{
+    div_t result;
+
+    result = div(i, 10);
+
+       *buffer++ = result.quot + '0';
+       *buffer++ = result.rem + '0';
+       *buffer = s;
+}
diff --git a/time/set_dst.c b/time/set_dst.c
new file mode 100644 (file)
index 0000000..9ba0964
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_dst.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Set the dst function pointer.
+*/
+
+#include <inttypes.h>
+#include <time.h>
+
+extern int      (*__dst_ptr) (const time_t *, int32_t *);
+
+void
+set_dst(int (*d) (const time_t *, int32_t *))
+{
+       __dst_ptr = d;
+}
diff --git a/time/set_position.c b/time/set_position.c
new file mode 100644 (file)
index 0000000..e268316
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_position.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Set the geographic position of the observer. Both parameters are in seconds, with
+       North latitude and East longitude being positive values.
+*/
+
+extern long     __latitude;
+extern long     __longitude;
+
+void
+set_position(long lat, long lon)
+{
+       __latitude = lat;
+       __longitude = lon;
+}
diff --git a/time/set_system_time.c b/time/set_system_time.c
new file mode 100644 (file)
index 0000000..334790e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_system_time.c 2356 2013-04-21 16:20:01Z swfltek $ */
+
+/*
+ * 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(time_t timestamp)
+{
+
+       asm             volatile(
+                                          "in __tmp_reg__, __SREG__" "\n\t"
+                                                "cli" "\n\t"
+                                ::
+       );
+       __system_time = timestamp;
+       asm             volatile(
+                                         "out __SREG__, __tmp_reg__" "\n\t"
+                                ::
+       );
+}
diff --git a/time/set_zone.c b/time/set_zone.c
new file mode 100644 (file)
index 0000000..eb0f11b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: set_zone.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Set the system time zone. The parameter is seconds offset from UTC.
+*/
+
+extern long     __utc_offset;
+
+void
+set_zone(long z)
+{
+       __utc_offset = z;
+}
diff --git a/time/solar_declination.c b/time/solar_declination.c
new file mode 100644 (file)
index 0000000..dd89028
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: solar_declination.c 2369 2013-04-28 14:19:35Z swfltek $ */
+
+/*
+    Were it not for the eccentricity of Earths orbit, this would be a trivial function.
+
+    We compute the Earths orbital position with respect to perihelion, from which we derive a
+    'velocity correction factor'. We then compute the orbital angle with respect to the
+    December solstice, as 'modulated' by that correction factor.
+
+    Due to the accumulation of rounding errors, the computed December solstice of 2135 will lag
+    the actual solstice by many hours. A fudge factor, 'LAG', distributes the error across
+    the 136 year range of this library.
+*/
+
+#include <time.h>
+#include <math.h>
+#include "ephemera_common.h"
+
+#define LAG 38520
+
+double
+solar_declination(const time_t * timer)
+{
+
+    uint32_t        fT, oV;
+    double          dV, dT;
+
+    /* Determine orbital angle relative to perihelion of January 1999 */
+    oV = *timer % ANOM_YEAR;
+    oV += PERIHELION;
+    dV = oV;
+    dV /= ANOM_CYCLE;
+
+    /* Derive velocity correction factor from the perihelion angle */
+    dV = sin(dV);
+    dV *= DELTA_V;
+
+    /* Determine orbital angle relative to solstice of December 1999 */
+    fT = *timer % TROP_YEAR;
+    fT += SOLSTICE + LAG;
+    dT = fT;
+    dT /= TROP_CYCLE;
+    dT += dV;
+
+    /* Finally having the solstice angle, we can compute the declination */
+    dT = cos(dT) * INCLINATION;
+
+    return -dT;
+}
diff --git a/time/solar_noon.c b/time/solar_noon.c
new file mode 100644 (file)
index 0000000..65bafcc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: solar_noon.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+    Return the time of solar noon at the observers position
+*/
+
+#include <time.h>
+
+extern long     __longitude;
+
+time_t
+solar_noon(const time_t * timer)
+{
+    time_t          t;
+    long            n;
+
+    /* determine time of solar noon at the prime meridian */
+    t = *timer % ONE_DAY;
+    t = *timer - t;
+    t += 43200L;
+    t -= equation_of_time(timer);
+
+    /* rotate to observers longitude */
+    n = __longitude / 15L;
+    t -= n;
+
+    return t;
+
+}
diff --git a/time/strftime.c b/time/strftime.c
new file mode 100644 (file)
index 0000000..4dcfd30
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: strftime.c 2391 2013-05-03 20:53:06Z swfltek $ */
+
+/*
+    Standard strftime(). This is a memory hungry monster.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+extern long     __utc_offset;
+
+#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];
+    struct week_date wd;
+
+    count = length = 0;
+    while (count < limit) {
+        c = *pattern++;
+        if (c == '%') {
+            c = *pattern++;
+            if (c == 'E' || c == 'O')
+                c = *pattern++;
+            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'):
+                asctime_r(timeptr, _store);
+                length = 0;
+                while (_store[length])
+                    length++;
+                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 % 100 \
+                    );
+                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 ('g'):
+                       case ('G'):
+                               iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd);
+                if (c == 'g') {
+                    length = sprintf(_store, "%.2d", wd.year % 100);
+                } else {
+                    length = sprintf(_store, "%.4d", wd.year);
+                }
+
+                               break;
+
+            case ('H'):
+                length = sprintf(_store, "%.2u", timeptr->tm_hour);
+                break;
+
+            case ('I'):
+                d = timeptr->tm_hour % 12;
+                if (d == 0)
+                    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'):
+                d = timeptr->tm_hour % 12;
+                if (d == 0)
+                    d = 12;
+                length = sprintf(_store, "%2d:%.2d:%.2d AM", \
+                         d, \
+                         timeptr->tm_min, \
+                         timeptr->tm_sec \
+                    );
+                if (timeptr->tm_hour > 11)
+                    _store[10] = 'P';
+                break;
+
+            case ('R'):
+                length = sprintf(_store, "%.2d:%.2d", timeptr->tm_hour, timeptr->tm_min);
+                break;
+
+            case ('S'):
+                length = sprintf(_store, "%.2u", timeptr->tm_sec);
+                break;
+
+            case ('t'):
+                length = sprintf(_store, "\t");
+                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 ('V'):
+                               iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd);
+                length = sprintf(_store, "%.2u", wd.week);
+                               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 % 100);
+                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 < (int) 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;
+}
diff --git a/time/sun_rise.c b/time/sun_rise.c
new file mode 100644 (file)
index 0000000..b2ff62c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: sun_rise.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+    Return the approximate time of sun rise.
+*/
+
+#include <time.h>
+
+time_t
+sun_rise(const time_t * timer)
+{
+    long            n;
+    time_t          t;
+
+    /* sunrise is 1/2 'day' before solar noon */
+    t = solar_noon(timer);
+    n = daylight_seconds(timer) / 2L;
+    t -= n;
+
+    return t;
+}
diff --git a/time/sun_set.c b/time/sun_set.c
new file mode 100644 (file)
index 0000000..338e35f
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: sun_set.c 2365 2013-04-27 15:32:59Z swfltek $ */
+
+/*
+    Return the approximate time of sun set.
+*/
+
+#include <time.h>
+
+time_t
+sun_set(const time_t * timer)
+{
+    long            n;
+    time_t          t;
+
+    /* sunset is 1/2 'day' after solar noon */
+    t = solar_noon(timer);
+    n = daylight_seconds(timer) / 2L;
+    t += n;
+
+    return t;
+
+}
diff --git a/time/system_tick.S b/time/system_tick.S
new file mode 100644 (file)
index 0000000..c1f90fd
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: system_tick.S 2348 2013-04-16 23:42:05Z swfltek $ */
+
+/*
+    Impoved system_tick Credit to Wouter van Gulik.
+*/
+
+#include <avr/common.h>
+
+    .global    system_tick
+       .type   system_tick, @function
+system_tick:
+    push r24
+    in r24,_SFR_IO_ADDR(SREG)
+       push r24
+       cli
+    lds r24,__system_time+0
+    subi r24, (-1)
+    sts __system_time+0,r24
+    lds r24,__system_time+1
+    sbci r24, (-1)
+    sts __system_time+1,r24
+    lds r24,__system_time+2
+    sbci r24, (-1)
+    sts __system_time+2,r24
+    lds r24,__system_time+3
+    sbci r24, (-1)
+    sts __system_time+3,r24
+    pop r24
+    out _SFR_IO_ADDR(SREG),r24
+    pop r24
+    ret
+       .size   system_tick, .-system_tick
diff --git a/time/system_time.c b/time/system_time.c
new file mode 100644 (file)
index 0000000..64bdac7
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: system_time.c 2321 2013-04-02 00:12:48Z swfltek $ */
+
+/*
+       The system time stamp.
+*/
+#include <time.h>
+
+volatile time_t __system_time;
diff --git a/time/time.c b/time/time.c
new file mode 100644 (file)
index 0000000..e794322
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: time.c 2318 2013-03-30 11:59:28Z swfltek $ */
+
+/*
+       Standard time() function. Copying from __system_time must be atomic, since it
+       may be incremented at interrupt time.
+*/
+#include <time.h>
+#include <inttypes.h>
+
+extern 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;
+}
diff --git a/time/time.h b/time/time.h
new file mode 100644 (file)
index 0000000..21d86e9
--- /dev/null
@@ -0,0 +1,523 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: time.h 2427 2014-05-01 14:06:03Z amylaar $ */
+
+/** \file */
+
+/**    \defgroup avr_time <time.h>: Time
+    \code #include <time.h> \endcode
+    <h3>Introduction to the Time functions</h3>
+    This file declares the time functions implemented in \c avr-libc.
+
+    The implementation aspires to conform with ISO/IEC 9899 (C90). However, due to limitations of the
+    target processor and the nature of its development environment, a practical implementation must
+    of necessity deviate from the standard.
+
+
+
+    Section 7.23.2.1 clock()
+    The type clock_t, the macro CLOCKS_PER_SEC, and the function clock() are not implemented. We
+    consider these items belong to operating system code, or to application code when no operating
+    system is present.
+
+    Section 7.23.2.3 mktime()
+    The standard specifies that mktime() should return (time_t) -1, if the time cannot be represented.
+    This implementation always returns a 'best effort' representation.
+
+    Section 7.23.2.4 time()
+    The standard specifies that time() should return (time_t) -1, if the time is not available.
+    Since the application must initialize the time system, this functionality is not implemented.
+
+    Section 7.23.2.2, difftime()
+    Due to the lack of a 64 bit double, the function difftime() returns a long integer. In most cases
+    this change will be invisible to the user, handled automatically by the compiler.
+
+    Section 7.23.1.4 struct tm
+    Per the standard, struct tm->tm_isdst is greater than zero when Daylight Saving time is in effect.
+    This implementation further specifies that, when positive, the value of tm_isdst represents
+    the amount time is advanced during Daylight Saving time.
+
+    Section 7.23.3.5 strftime()
+    Only the 'C' locale is supported, therefore the modifiers 'E' and 'O' are ignored.
+    The 'Z' conversion is also ignored, due to the lack of time zone name.
+
+    In addition to the above departures from the standard, there are some behaviors which are different
+    from what is often expected, though allowed under the standard.
+
+    There is no 'platform standard' method to obtain the current time, time zone, or
+    daylight savings 'rules' in the AVR environment. Therefore the application must initialize
+    the time system with this information. The functions set_zone(), set_dst(), and
+    set_system_time() are provided for initialization. Once initialized, system time is maintained by
+    calling the function system_tick() at one second intervals.
+
+    Though not specified in the standard, it is often expected that time_t is a signed integer
+    representing an offset in seconds from Midnight Jan 1 1970... i.e. 'Unix time'. This implementation
+    uses an unsigned 32 bit integer offset from Midnight Jan 1 2000. The use of this 'epoch' helps to
+    simplify the conversion functions, while the 32 bit value allows time to be properly represented
+    until Tue Feb 7 06:28:15 2136 UTC. The macros UNIX_OFFSET and NTP_OFFSET are defined to assist in
+    converting to and from Unix and NTP time stamps.
+
+    Unlike desktop counterparts, it is impractical to implement or maintain the 'zoneinfo' database.
+    Therefore no attempt is made to account for time zone, daylight saving, or leap seconds in past dates.
+    All calculations are made according to the currently configured time zone and daylight saving 'rule'.
+
+    In addition to C standard functions, re-entrant versions of ctime(), asctime(), gmtime() and
+    localtime() are provided which, in addition to being re-entrant, have the property of claiming
+    less permanent storage in RAM. An additional time conversion, isotime() and its re-entrant version,
+    uses far less storage than either ctime() or asctime().
+
+    Along with the usual smattering of utility functions, such as is_leap_year(), this library includes
+    a set of functions related the sun and moon, as well as sidereal time functions.
+*/
+
+#ifndef TIME_H
+#define TIME_H
+
+#ifdef __cplusplus
+extern          "C" {
+#endif
+
+#include <inttypes.h>
+#include <stdlib.h>
+
+    /** \ingroup avr_time */
+    /* @{ */
+
+    /**
+        time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the Y2K 'epoch').
+        Its range allows this implementation to represent time up to Tue Feb 7 06:28:15 2136 UTC.
+    */
+    typedef uint32_t time_t;
+
+    /**
+    The time function returns the systems current time stamp.
+    If timer is not a null pointer, the return value is also assigned to the object it points to.
+    */
+    time_t          time(time_t *timer);
+
+    /**
+    The difftime function returns the difference between two binary time stamps,
+    time1 - time0.
+    */
+    int32_t         difftime(time_t time1, time_t time0);
+
+
+    /**
+        The tm structure contains a representation of time 'broken down' into components of the
+        Gregorian calendar.
+
+        The normal ranges of the elements are..
+
+    \code
+        tm_sec      seconds after the minute - [ 0 to 59 ]
+        tm_min      minutes after the hour - [ 0 to 59 ]
+        tm_hour     hours since midnight - [ 0 to 23 ]
+        tm_mday     day of the month - [ 1 to 31 ]
+        tm_wday     days since Sunday - [ 0 to 6 ]
+        tm_mon      months since January - [ 0 to 11 ]
+        tm_year     years since 1900
+        tm_yday     days since January 1 - [ 0 to 365 ]
+        tm_isdst    Daylight Saving Time flag *
+
+    \endcode
+
+        *The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if
+        the information is not available.
+
+        When Daylight Saving Time is in effect, the value represents the number of
+        seconds the clock is advanced.
+
+        See the set_dst() function for more information about Daylight Saving.
+
+    */
+    struct tm {
+        int8_t          tm_sec;
+        int8_t          tm_min;
+        int8_t          tm_hour;
+        int8_t          tm_mday;
+        int8_t          tm_wday;
+        int8_t          tm_mon;
+        int16_t         tm_year;
+        int16_t         tm_yday;
+        int16_t         tm_isdst;
+    };
+
+    
+    /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can
+       be built.  We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_
+       so that the user can provide the value on the link line, which should
+       result in little or no run-time overhead compared with a constant.  */
+    typedef unsigned long clock_t;
+    extern char *_CLOCKS_PER_SEC_;
+#define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_)
+    extern clock_t clock(void);
+
+    /**
+    This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
+    The elements of timeptr are interpreted as representing Local Time.
+
+    The original values of the tm_wday and tm_yday elements of the structure are ignored,
+    and the original values of the other elements are not restricted to the ranges stated for struct tm.
+
+    On successful completion, the values of all elements of timeptr are set to the appropriate range.
+    */
+    time_t          mktime(struct tm * timeptr);
+
+    /**
+    This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
+    The elements of timeptr are interpreted as representing UTC.
+
+    The original values of the tm_wday and tm_yday elements of the structure are ignored,
+    and the original values of the other elements are not restricted to the ranges stated for struct tm.
+
+    Unlike mktime(), this function DOES NOT modify the elements of timeptr.
+    */
+    time_t          mk_gmtime(const struct tm * timeptr);
+
+    /**
+    The gmtime function converts the time stamp pointed to by timer into broken-down time,
+    expressed as UTC.
+    */
+    struct tm      *gmtime(const time_t * timer);
+
+    /**
+        Re entrant version of gmtime().
+    */
+    void            gmtime_r(const time_t * timer, struct tm * timeptr);
+
+    /**
+    The localtime function converts the time stamp pointed to by timer into broken-down time,
+    expressed as Local time.
+    */
+    struct tm      *localtime(const time_t * timer);
+
+    /**
+        Re entrant version of localtime().
+    */
+    void            localtime_r(const time_t * timer, struct tm * timeptr);
+
+    /**
+    The asctime function converts the broken-down time of timeptr, into an ascii string in the form
+
+        Sun Mar 23 01:03:52 2013
+    */
+    char           *asctime(const struct tm * timeptr);
+
+    /**
+        Re entrant version of asctime().
+    */
+    void            asctime_r(const struct tm * timeptr, char *buf);
+
+    /**
+        The ctime function is equivalent to asctime(localtime(timer))
+    */
+    char           *ctime(const time_t * timer);
+
+    /**
+        Re entrant version of ctime().
+    */
+    void            ctime_r(const time_t * timer, char *buf);
+
+    /**
+    The isotime function constructs an ascii string in the form
+        \code2013-03-23 01:03:52\endcode
+    */
+    char           *isotime(const struct tm * tmptr);
+
+    /**
+        Re entrant version of isotime()
+    */
+    void            isotime_r(const struct tm *, char *);
+
+    /**
+    A complete description of strftime() is beyond the pale of this document.
+    Refer to ISO/IEC document 9899 for details.
+
+    All conversions are made using the 'C Locale', ignoring the E or O modifiers. Due to the lack of
+    a time zone 'name', the 'Z' conversion is also ignored.
+    */
+    size_t          strftime(char *s, size_t maxsize, const char *format, const struct tm * timeptr);
+
+    /**
+        Specify the Daylight Saving function.
+
+        The Daylight Saving function should examine its parameters to determine whether
+        Daylight Saving is in effect, and return a value appropriate for tm_isdst.
+
+        Working examples for the USA and the EU are available..
+
+            \code #include <util/eu_dst.h>\endcode
+            for the European Union, and
+            \code #include <util/usa_dst.h>\endcode
+            for the United States
+
+        If a Daylight Saving function is not specified, the system will ignore Daylight Saving.
+    */
+    void            set_dst(int (*) (const time_t *, int32_t *));
+
+    /**
+        Set the 'time zone'. The parameter is given in seconds East of the Prime Meridian.
+        Example for New York City:
+        \code set_zone(-5 * ONE_HOUR);\endcode
+
+        If the time zone is not set, the time system will operate in UTC only.
+    */
+    void            set_zone(int32_t);
+
+    /**
+        Initialize the system time. Examples are...
+
+        From a Clock / Calendar type RTC:
+        \code
+        struct tm rtc_time;
+
+        read_rtc(&rtc_time);
+        rtc_time.tm_isdst = 0;
+        set_system_time( mktime(&rtc_time) );
+        \endcode
+
+        From a Network Time Protocol time stamp:
+        \code
+        set_system_time(ntp_timestamp - NTP_OFFSET);
+        \endcode
+
+        From a UNIX time stamp:
+         \code
+        set_system_time(unix_timestamp - UNIX_OFFSET);
+        \endcode
+
+    */
+    void            set_system_time(time_t timestamp);
+
+    /**
+        Maintain the system time by calling this function at a rate of 1 Hertz.
+
+        It is anticipated that this function will typically be called from within an
+        Interrupt Service Routine, (though that is not required). It therefore includes code which
+        makes it simple to use from within a 'Naked' ISR, avoiding the cost of saving and restoring
+        all the cpu registers.
+
+        Such an ISR may resemble the following example...
+        \code
+            ISR(RTC_OVF_vect, ISR_NAKED)
+            {
+                system_tick();
+                reti();
+            }
+        \endcode
+    */
+    void            system_tick(void);
+
+    /**
+        Enumerated labels for the days of the week.
+    */
+    enum _WEEK_DAYS_ {
+        SUNDAY,
+        MONDAY,
+        TUESDAY,
+        WEDNESDAY,
+        THURSDAY,
+        FRIDAY,
+        SATURDAY
+    };
+
+    /**
+        Enumerated labels for the months.
+    */
+    enum _MONTHS_ {
+        JANUARY,
+        FEBRUARY,
+        MARCH,
+        APRIL,
+        MAY,
+        JUNE,
+        JULY,
+        AUGUST,
+        SEPTEMBER,
+        OCTOBER,
+        NOVEMBER,
+        DECEMBER
+    };
+
+    /**
+        Return 1 if year is a leap year, zero if it is not.
+    */
+    uint8_t         is_leap_year(int16_t year);
+
+    /**
+        Return the length of month, given the year and month, where month is in the range 1 to 12.
+     */
+    uint8_t         month_length(int16_t year, uint8_t month);
+
+    /**
+        Return the calendar week of year, where week 1 is considered to begin on the
+        day of week specified by 'start'. The returned value may range from zero to 52.
+    */
+    uint8_t         week_of_year(const struct tm * timeptr, uint8_t start);
+
+    /**
+        Return the calendar week of month, where the first week is considered to begin on the
+        day of week specified by 'start'. The returned value may range from zero to 5.
+    */
+    uint8_t         week_of_month(const struct tm * timeptr, uint8_t start);
+
+    /**
+        Structure which represents a date as a year, week number of that year, and day of week.
+        See http://en.wikipedia.org/wiki/ISO_week_date for more information.
+    */
+    struct week_date{
+        int year;
+        int week;
+        int day;
+    };
+
+    /**
+        Return a week_date structure with the ISO_8601 week based date corresponding to the given
+        year and day of year. See http://en.wikipedia.org/wiki/ISO_week_date for more
+        information.
+    */
+    struct week_date * iso_week_date( int year, int yday);
+
+    /**
+        Re-entrant version of iso-week_date.
+    */
+    void iso_week_date_r( int year, int yday, struct week_date *);
+
+    /**
+        Convert a Y2K time stamp into a FAT file system time stamp.
+    */
+    uint32_t        fatfs_time(const struct tm * timeptr);
+
+    /** One hour, expressed in seconds */
+#define ONE_HOUR 3600
+
+    /** Angular degree, expressed in arc seconds */
+#define ONE_DEGREE 3600
+
+    /** One day, expressed in seconds */
+#define ONE_DAY 86400
+
+    /** Difference between the Y2K and the UNIX epochs, in seconds. To convert a Y2K
+        timestamp to UNIX...
+        \code
+        long unix;
+        time_t y2k;
+
+        y2k = time(NULL);
+        unix = y2k + UNIX_OFFSET;
+        \endcode
+    */
+#define UNIX_OFFSET 946684800
+
+    /** Difference between the Y2K and the NTP epochs, in seconds. To convert a Y2K
+        timestamp to NTP...
+        \code
+        unsigned long ntp;
+        time_t y2k;
+
+        y2k = time(NULL);
+        ntp = y2k + NTP_OFFSET;
+        \endcode
+    */
+#define NTP_OFFSET 3155673600
+
+    /*
+     * ===================================================================
+     *                              Ephemera
+     */
+
+    /**
+        Set the geographic coordinates of the 'observer', for use with several of the
+        following functions. Parameters are passed as seconds of North Latitude, and seconds
+        of East Longitude.
+
+        For New York City...
+        \code set_position( 40.7142 * ONE_DEGREE, -74.0064 * ONE_DEGREE); \endcode
+    */
+    void            set_position(int32_t latitude, int32_t longitude);
+
+    /**
+        Computes the difference between apparent solar time and mean solar time.
+        The returned value is in seconds.
+    */
+    int16_t         equation_of_time(const time_t * timer);
+
+    /**
+        Computes the amount of time the sun is above the horizon, at the location of the observer.
+
+        NOTE: At observer locations inside a polar circle, this value can be zero during the winter,
+        and can exceed ONE_DAY during the summer.
+
+        The returned value is in seconds.
+    */
+    int32_t         daylight_seconds(const time_t * timer);
+
+    /**
+        Computes the time of solar noon, at the location of the observer.
+    */
+    time_t          solar_noon(const time_t * timer);
+
+    /**
+        Return the time of sunrise, at the location of the observer. See the note about daylight_seconds().
+    */
+    time_t          sun_rise(const time_t * timer);
+
+    /**
+        Return the time of sunset, at the location of the observer. See the note about daylight_seconds().
+    */
+    time_t          sun_set(const time_t * timer);
+
+    /** Returns the declination of the sun in radians. */
+    double          solar_declination(const time_t * timer);
+
+    /**
+        Returns an approximation to the phase of the moon.
+        The sign of the returned value indicates a waning or waxing phase.
+        The magnitude of the returned value indicates the percentage illumination.
+    */
+    int8_t          moon_phase(const time_t * timer);
+
+    /**
+        Returns Greenwich Mean Sidereal Time, as seconds into the sidereal day.
+        The returned value will range from 0 through 86399 seconds.
+    */
+    unsigned long   gm_sidereal(const time_t * timer);
+
+    /**
+        Returns Local Mean Sidereal Time, as seconds into the sidereal day.
+        The returned value will range from 0 through 86399 seconds.
+    */
+    unsigned long   lm_sidereal(const time_t * timer);
+
+    /* @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif              /* TIME_H  */
diff --git a/time/tm_store.c b/time/tm_store.c
new file mode 100644 (file)
index 0000000..af8229b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: tm_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */
+
+/*
+       Private allocation, used by gmtime() and localtime()
+*/
+
+#include <time.h>
+
+struct tm       __tm_store;
diff --git a/time/utc_offset.c b/time/utc_offset.c
new file mode 100644 (file)
index 0000000..14c8180
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: utc_offset.c 2321 2013-04-02 00:12:48Z swfltek $ */
+
+/*
+       UTC offset in seconds East
+*/
+
+long            __utc_offset;
diff --git a/time/week_of_month.c b/time/week_of_month.c
new file mode 100644 (file)
index 0000000..6eca94f
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * (c)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: week_of_month.c 2362 2013-04-26 22:22:46Z swfltek $ */
+
+/*
+       Return the week of month, where 'base' represents the starting day.
+       In the USA, the week is generally considered to start on 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 * timestruct, uint8_t base)
+{
+       int             first, n;
+
+       /* zero base the day of month */
+       n = timestruct->tm_mday - 1;
+
+       /* find the first base day of the month (start of week 1) */
+       first = 7 + n - timestruct->tm_wday + base;
+       first %= 7;
+
+       /* find days since the first week began */
+       n = n - first;
+
+       /* if negative, we are in week 0 */
+       if (n < 0)
+               return 0;
+
+       return n / 7 + 1;
+
+}
diff --git a/time/week_of_year.c b/time/week_of_year.c
new file mode 100644 (file)
index 0000000..ad06f62
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: week_of_year.c 2362 2013-04-26 22:22:46Z swfltek $ */
+
+/*
+       Return the week of year, where 'base' represents the first day of the week.
+       In the USA, the week is generally considered to start on Sunday (base = 0),
+       while in Europe it is generally considered to be Monday (base = 1).
+
+       Return value ranges from 0 to 52.
+*/
+
+#include <time.h>
+
+uint8_t
+week_of_year(const struct tm * timestruct, uint8_t base)
+{
+       int             first, n;
+
+       /* find the first base day of the year (start of week 1) */
+       first = 7 + timestruct->tm_yday - timestruct->tm_wday + base;
+    first %= 7;
+
+       /* find days since that first base day*/
+       n = timestruct->tm_yday - first;
+
+       /* if negative, we are in week 0 */
+       if (n < 0)
+               return 0;
+
+       return n / 7 + 1;
+}