double ymd2dd(YMD ymd) { double dd; double j0; double j; /* normalize the time */ ymd = ymd2ymd(ymd); /* get the julian day number of the target date */ j = ymd2j(ymd); /* get the julian day number of the start of the year */ j0 = gcal2j(ymdGetYear(ymd), 1, 1) - 0.5; dd = j - j0 + 1; return(dd); }
char * fmt_ymd(YMD ymd) { char *p; double j; /* julian day number of target time */ int fpart; int ipart; int today; /* get a buffer */ p = ymdbuf[nxtymdbuf++]; nxtymdbuf %= NYMDBUF; /* normalize the time */ ymd = ymd2ymd(ymd); /* get the julian day number */ j = ymd2j(ymd); /* get the day of the week */ today = j2dow(j); ipart = (int)ymdGetSeconds(ymd); fpart = 1e3 * (ymdGetSeconds(ymd) - ipart); (void)sprintf(p, "%3.3s %3.3s %2d %02d:%02d:%02d.%03d %4d", dow[today], moy[ymdGetMonth(ymd)-1], (int)ymdGetDay(ymd), (int)ymdGetHours(ymd), (int)ymdGetMinutes(ymd), ipart, fpart, ((ymdGetYear(ymd) > 0) ? ymdGetYear(ymd) : (1-ymdGetYear(ymd)))); if (ymdGetYear(ymd) <= 0) { (void)strcat(p, " BC"); } return(p); }
YMD ymd2ymd(YMD ymd) { double j; /* julian day number */ double x; int y, m, d; j = ymd2j(ymd); j2gcal(&y, &m, &d, j); ymdSetYear(ymd, y); ymdSetMonth(ymd, m); ymdSetDay(ymd, d); x = j - floor(j); /* ** we do this next step because the rounding of j in j2gcal() ** either credits or debits us with 12 hours */ if (x < 0.5) { x += 0.5; } else { x -= 0.5; } /* promote the hours */ x = (x - floor(x)) * 24.0; ymdSetHours(ymd, floor(x)); /* promote the minutes */ x = (x - floor(x)) * 60.0; ymdSetMinutes(ymd, floor(x)); /* promote the seconds */ x = (x - floor(x)) * 60.0; ymdSetSeconds(ymd, x); return(ymd); }