Exemple #1
0
YMD
jd2ymd(JD jd)
{
    YMD ymd;
    double j;
    double x;
    int y, m, d;

    j = jdGetDay(jd);
    j2gcal(&y, &m, &d, j);
    ymdSetYear(ymd, y);
    ymdSetMonth(ymd, m);
    ymdSetDay(ymd, (double)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;
    }
    ymdIncDay(ymd, x);

    /* pick up the hours, minutes, and seconds */
    ymd.hms = jd.hms;

    return(ymd);
}
Exemple #2
0
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);
}