Back to index

php5  5.3.10
Functions | Variables
sdncal.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void SdnToGregorian (long int sdn, int *pYear, int *pMonth, int *pDay)
long int GregorianToSdn (int year, int month, int day)
void SdnToJulian (long int sdn, int *pYear, int *pMonth, int *pDay)
long int JulianToSdn (int year, int month, int day)
void SdnToJewish (long int sdn, int *pYear, int *pMonth, int *pDay)
long int JewishToSdn (int year, int month, int day)
void SdnToFrench (long int sdn, int *pYear, int *pMonth, int *pDay)
long int FrenchToSdn (int inputYear, int inputMonth, int inputDay)
int DayOfWeek (long int sdn)

Variables

char * MonthNameShort [13]
char * MonthNameLong [13]
char * JewishMonthName [14]
char * JewishMonthHebName [14]
char * FrenchMonthName [14]
char * DayNameShort [7]
char * DayNameLong [7]

Function Documentation

int DayOfWeek ( long int  sdn)

Definition at line 34 of file dow.c.

{
       int dow;

       dow = (sdn + 1) % 7;
       if (dow >= 0) {
              return (dow);
       } else {
              return (dow + 7);
       }
}

Here is the caller graph for this function:

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

Definition at line 117 of file french.c.

{
       /* check for invalid dates */
       if (year < 1 || year > 14 ||
              month < 1 || month > 13 ||
              day < 1 || day > 30) {
              return (0);
       }
       return ((year * DAYS_PER_4_YEARS) / 4
                     + (month - 1) * DAYS_PER_MONTH
                     + day
                     + FRENCH_SDN_OFFSET);
}

Here is the caller graph for this function:

long int GregorianToSdn ( int  year,
int  month,
int  day 
)

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:

long int JewishToSdn ( int  year,
int  month,
int  day 
)

Definition at line 646 of file jewish.c.

