Back to index

php5  5.3.10
Defines | Functions | Variables
gregor.c File Reference
#include "sdncal.h"
#include <limits.h>

Go to the source code of this file.

Defines

#define GREGOR_SDN_OFFSET   32045
#define DAYS_PER_5_MONTHS   153
#define DAYS_PER_4_YEARS   1461
#define DAYS_PER_400_YEARS   146097

Functions

void SdnToGregorian (long int sdn, int *pYear, int *pMonth, int *pDay)
long int GregorianToSdn (int inputYear, int inputMonth, int inputDay)

Variables

char * MonthNameShort [13]
char * MonthNameLong [13]

Define Documentation

#define DAYS_PER_400_YEARS   146097

Definition at line 135 of file gregor.c.

#define DAYS_PER_4_YEARS   1461

Definition at line 134 of file gregor.c.

#define DAYS_PER_5_MONTHS   153

Definition at line 133 of file gregor.c.

#define GREGOR_SDN_OFFSET   32045

Definition at line 132 of file gregor.c.


Function Documentation

long int GregorianToSdn ( int  inputYear,
int  inputMonth,
int  inputDay 
)

Definition at line 193 of file gregor.c.

{
       int year;
       int month;

       /* check for invalid dates */
       if (inputYear == 0 || inputYear < -4714 ||
              inputMonth <= 0 || inputMonth > 12 ||
              inputDay <= 0 || inputDay > 31) {
              return (0);
       }
       /* check for dates before SDN 1 (Nov 25, 4714 B.C.) */
       if (inputYear == -4714) {
              if (inputMonth < 11) {
                     return (0);
              }
              if (inputMonth == 11 && inputDay < 25) {
                     return (0);
              }
       }
       /* Make year always a positive number. */
       if (inputYear < 0) {
              year = inputYear + 4801;
       } else {
              year = inputYear + 4800;
       }

       /* Adjust the start of the year. */
       if (inputMonth > 2) {
              month = inputMonth - 3;
       } else {
              month = inputMonth + 9;
              year--;
       }

       return (((year / 100) * DAYS_PER_400_YEARS) / 4
                     + ((year % 100) * DAYS_PER_4_YEARS) / 4
                     + (month * DAYS_PER_5_MONTHS + 2) / 5
                     + inputDay
                     - GREGOR_SDN_OFFSET);
}

Here is the caller graph for this function:

void SdnToGregorian ( long int  sdn,
int pYear,
int pMonth,
int pDay 
)

Definition at line 137 of file gregor.c.

{
       int century;
       int year;
       int month;
       int day;
       long int temp;
       int dayOfYear;

       if (sdn <= 0 ||
                     sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
              goto fail;
       }
       temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;

       /* Calculate the century (year/100). */
       century = temp / DAYS_PER_400_YEARS;

       /* Calculate the year and day of year (1 <= dayOfYear <= 366). */
       temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
       year = (century * 100) + (temp / DAYS_PER_4_YEARS);
       dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1;

       /* Calculate the month and day of month. */
       temp = dayOfYear * 5 - 3;
       month = temp / DAYS_PER_5_MONTHS;
       day = (temp % DAYS_PER_5_MONTHS) / 5 + 1;

       /* Convert to the normal beginning of the year. */
       if (month < 10) {
              month += 3;
       } else {
              year += 1;
              month -= 9;
       }

       /* Adjust to the B.C./A.D. type numbering. */
       year -= 4800;
       if (year <= 0)
              year--;

       *pYear = year;
       *pMonth = month;
       *pDay = day;
       return;

fail:
       *pYear = 0;
       *pMonth = 0;
       *pDay = 0;
}

Here is the caller graph for this function:


Variable Documentation

char* MonthNameLong[13]
Initial value:
{
       "",
       "January",
       "February",
       "March",
       "April",
       "May",
       "June",
       "July",
       "August",
       "September",
       "October",
       "November",
       "December"
}

Definition at line 255 of file gregor.c.

char* MonthNameShort[13]
Initial value:
{
       "",
       "Jan",
       "Feb",
       "Mar",
       "Apr",
       "May",
       "Jun",
       "Jul",
       "Aug",
       "Sep",
       "Oct",
       "Nov",
       "Dec"
}

Definition at line 238 of file gregor.c.