00001
00002
00003
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <windowsx.h>
00007
00008 #include <OSTR.H>
00009 #include <OMISC.H>
00010 #include <ODATE.H>
00011
00012
00013
00014 #define JULIAN_ADJUSTMENT 1721425L
00015
00016 static char month_str_array[][10] = {
00017 "January",
00018 "February",
00019 "March",
00020 "April",
00021 "May",
00022 "June",
00023 "July",
00024 "August",
00025 "September",
00026 "October",
00027 "November",
00028 "December"
00029 } ;
00030
00031 static int month_tot[]=
00032 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
00033 ;
00034
00035
00036
00037
00038
00050
00051 long total, dayYear ;
00052
00053 dayYear = day_year( year, month, day) ;
00054
00055 if (dayYear < 1)
00056 return( -1) ;
00057
00058 total = ytoj(year) ;
00059 total+= dayYear ;
00060 total+= JULIAN_ADJUSTMENT ;
00061
00062 return total;
00063 }
00064
00065
00066
00067
00078
00079 return julian( m.atoi( dateStr,4 ), m.atoi( dateStr+4,2 ),
00080 m.atoi( dateStr+6,2 ) );
00081 }
00082
00083
00084
00085
00095
00096 int year, month, day, nDays, maxDays ;
00097 long totalDays ;
00098
00099
00100 if ( julianDate > 5373484 || julianDate < JULIAN_ADJUSTMENT )
00101 return -1;
00102
00103 totalDays = (long) (julianDate) - JULIAN_ADJUSTMENT ;
00104 year = (int) ((double)totalDays/365.2425) + 1 ;
00105 nDays = (int) (totalDays - ytoj(year)) ;
00106
00107 if ( nDays <= 0 ) {
00108 year-- ;
00109 nDays = (int) (totalDays - ytoj(year)) ;
00110 }
00111
00112 if (year%4 == 0 && year%100 != 0 || year%400 == 0)
00113 maxDays = 366 ;
00114 else
00115 maxDays = 365 ;
00116
00117 if ( nDays > maxDays ) {
00118 year++ ;
00119 nDays -= maxDays ;
00120 }
00121
00122 if ( month_day( year, nDays, month, day ) < 0 )
00123 return -1;
00124
00125
00126
00127 switch( returnType ) {
00128 case 'Y':
00129 return year;
00130
00131 case 'M':
00132 return month;
00133
00134 case 'D':
00135 return day;
00136 }
00137
00138 return 0;
00139 }
00140
00141
00142
00143
00159
00160 int year, month, day, nDays, maxDays ;
00161 long totalDays ;
00162 static char strBuf[10];
00163
00164 if ( julianDate > 5373484 || julianDate < JULIAN_ADJUSTMENT ) {
00165 strBuf[0]=NULL;
00166 return strBuf;
00167 }
00168
00169 totalDays = (long) (julianDate) - JULIAN_ADJUSTMENT ;
00170 year = (int) ((double)totalDays/365.2425) + 1 ;
00171 nDays = (int) (totalDays - ytoj(year)) ;
00172
00173 if ( nDays <= 0 ) {
00174 year-- ;
00175 nDays = (int) (totalDays - ytoj(year)) ;
00176 }
00177
00178 if (year%4 == 0 && year%100 != 0 || year%400 == 0)
00179 maxDays = 366 ;
00180 else
00181 maxDays = 365 ;
00182
00183 if ( nDays > maxDays ) {
00184 year++ ;
00185 nDays -= maxDays ;
00186 }
00187
00188 if ( month_day( year, nDays, month, day ) < 0 ) {
00189 strBuf[0]=NULL;
00190 return strBuf;
00191 }
00192
00193
00194
00195 static String str;
00196
00197 str = month_str_array[month-1];
00198
00199 if( shortMonthStr )
00200 str = str.left(3);
00201
00202 if( showDate ) {
00203 str += " ";
00204 str += itoa(day,strBuf,10);
00205 str += ",";
00206 }
00207 str += " Yr.";
00208 str += itoa(year,strBuf,10);
00209
00210 return str;
00211 }
00212
00213
00214
00215
00221
00222 return month_str_array[monthNo-1];
00223 }
00224
00225
00226
00227
00234
00235 int DateInfo::day_year( int year, int month, int day ) {
00236 int isLeap, monthDays ;
00237
00238 isLeap = ( year%4 == 0 && year%100 != 0 || year%400 == 0 ) ? 1 : 0 ;
00239
00240 monthDays = month_tot[ month+1 ] - month_tot[ month] ;
00241 if ( month == 2 ) monthDays += isLeap ;
00242
00243 if ( year < 0 ||
00244 month < 1 || month > 12 ||
00245 day < 1 || day > monthDays )
00246 return( -1 ) ;
00247
00248 if ( month <= 2 ) isLeap = 0 ;
00249
00250 return( month_tot[month] + day + isLeap ) ;
00251 }
00252
00253
00254
00255
00266
00267 long DateInfo::ytoj( int yr ) {
00268 yr-- ;
00269 return( yr*365L + yr/4L - yr/100L + yr/400L ) ;
00270 }
00271
00272
00273
00274
00279
00280 int isLeap, i ;
00281
00282 isLeap = ( year%4 == 0 && year%100 != 0 || year%400 == 0 ) ? 1 : 0 ;
00283 if ( days <= 59 ) isLeap = 0 ;
00284
00285 for( i = 2; i <= 13; i++) {
00286 if ( days <= month_tot[i] + isLeap ) {
00287 monthRef = --i ;
00288 if ( i <= 2) isLeap = 0 ;
00289
00290 dayRef = days - month_tot[ i] - isLeap ;
00291 return( 0) ;
00292 }
00293 }
00294 dayRef = 0 ;
00295 monthRef = 0 ;
00296
00297 return( -1 ) ;
00298 }
00299
00300
00301
00302
00308
00309
00310 static char strBuf[6] = "00:00";
00311
00312
00313 strBuf[4] = '0' + inTime % 10;
00314 strBuf[3] = '0' + (inTime/10) % 10;
00315 strBuf[1] = '0' + (inTime/100) % 10;
00316 strBuf[0] = '0' + (inTime/1000) % 10;
00317
00318
00319 return strBuf;
00320 }
00321
00322
00323
00324
00332
00333 return month_tot[inMonth+1] - month_tot[inMonth];
00334 }
00335
00336
00337
00338
00347
00348 int inYear = year(inDate);
00349 int inMonth = month(inDate);
00350 int inDay = day(inDate);
00351
00352 inMonth += addMonth;
00353
00354 if( inMonth > 12 ) {
00355 inMonth -= 12;
00356 inYear++;
00357 }
00358
00359 if( inDay > days_in_month(inMonth) )
00360 inDay = days_in_month(inMonth);
00361
00362 return julian( inYear, inMonth, inDay );
00363 }
00364
00365
00366
00367
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 return 0;
00385 }
00386
00387