{
       long int sdn;
       int metonicCycle;
       int metonicYear;
       int tishri1;
       int tishri1After;
       long int moladDay;
       long int moladHalakim;
       int yearLength;
       int lengthOfAdarIAndII;

       if (year <= 0 || day <= 0 || day > 30) {
              return (0);
       }
       switch (month) {
              case 1:
              case 2:
                     /* It is Tishri or Heshvan - don't need the year length. */
                     FindStartOfYear(year, &metonicCycle, &metonicYear,
                                                 &moladDay, &moladHalakim, &tishri1);
                     if (month == 1) {
                            sdn = tishri1 + day - 1;
                     } else {
                            sdn = tishri1 + day + 29;
                     }
                     break;

              case 3:
                     /* It is Kislev - must find the year length. */

                     /* Find the start of the year. */
                     FindStartOfYear(year, &metonicCycle, &metonicYear,
                                                 &moladDay, &moladHalakim, &tishri1);

                     /* Find the end of the year. */
                     moladHalakim += HALAKIM_PER_LUNAR_CYCLE * monthsPerYear[metonicYear];
                     moladDay += moladHalakim / HALAKIM_PER_DAY;
                     moladHalakim = moladHalakim % HALAKIM_PER_DAY;
                     tishri1After = Tishri1((metonicYear + 1) % 19, moladDay, moladHalakim);

                     yearLength = tishri1After - tishri1;

                     if (yearLength == 355 || yearLength == 385) {
                            sdn = tishri1 + day + 59;
                     } else {
                            sdn = tishri1 + day + 58;
                     }
                     break;

              case 4:
              case 5:
              case 6:
                     /* It is Tevet, Shevat or Adar I - don't need the year length. */

                     FindStartOfYear(year + 1, &metonicCycle, &metonicYear,
                                                 &moladDay, &moladHalakim, &tishri1After);

                     if (monthsPerYear[(year - 1) % 19] == 12) {
                            lengthOfAdarIAndII = 29;
                     } else {
                            lengthOfAdarIAndII = 59;
                     }

                     if (month == 4) {
                            sdn = tishri1After + day - lengthOfAdarIAndII - 237;
                     } else if (month == 5) {
                            sdn = tishri1After + day - lengthOfAdarIAndII - 208;
                     } else {
                            sdn = tishri1After + day - lengthOfAdarIAndII - 178;
                     }
                     break;

              default:
                     /* It is Adar II or later - don't need the year length. */
                     FindStartOfYear(year + 1, &metonicCycle, &metonicYear,
                                                 &moladDay, &moladHalakim, &tishri1After);

                     switch (month) {
                            case 7:
                                   sdn = tishri1After + day - 207;
                                   break;
                            case 8:
                                   sdn = tishri1After + day - 178;
                                   break;
                            case 9:
                                   sdn = tishri1After + day - 148;
                                   break;
                            case 10:
                                   sdn = tishri1After + day - 119;
                                   break;
                            case 11:
                                   sdn = tishri1After + day - 89;
                                   break;
                            case 12:
                                   sdn = tishri1After + day - 60;
                                   break;
                            case 13:
                                   sdn = tishri1After + day - 30;
                                   break;
                            default:
                                   return (0);
                     }
       }
       return (sdn + JEWISH_SDN_OFFSET);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long int JulianToSdn ( int  year,
int  month,
int  day 
)

Definition at line 215 of file julian.c.

{
       int year;
       int month;

       /* check for invalid dates */
       if (inputYear == 0 || inputYear < -4713 ||
              inputMonth <= 0 || inputMonth > 12 ||
              inputDay <= 0 || inputDay > 31) {
              return (0);
       }
       /* check for dates before SDN 1 (Jan 2, 4713 B.C.) */
       if (inputYear == -4713) {
              if (inputMonth == 1 && inputDay == 1) {
                     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 * DAYS_PER_4_YEARS) / 4
                     + (month * DAYS_PER_5_MONTHS + 2) / 5
                     + inputDay
                     - JULIAN_SDN_OFFSET);
}

Here is the caller graph for this function:

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

Definition at line 95 of file french.c.

{
       long int temp;
       int dayOfYear;

       if (sdn < FIRST_VALID || sdn > LAST_VALID) {
              *pYear = 0;
              *pMonth = 0;
              *pDay = 0;
              return;
       }
       temp = (sdn - FRENCH_SDN_OFFSET) * 4 - 1;
       *pYear = temp / DAYS_PER_4_YEARS;
       dayOfYear = (temp % DAYS_PER_4_YEARS) / 4;
       *pMonth = dayOfYear / DAYS_PER_MONTH + 1;
       *pDay = dayOfYear % DAYS_PER_MONTH + 1;
}

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:

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

Definition at line 507 of file jewish.c.

{
       long int inputDay;
       long int day;
       long int halakim;
       int metonicCycle;
       int metonicYear;
       int tishri1;
       int tishri1After;
       int yearLength;

       if (sdn <= JEWISH_SDN_OFFSET) {
              *pYear = 0;
              *pMonth = 0;
              *pDay = 0;
              return;
       }
       inputDay = sdn - JEWISH_SDN_OFFSET;

       FindTishriMolad(inputDay, &metonicCycle, &metonicYear, &day, &halakim);
       tishri1 = Tishri1(metonicYear, day, halakim);

       if (inputDay >= tishri1) {
              /* It found Tishri 1 at the start of the year. */
              *pYear = metonicCycle * 19 + metonicYear + 1;
              if (inputDay < tishri1 + 59) {
                     if (inputDay < tishri1 + 30) {
                            *pMonth = 1;
                            *pDay = inputDay - tishri1 + 1;
                     } else {
                            *pMonth = 2;
                            *pDay = inputDay - tishri1 - 29;
                     }
                     return;
              }
              /* We need the length of the year to figure this out, so find
               * Tishri 1 of the next year. */
              halakim += HALAKIM_PER_LUNAR_CYCLE * monthsPerYear[metonicYear];
              day += halakim / HALAKIM_PER_DAY;
              halakim = halakim % HALAKIM_PER_DAY;
              tishri1After = Tishri1((metonicYear + 1) % 19, day, halakim);
       } else {
              /* It found Tishri 1 at the end of the year. */
              *pYear = metonicCycle * 19 + metonicYear;
              if (inputDay >= tishri1 - 177) {
                     /* It is one of the last 6 months of the year. */
                     if (inputDay > tishri1 - 30) {
                            *pMonth = 13;
                            *pDay = inputDay - tishri1 + 30;
                     } else if (inputDay > tishri1 - 60) {
                            *pMonth = 12;
                            *pDay = inputDay - tishri1 + 60;
                     } else if (inputDay > tishri1 - 89) {
                            *pMonth = 11;
                            *pDay = inputDay - tishri1 + 89;
                     } else if (inputDay > tishri1 - 119) {
                            *pMonth = 10;
                            *pDay = inputDay - tishri1 + 119;
                     } else if (inputDay > tishri1 - 148) {
                            *pMonth = 9;
                            *pDay = inputDay - tishri1 + 148;
                     } else {
                            *pMonth = 8;
                            *pDay = inputDay - tishri1 + 178;
                     }
                     return;
              } else {
                     if (monthsPerYear[(*pYear - 1) % 19] == 13) {
                            *pMonth = 7;
                            *pDay = inputDay - tishri1 + 207;
                            if (*pDay > 0)
                                   return;
                            (*pMonth)--;
                            (*pDay) += 30;
                            if (*pDay > 0)
                                   return;
                            (*pMonth)--;
                            (*pDay) += 30;
                     } else {
                            *pMonth = 6;
                            *pDay = inputDay - tishri1 + 207;
                            if (*pDay > 0)
                                   return;
                            (*pMonth)--;
                            (*pDay) += 30;
                     }
                     if (*pDay > 0)
                            return;
                     (*pMonth)--;
                     (*pDay) += 29;
                     if (*pDay > 0)
                            return;

                     /* We need the length of the year to figure this out, so find
                      * Tishri 1 of this year. */
                     tishri1After = tishri1;
                     FindTishriMolad(day - 365,
                                                 &metonicCycle, &metonicYear, &day, &halakim);
                     tishri1 = Tishri1(metonicYear, day, halakim);
              }
       }

       yearLength = tishri1After - tishri1;
       day = inputDay - tishri1 - 29;
       if (yearLength == 355 || yearLength == 385) {
              /* Heshvan has 30 days */
              if (day <= 30) {
                     *pMonth = 2;
                     *pDay = day;
                     return;
              }
              day -= 30;
       } else {
              /* Heshvan has 29 days */
              if (day <= 29) {
                     *pMonth = 2;
                     *pDay = day;
                     return;
              }
              day -= 29;
       }

       /* It has to be Kislev. */
       *pMonth = 3;
       *pDay = day;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 155 of file julian.c.

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

       if (sdn <= 0) {
              goto fail;
       }
       /* Check for overflow */
       if (sdn > (LONG_MAX - JULIAN_SDN_OFFSET * 4 + 1) / 4 || sdn < LONG_MIN / 4) {
              goto fail;
       }
       temp = sdn * 4 + (JULIAN_SDN_OFFSET * 4 - 1);

       /* Calculate the year and day of year (1 <= dayOfYear <= 366). */
       {
              long yearl = temp / DAYS_PER_4_YEARS;
              if (yearl > INT_MAX || yearl < INT_MIN) {
                     goto fail;
              }
              year = (int) yearl;
       }
       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* DayNameLong[7]

Definition at line 58 of file dow.c.

char* DayNameShort[7]

Definition at line 47 of file dow.c.

char* FrenchMonthName[14]

Definition at line 134 of file french.c.

char* JewishMonthHebName[14]

Definition at line 318 of file jewish.c.

char* JewishMonthName[14]

Definition at line 300 of file jewish.c.

char* MonthNameLong[13]

Definition at line 255 of file gregor.c.

char* MonthNameShort[13]

Definition at line 238 of file gregor.c.