Main Page   Compound List   File List   Compound Members   File Members  

date.h

Go to the documentation of this file.
00001 /*
00002 ** date.h
00003 **
00004 ** libdate - A C library for manipulating dates
00005 ** Copyright (C) 2000 James Williams
00006 **
00007 ** This library is free software; you can redistribute it and/or
00008 ** modify it under the terms of the GNU Lesser General Public
00009 ** License as published by the Free Software Foundation; either
00010 ** version 2 of the License, or (at your option) any later version.
00011 **
00012 ** This library is distributed in the hope that it will be useful,
00013 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 ** Lesser General Public License for more details.
00016 **
00017 ** You should have received a copy of the GNU Lesser General Public
00018 ** License along with this library; if not, write to the Free Software
00019 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 **
00021 */
00022 
00023 #ifndef DATE_H
00024 #define DATE_H
00025 
00026 #define DT_INTERVAL_DAY        1
00027 #define DT_INTERVAL_MONTH      2
00028 #define DT_INTERVAL_MONTH_DOW  3
00029 
00030 #define DT_FIRST      1
00031 #define DT_SECOND     2
00032 #define DT_THIRD      3
00033 #define DT_FOURTH     4
00034 #define DT_LAST       5
00035 
00036 #define DT_SUNDAY     0
00037 #define DT_MONDAY     1
00038 #define DT_TUESDAY    2
00039 #define DT_WEDNESDAY  3
00040 #define DT_THURSDAY   4
00041 #define DT_FRIDAY     5
00042 #define DT_SATURDAY   6
00043 #define DT_DAY        10
00044 
00045 #define DT_JANUARY    1
00046 #define DT_FEBRUARY   2
00047 #define DT_MARCH      3
00048 #define DT_APRIL      4
00049 #define DT_MAY        5
00050 #define DT_JUNE       6
00051 #define DT_JULY       7
00052 #define DT_AUGUST     8
00053 #define DT_SEPTEMBER  9
00054 #define DT_OCTOBER    10
00055 #define DT_NOVEMBER   11
00056 #define DT_DECEMBER   12
00057 
00058 /* For calculating the phase of the moon */
00059 #define DT_LUNAR_PERIOD    29.5305882
00060 #define DT_NEWMOON_OFFSET  17.7800836001
00061 
00062 /* For ASCII output of dates */
00063 #define DT_ASCII_BUFFER_SIZE  32
00064 #define DT_NUMERIC_OUT        0x01
00065 #define DT_US_FORMAT          0x02
00066 #define DT_EUROPE_FORMAT      0x04
00067 #define DT_UNIVERSAL_FORMAT   0x08
00068 
00069 /* How to free an event structure */
00070 #define DT_FREE_ALL           1
00071 #define DT_FREE_NONE          2
00072 
00073 /* Day of week adjustment sign modifiers */
00074 #define DT_PREV              -1
00075 #define DT_NONE               0
00076 #define DT_NEXT               1
00077 
00090 typedef struct
00091 {
00092   long int rata_die;  
00093   int greg_calced;  
00094   int year;  
00095   int month;  
00096   int day;  
00097 } DT_DATE;
00098 
00109 typedef struct
00110 {
00111   DT_DATE *start_date;  
00112   DT_DATE *end_date; 
00113   int interval_type; 
00114   int interval_length; 
00115   int event_length;  
00116   int ordinal; 
00117   int day; 
00118   int adj_rel; 
00119   int adj_sign; 
00120   int adj_dow; 
00121   char *pattern; 
00122   void *data;  
00123 } DT_EVENT;
00124 
00125 /* Macros */
00126 
00128 #define DT_is_leap_year(x)  (DT_year(x)%400==0 \
00129                              || (DT_year(x)%100!=0 && DT_year(x)%4==0))
00130 
00132 #define DT_is_leap_year_q(x)  ((x)%400==0 || ((x)%100!=0 && (x)%4==0))
00133 
00135 #define DT_set_year(date,year)  DT_set_date((date),(year),DT_month(date), \
00136                                 DT_day(date))
00137 
00139 #define DT_set_month(date,month)  DT_set_date((date),DT_year(date), \
00140                                   (month), DT_day(date))
00141 
00143 #define DT_set_day(date,day)  DT_set_date((date),DT_year(date), \
00144                               DT_month(date), (day))
00145 
00146 DT_DATE *DT_mkdate(int year, int month, int day);
00147 DT_DATE *DT_mkdate_dow(int ordinal, int dow, int month, int year);
00148 DT_DATE *DT_mkdate_rata_die(long int rata_die);
00149 void DT_rmdate(DT_DATE *date);
00150 DT_DATE *DT_copy_date(DT_DATE *date);
00151 long int DT_days_between(DT_DATE *date1, DT_DATE *date2);
00152 long int DT_months_between(DT_DATE *date1, DT_DATE *date2);
00153 char *DT_ascii(DT_DATE *date, unsigned long int format);
00154 char *DT_ascii_r(char *buffer, int buf_size, DT_DATE *date,
00155                  unsigned long int format);
00156 char *DT_dow_ascii(DT_DATE *date);
00157 void DT_set_date(DT_DATE *date, int year, int month, int day);
00158 void DT_set_rata_die(DT_DATE *date, long int rata_die);
00159 int DT_dow(DT_DATE *date);
00160 int DT_year(DT_DATE *date);
00161 int DT_month(DT_DATE *date);
00162 int DT_day(DT_DATE *date);
00163 long int DT_rata_die(DT_DATE *date);
00164 void DT_add_days(DT_DATE *date, long int days);
00165 void DT_add_months(DT_DATE *date, long int months);
00166 void DT_find_dow_date(DT_DATE *date, int ordinal, int dow, int month);
00167 int DT_days_this_month(DT_DATE *date);
00168 int DT_days_this_month_q(int year, int month);
00169 void DT_easter(DT_DATE *date);
00170 
00171 DT_EVENT *DT_mkevent(DT_DATE *start, DT_DATE *end, long int interval);
00172 DT_EVENT *DT_mkevent_monthly(DT_DATE *start, DT_DATE *end,
00173                              long int interval, int day);
00174 DT_EVENT *DT_mkevent_monthly_dow(DT_DATE *start, DT_DATE *end,
00175                                  long int interval, int ordinal, int dow);
00176 void DT_rmevent(DT_EVENT *event, int freeall);
00177 void DT_event_adj_rel(DT_EVENT *event, int adj);
00178 void DT_event_adj_dow(DT_EVENT *event, int sign, int dow);
00179 void DT_event_multiday(DT_EVENT *event, int len);
00180 void DT_event_pattern(DT_EVENT *event, char *pattern);
00181 int DT_is_event_today(DT_DATE *date, DT_EVENT *event);
00182 DT_DATE *DT_event_next(DT_DATE *date, DT_EVENT *event);
00183 
00184 int DT_cal_rows(DT_DATE *date);
00185 int DT_cal_day_to_row(DT_DATE *date);
00186 int DT_cal_day_to_col(DT_DATE *date);
00187 int DT_cal_row_col_to_day(DT_DATE *date, int row, int col);
00188 
00189 double DT_moon_age(DT_DATE *date, int timezone);
00190 #endif  /* DATE_H */

Generated at Fri May 12 15:50:03 2000 for Date Manipulation Library by doxygen 1.1.3 written by Dimitri van Heesch, © 1997-2000