00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <math.h>
00022 #include <stdlib.h>
00023 #ifndef _REENTRANT
00024 #define _REENTRANT
00025 #endif
00026 #ifndef __USE_POSIX
00027 #define __USE_POSIX
00028 #endif
00029 #include <time.h>
00030
00031 #include <lal/LALStdlib.h>
00032 #include <lal/Date.h>
00033 #include <lal/AVFactories.h>
00034
00035 INT4 lalDebugLevel = 0;
00036
00037 NRCSID (LALTESTDATESTRINGC, "$Id: TestDateString.c,v 1.11 2007/06/08 14:41:43 bema Exp $");
00038
00039 int main(int argc, char **argv)
00040 {
00041 static LALStatus stat;
00042 time_t tmpsecs;
00043 LALDate date;
00044 CHAR refstamp[128];
00045 CHARVector *timestamp = NULL;
00046
00047 if (argc > 1)
00048 lalDebugLevel = atoi(argv[1]);
00049
00050 LALCHARCreateVector(&stat, ×tamp, (UINT4)64);
00051
00052 if (stat.statusCode && lalDebugLevel > 0)
00053 {
00054 fprintf(stderr,
00055 "TestDateString: error in LALCHARCreateVector, line %i, %s\n",
00056 __LINE__, LALTESTDATESTRINGC);
00057 REPORTSTATUS(&stat);
00058 return stat.statusCode;
00059 }
00060 if (lalDebugLevel > 2)
00061 REPORTSTATUS(&stat);
00062
00063 tmpsecs = (24*365 + 8*366 + 2*31 + 28)*86400 - 1;
00064 gmtime_r(&tmpsecs, &(date.unixDate));
00065
00066 LALDateString(&stat, timestamp, &date);
00067
00068 if (stat.statusCode && lalDebugLevel > 0)
00069 {
00070 fprintf(stderr,
00071 "TestDateString: LALDateString() failed, line %i, %s\n",
00072 __LINE__, LALTESTDATESTRINGC);
00073 REPORTSTATUS(&stat);
00074 return stat.statusCode;
00075 }
00076
00077 if (!stat.statusCode)
00078 {
00079 sprintf(refstamp, "2002-03-31 23:59:59 UTC Sun");
00080 if (lalDebugLevel > 2)
00081 {
00082 fprintf(stderr, "refstamp = %s\n", refstamp);
00083 fprintf(stderr, "timestamp = %s\n", timestamp->data);
00084 }
00085 }
00086
00087 if (strcmp(refstamp, timestamp->data) == 0)
00088 {
00089 LALCHARDestroyVector(&stat, ×tamp);
00090 if (lalDebugLevel > 2)
00091 REPORTSTATUS(&stat);
00092 LALCheckMemoryLeaks();
00093 return 0;
00094 }
00095 else
00096 {
00097 LALCHARDestroyVector(&stat, ×tamp);
00098 REPORTSTATUS(&stat);
00099 LALCheckMemoryLeaks();
00100 return 1;
00101 }
00102 }