OSSP CVS Repository

ossp - Check-in [2119]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2119
Date: 2002-May-01 20:48:34 (local)
2002-May-01 18:48:34 (UTC)
User:rse
Branch:
Comment: flush todays work
Tickets:
Inspections:
Files:
ossp-pkg/tai/Makefile.in      1.2 -> 1.3     1 inserted, 1 deleted
ossp-pkg/tai/tai_cal.c      added-> 1.1
ossp-pkg/tai/tai_lib.c      1.3 -> 1.4     8 inserted, 1 deleted
ossp-pkg/tai/tai_p.h      1.2 -> 1.3     4 inserted, 0 deleted
ossp-pkg/tai/tai_test.c      1.1 -> 1.2     13 inserted, 0 deleted

ossp-pkg/tai/Makefile.in 1.2 -> 1.3

--- Makefile.in  2002/04/29 19:19:48     1.2
+++ Makefile.in  2002/05/01 18:48:34     1.3
@@ -50,7 +50,7 @@
 TRUE        = true
 
 LIB_NAME    = libtai.la
-LIB_OBJS    = tai_lib.lo tai_format.lo tai_parse.lo tai_data.lo tai_ui64.lo
+LIB_OBJS    = tai_lib.lo tai_format.lo tai_parse.lo tai_data.lo tai_cal.lo tai_ui64.lo
 
 TST_NAME    = tai_test
 TST_OBJS    = tai_test.o ts.o


ossp-pkg/tai/tai_cal.c -> 1.1

*** /dev/null    Sat Nov 23 01:18:55 2024
--- -    Sat Nov 23 01:19:12 2024
***************
*** 0 ****
--- 1,154 ----
+ /*
+ **  OSSP tai - Time Handling
+ **  Copyright (c) 2002 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 2002 The OSSP Project <http://www.ossp.org/>
+ **  Copyright (c) 2002 Cable & Wireless Deutschland <http://www.cw.com/de/>
+ **
+ **  This file is part of OSSP tai, a time handling library
+ **  which can be found at http://www.ossp.org/pkg/lib/tai/.
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  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.
+ **
+ **  tai_calendar.c: calendar calculations
+ */
+ 
+ #include "tai.h"
+ #include "tai_p.h"
+ 
+ #if 0
+ struct leap {
+     tai_ui64_t leapsec;
+ } tai_tab_leapsec[] = {
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1972 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1972 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1973 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1974 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1975 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1976 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1977 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1978 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1979 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1981 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1982 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1983 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1985 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1987 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1989 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1990 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1992 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1993 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1994 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1995 Dec 31 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1997 Jun 30 23:59:60 + */
+     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }  /* 1998 Dec 31 23:59:60 + */
+ };
+ #endif
+ 
+ #define TAI_CAL_SUNDAY       0
+ #define TAI_CAL_MONDAY       1
+ #define TAI_CAL_TUESDAY      2
+ #define TAI_CAL_WEDNESDAY    3
+ #define TAI_CAL_THURSDAY     4
+ #define TAI_CAL_FRIDAY       5
+ #define TAI_CAL_SATURDAY     6
+ 
+ #define TAI_CAL_JANUARY      0
+ #define TAI_CAL_FEBRUARY     1
+ #define TAI_CAL_MARCH        2
+ #define TAI_CAL_APRIL        3
+ #define TAI_CAL_MAY          4
+ #define TAI_CAL_JUNE         5
+ #define TAI_CAL_JULY         6
+ #define TAI_CAL_AUGUST       7
+ #define TAI_CAL_SEPTEMBER    8
+ #define TAI_CAL_OCTOBER      9
+ #define TAI_CAL_NOVEMBER     10
+ #define TAI_CAL_DECEMBER     11
+ 
+ #define TAI_EPOCH "9223372036854775808" /* 2^62 / 2 (=2^63) meaning 1972-01-01 00:00:00 UTC was 1972-01-01 00:00:10 TAI */
+ #define TAI_EPOCH_YEAR      1970
+ #define TAI_EPOCH_WDAY      TAI_CAL_THURSDAY
+ 
+ /* the Gregorian calendar */
+ #define TAI_CAL_SECS_PER_MIN      60
+ #define TAI_CAL_MINS_PER_HOUR     60
+ #define TAI_CAL_HOURS_PER_DAY     24
+ #define TAI_CAL_DAYS_PER_WEEK     7
+ #define TAI_CAL_DAYS_PER_NYEAR    365
+ #define TAI_CAL_DAYS_PER_LYEAR    366
+ #define TAI_CAL_SECS_PER_HOUR     (TAI_CAL_SECS_PER_MIN * TAI_CAL_MINS_PER_HOUR)
+ #define TAI_CAL_SECS_PER_DAY      (TAI_CAL_SECS_PER_HOUR * TAI_CAL_HOURS_PER_DAY)
+ #define TAI_CAL_MONS_PER_YEAR     12
+ 
+ #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+ 
+ tai_rc_t tai_tai2cal(tai_t *tai, int offset)
+ {
+     tai_ui64_t secs;
+     tai_ui64_t days;
+     tai_ui64_t rem;
+     tai_ui64_t tmp;
+     tai_ui64_t tmp2;
+     int lshit;
+ 
+     secs = tai->sec;
+ 
+     /* perform leap second correction */
+     lshit = 0; /* FIXME */
+ 
+     /* perform timezone offset correction */
+     secs = tai_ui64_addn(secs, offset, NULL);
+ 
+     /* days = secs / TAI_CAL_SECS_PER_DAY
+        rem  = secs % TAI_CAL_SECS_PER_DAY */
+     tmp  = tai_ui64_n2i(TAI_CAL_SECS_PER_DAY);
+     days = tai_ui64_div(secs, tmp, &rem);
+ 
+     /* hour = rem / TAI_CAL_SECS_PER_HOUR
+        rem  = rem % TAI_CAL_SECS_PER_HOUR */
+     tmp  = tai_ui64_n2i(TAI_CAL_SECS_PER_HOUR);
+     tmp = tai_ui64_div(rem, tmp, &rem);
+     tai->tai_hour = (int)tai_ui64_i2n(tmp);
+ 
+     /* min = rem / TAI_CAL_SECS_PER_MIN
+        rem = rem % TAI_CAL_SECS_PER_MIN */
+     tmp  = tai_ui64_n2i(TAI_CAL_SECS_PER_MIN);
+     tmp = tai_ui64_div(rem, tmp, &rem);
+     tai->tai_min = (int)tai_ui64_i2n(tmp);
+ 
+     /* sec = rem + lshit */
+     tai->tai_sec = (int)tai_ui64_i2n(rem) + lshit;
+ 
+     /* wday = (TAI_EPOCH_WDAY + days) % TAI_CAL_DAYS_PER_WEEK */
+     /* FIXME: TAI is not 0 on EPOCH */
+     tmp = tai_ui64_addn(days, TAI_EPOCH_WDAY, NULL);
+     tmp2 = tai_ui64_n2i(TAI_CAL_DAYS_PER_WEEK);
+     tai_ui64_div(tmp, tmp2, &tmp);
+     tai->tai_wday = (int)tai_ui64_i2n(tmp);
+ 
+     tai->tai_gmtoff = (long)offset;
+     
+     return TAI_OK;
+ }
+ 
+ tai_rc_t tai_cal2tai(tai_t *tai)
+ {
+     return TAI_OK;
+ }
+ 


