| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

days_to_date

#include "sfldate.h"
long
days_to_date (long days)

Synopsis

Converts a number of days since some distant but unspecified epoch into a date. You can use this function to calculate differences between dates, and forward dates. Use date to days() to calculate the reverse function. Author: Robert G. Tantzen, translated from the Algol original in Collected Algorithms of the CACM (algorithm 199). Original translation into C by Nat Howard, posted to Usenet 5 Jul 1985.

Source Code - (sfldate.c)

{
    long
        century,
        year,
        month,
        day;

    days   -= 1721119L;
    century = (4L * days - 1L) / 146097L;
    days    =  4L * days - 1L  - 146097L * century;
    day     =  days / 4L;

    year    = (4L * day + 3L) / 1461L;
    day     =  4L * day + 3L  - 1461L * year;
    day     = (day + 4L) / 4L;

    month   = (5L * day - 3L) / 153L;
    day     =  5L * day - 3   - 153L * month;
    day     = (day + 5L) / 5L;

    if (month < 10)
        month += 3;
    else
      {
        month -= 9;
        if (year++ == 99)
          {
            year = 0;
            century++;
          }
      }
    return (MAKE_DATE (century, year, month, day));
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation