//
// Usage: rd = rd_from_gregorian( GDATE *gdate )
// Description: Compute the R.D. date (rd) given a gregorian date (GDATE *gdate).
//
int
rd_from_gregorian(GDATE *gdate)
{
GDATE rd;
rd = gregorian_epoch - 1 + 365 * (gdate.year - 1) + floor((gdate.year-1)/4) - floor((gdate.year - 1)/100) + floor((gdate.year-1)/400) + floor((367*gdate.month-362)/12);
if (gdate.month <= 2) {
rd = rd + 0;
} else if ((gdate.month > 2) && (gregorian_leap_year(gdate.year) == 1)) {
rd = rd - 1;
} else {
rd = rd - 2;
}
rd = rd + gdate.day;
return rd;
}
//
// Usage: gregorian_from_rd( int rd, GDATE *date )
// Description: Compute the gregorian date (GDATE *date) given a R.D. date (rd).
//
void
gregorian_from_rd(int rd, GDATE *gdate)
{
gdate.year = gregorian_year_from_rd(rd);
GDATE prior_days = rd - rd_from_gregorian(january, 1, gdate.year);
int correction = 0;
if (rd < rd_from_gregorian(march, 1, gdate.year)){
correction = 0;
}else if (rd >= rd_from_gregorian(march, 1, gdate.year)&&gregorian_leap_year(gdate.year)){
correction = 1;
}else{
correction = 2;
}
gdate.month = (12*(prior_days + correction)+373)/367;
gdate.day =rd - rd_from_gregorian(gdate.month, 1, gdate.year)+1;
return gdate.month, gdate.day, gdate.year;
}
static int
paschal_moon( int g_year )
{
GDATE rd;
int century = (g_year/100)+1;
int shifted_epact = (14 + 11* (g_year % 19) - ((3*century)/4)+((5+8*century)/4))%30;
int adjusted_epact;
if (shifted_epact == 0 || shifted_epact == 1 && g_year % 19 > 10){
adjusted_epact = shifted_epact + 1;
}else {
adjusted_epact = shifted_epact;
}
rd = rd_from_gregroian(april, 19, g_year) - adjusted_epact;
return rd;
}
//
// Usage: rd = labor_day( g_year )
// Description: For any gregorian year (g_year), determine the R.D. date of Labour Day.
// Labour Day is the first Monday in September, on the gregorian calendar.
//
int
labor_day( int g_year )
{
return kday_on_or_before(rd_from_gregorian(September, 1, g_year), 1 );
}
//
// Usage: rd = christmas( g_year )
// Description: For any gregorian year (g_year), determine the R.D. date of Christmas.
// Christmas falls on December 25, on the gregorian calendar.
//
int
christmas( int g_year )
{
GDATE date;
date = (December, 25, g_year);
return rd_from_gregorian(date);
}
//
// Usage: rd = daylight_savings_start( g_year )
// Description: For any gregorian year (g_year), determine the R.D. date for the start of Daylight Savings Time.
// Daylight Savings Time starts on the first Sunday of April, on the gregorian calendar.
//
int
daylight_savings_start( int g_year )
{
GDATE date = kday_on_or_before(rd_from_gregorian(April, 1, g_year), Sunday);
return rd_from_gregorian(date);
}
//
// Usage: rd = daylight_savings_end( g_year )
// Description: For any gregorian year (g_year), determine the R.D. date for the end of Daylight Savings Time.
// Daylight Savings Time ends on the last Sunday of October, on the gregorian calendar.
//
int
daylight_savings_end( int g_year )
{
GDATE date = kday_on_or_before(rd_from_gregorian(October, 1, g_year), Sunday);
return rd_from_gregorian(date);
}