ossp-pkg/tai/tai_lib.c 1.3 -> 1.4

--- tai_lib.c    2002/04/29 19:24:41     1.3
+++ tai_lib.c    2002/05/01 18:48:34     1.4
@@ -25,7 +25,7 @@
 **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 **  SUCH DAMAGE.
 **
-**  tm.c: API implementation
+**  tai_lib.c: API implementation
 */
 
 #include <stdio.h>
@@ -127,6 +127,13 @@
         else
             tai->tai_zone = strdup(stm->tm_zone);
     }
+    else if (type == TAI_TYPE_UNIX) {
+        /* import from time(3) FIXME */
+        time_t t = time(NULL);
+        tai->sec  = tai_ui64_n2i((unsigned long)t);
+        tai->asec = tai_ui64_n2i((unsigned long)0);
+        tai_tai2cal(tai, 7200);
+    }
     else
         return TAI_ERR_IMP; /* FIXME */
     va_end(ap); 


ossp-pkg/tai/tai_p.h 1.2 -> 1.3

--- tai_p.h      2002/04/29 19:24:41     1.2
+++ tai_p.h      2002/05/01 18:48:34     1.3
@@ -32,6 +32,7 @@
 #include <time.h>
 
 #include "config.h"
+#include "tai.h"
 #include "tai_ui64.h"
 
 struct tai_st {
@@ -78,4 +79,7 @@
 size_t  tai_format_int(char *const s, const size_t maxsize, const char *const format, const struct tm *const t);
 char   *tai_parse_int (const char *buf, const char *fmt, struct tm *tm);
 
+tai_rc_t tai_tai2cal(tai_t *tai, int offset);
+tai_rc_t tai_cal2tai(tai_t *tai);
+
 #endif /* !_TIMELOCAL_H_ */


ossp-pkg/tai/tai_test.c 1.1 -> 1.2

--- tai_test.c   2002/04/18 09:10:45     1.1
+++ tai_test.c   2002/05/01 18:48:34     1.2
@@ -36,6 +36,18 @@
 #include "ts.h"
 #include "tai.h"
 
+TS_TEST(test_calendar)
+{
+    tai_t *tai;
+    char out[1024];
+
+    ts_test_check(TS_CTX, "calendar calculations");
+    tai_create(&tai);
+    tai_import(tai, TAI_TYPE_UNIX);
+    tai_format(tai, out, sizeof(out), "%a %Y-%m-%d %H:%M:%S %z");
+    fprintf(stdout, "\n<%s>\n", out);
+    tai_destroy(tai);
+}
 TS_TEST(test_object)
 {
     tai_t *tm;
@@ -127,6 +139,7 @@
     int n;
 
     ts = ts_suite_new("OSSP tai (Time Handling)");
+    ts_suite_test(ts, test_calendar,     "calendar calculations");
     ts_suite_test(ts, test_object,       "object handling");
     ts_suite_test(ts, test_importexport, "time import/export");
     ts_suite_test(ts, test_parsing,      "time parsing");

CVSTrac 2.0.1