Annotation of sbbs/src/xpdev/datewrap.h, revision 1.1.1.1

1.1       root        1: /* datewrap.h */
                      2: 
                      3: /* Wrappers for Borland getdate() and gettime() functions */
                      4: 
                      5: /* $Id: datewrap.h,v 1.17 2005/09/28 02:09:54 rswindell Exp $ */
                      6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
                     11:  * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html         *
                     12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser General Public License          *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #ifndef _DATEWRAP_H_
                     39: #define _DATEWRAP_H_
                     40: 
                     41: #include "genwrap.h"   /* time_t */
                     42: 
                     43: /* Compensates for struct tm "weirdness" */
                     44: time_t sane_mktime(struct tm*);
                     45: 
                     46: /**************************************/
                     47: /* Cross-platform date/time functions */
                     48: /**************************************/
                     49: 
                     50: typedef struct {
                     51:        unsigned        year;
                     52:        unsigned        month;
                     53:        unsigned        day;
                     54: } xpDate_t;
                     55: 
                     56: typedef struct {
                     57:        unsigned        hour;
                     58:        unsigned        minute;
                     59:        float           second; /* supports fractional seconds */
                     60: } xpTime_t;
                     61: 
                     62: typedef int xpTimeZone_t;
                     63: 
                     64: typedef struct {
                     65:        xpDate_t                date;
                     66:        xpTime_t                time;
                     67:        xpTimeZone_t    zone;   /* minutes +/- UTC */
                     68: } xpDateTime_t;
                     69: 
                     70: xpDateTime_t   xpDateTime_create(unsigned year, unsigned month, unsigned day
                     71:                                                                   ,unsigned hour, unsigned minute, float second
                     72:                                                                   ,xpTimeZone_t);
                     73: xpDateTime_t   xpDateTime_now(void);
                     74: time_t                 xpDateTime_to_time(xpDateTime_t);
                     75: xpDateTime_t   time_to_xpDateTime(time_t);
                     76: xpTimeZone_t   xpTimeZone_local(void);
                     77: 
                     78: /**********************************************/
                     79: /* Decimal-coded ISO-8601 date/time functions */
                     80: /**********************************************/
                     81: 
                     82: typedef ulong  isoDate_t;      /* CCYYMMDD (decimal) */
                     83: typedef ulong  isoTime_t;      /* HHMMSS   (decimal) */
                     84: 
                     85: #define                        isoDate_create(year,mon,day)    (((year)*10000)+((mon)*100)+(day))
                     86: #define                        isoTime_create(hour,min,sec)    (((hour)*10000)+((min)*100)+((unsigned)sec))
                     87:                                
                     88: #define                        isoDate_year(date)                              ((date)/10000)
                     89: #define                        isoDate_month(date)                             (((date)/100)%100)
                     90: #define                        isoDate_day(date)                               ((date)%100)
                     91:                                                                                                
                     92: #define                        isoTime_hour(time)                              ((time)/10000)
                     93: #define                        isoTime_minute(time)                    (((time)/100)%100)
                     94: #define                        isoTime_second(time)                    ((time)%100)
                     95: 
                     96: BOOL                   isoTimeZone_parse(const char* str, xpTimeZone_t*);
                     97: xpDateTime_t   isoDateTime_parse(const char* str);
                     98: 
                     99: /**********************************************/
                    100: /* Conversion between time_t and isoDate/Time */
                    101: /**********************************************/
                    102: isoTime_t              time_to_isoTime(time_t);
                    103: isoDate_t              time_to_isoDateTime(time_t, isoTime_t*);
                    104: time_t                 isoDateTime_to_time(isoDate_t, isoTime_t);
                    105: #define                        time_to_isoDate(t)              time_to_isoDateTime(t,NULL)
                    106: 
                    107: /***************************************************/
                    108: /* Conversion between xpDate/Time and isoDate/Time */
                    109: /***************************************************/
                    110: 
                    111: #define                        xpDate_to_isoDate(date) isoDate_create((date).year,(date).month,(date).day)
                    112: #define                        xpTime_to_isoTime(time) isoTime_create((time).hour,(time).minute,(unsigned)((time).second))
                    113: 
                    114: xpDateTime_t   isoDateTime_to_xpDateTime(isoDate_t, isoTime_t);
                    115: isoDate_t              xpDateTime_to_isoDateTime(xpDateTime_t, isoTime_t*);
                    116: 
                    117: /***********************************/
                    118: /* Borland DOS date/time functions */
                    119: /***********************************/
                    120: 
                    121: #if defined(__BORLANDC__)
                    122: 
                    123: #include <dos.h>
                    124: 
                    125: #else 
                    126: 
                    127: struct date {
                    128:        short da_year;
                    129:        char  da_day;
                    130:        char  da_mon;
                    131: };
                    132: 
                    133: struct time {
                    134:        unsigned char ti_min;
                    135:        unsigned char ti_hour;
                    136:        unsigned char ti_hund;
                    137:        unsigned char ti_sec;
                    138: };
                    139: 
                    140: #if defined(__cplusplus)
                    141: extern "C" {
                    142: #endif
                    143: 
                    144: #define getdate(x)     xp_getdate(x)
                    145: void xp_getdate(struct date*);
                    146: void gettime(struct time*);
                    147: 
                    148: #if defined(__cplusplus)
                    149: }
                    150: #endif
                    151: 
                    152: #endif /* !Borland */
                    153: 
                    154: #endif /* Don't add anything after this line */
                    155: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.