Make your own free website on Tripod.com

MKoD - D Programming Language

Functions that gather important dates during Easter - code-name getEasterDates.d

Very Kool! Gather very important Easter dates example:

/+ 
 ' Functions that gather important dates during Easter. 
 ' 1) getAshWednesday()
 ' 2) getPalmSunday()
 ' 3) getMaundyThursday()
 ' 4) getGoodFriday()
 ' 5) getEasterSunday()
 ' 6) getAscensionThursday()
 ' 7) getPentecost()
 '
 ' License: Public Domain
 '
 ' To Compile: C:\dmd\MKoD_ex>dmd getEasterDates.d
 '
 ' 02.Oct.04 Compiled and Tested with dmd v0.102
 ' 04.Jun.06 Compiled and Tested with dmd v0.160
 ' 10.Jan.07 Compiled and Tested with dmd v1.0
 '
 +/
private import std.stdio;

/+
 ' Determine the date of "Easter Sunday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getEasterSunday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear );
       
    if ( iday > 31 )
    {
        iday   = iday - 31;
        imonth = 4;
    }
    else 
        imonth = 3;
        
} // end void getEasterSunday( in int, out int, out int )

/+
 ' Determine the date of "Palm Sunday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getPalmSunday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) - 7;
    
    if ( iday > 31 )
    {
        iday   = iday - 31;
        imonth = 4;
    }
    else 
        imonth = 3;
    
} // end void getPalmSunday( in int, out int, out int )

/+
 ' Determine the date of "Good Friday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getGoodFriday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) - 2;    
    
    if ( iday > 31 )
    {
        iday   = iday - 31;
        imonth = 4;
    }
    else 
        imonth = 3;    
        
} // end void getGoodFriday( in int, out int, out int )

/+
 ' Determine the date of "Maundy Thursday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getMaundyThursday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) - 3;    
    
    if ( iday > 31 )
    {
        iday   = iday - 31;
        imonth = 4;
    }
    else 
        imonth = 3;    
        
} // end void getMaundyThursday( in int, out int, out int )

/+
 ' Determine the date of "Ash Wednesday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getAshWednesday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) - 46;    
     
    if ( iday > 0 )
    {
        imonth = 3;
    }
    else
    { 
        iday   = 28 + iday + leapYearDay( iyear );
        imonth = 2;    
    }
        
} // end void getAshWednesday( in int, out int, out int )

/+
 ' Determine the date of "Ascension Thursday" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getAscensionThursday
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) + 40;
       
    if ( iday > 93 )
    {
        iday   = iday - 93;
        imonth = 6;
    }
    else if (iday > 62 )
    {
        iday = iday - 62;
        imonth = 5;
    }    
    else 
        imonth = 4;
          
} // end void getAscensionThursday( in int, out int, out int )

/+
 ' Determine the date of "Pentecost" for any year  
 ' in the Gregorian Calendar from 1583 to 4099. 
 '
 +/
void getPentecost
(
    in  int iyear, 
    out int imonth, 
    out int iday
)
{
    iday = getEasterDays( iyear ) + 50;
       
    if ( iday > 93 )
    {
        iday   = iday - 93;
        imonth = 6;
    }
    else if (iday > 62 )
    {
        iday = iday - 62;
        imonth = 5;
    }    
    else if ( iday > 31 )
    {
        iday = iday - 31;
        imonth = 4;
    }    
    else
        imonth = 3;        
    
} // end void getPentecost( in int, out int, out int )

private int getEasterDays
(
    in  int iyear 
)
{
    int ia; 
    int ib; 
    int ic;
    int itA;
    int itB; 
    int itC; 
    int itD; 
    int itE;
    int iday = 0;

    ia = iyear / 100;
    ib = iyear % 19;

    ic = ( ( ia - 15 ) >> 1 ) + 202 - 11 * ib;
    
    if ( ia > 26 ) ic--;
    if ( ia > 38 ) ic--;
    if ( ia == 21 || ia == 24 || ia == 25 || 
         ia == 33 || ia == 36 || ia==37 ) 
        ic--;
        
    ic  = ic % 30;
    itA = ic + 21;
    
    if ( ic == 29 ) itA--;
    if ( ic == 28 && ib > 10) itA--;
    
    itB = ( itA - 19 ) % 7;
    ic  = ( 40 - ia ) & 3;
    itC = ic;
    
    if ( ic > 1) itC++;
    if ( ic == 3) itC++;
    
    ic  = iyear % 100;
    itD = ( ic + ( ic >> 2 ) ) % 7;
    itE = ( ( 20 - itB - itC - itD ) % 7 ) + 1;
    iday = itA + itE;
    
    return iday;
    
} // end int getEasterDays( in int )

private int leapYearDay
(
    in int iyear
)
{
    return ( ( iyear & 3 ) == 0 && ( iyear % 100 || ( iyear % 400 ) == 0 ) );
    
} // end int leapYearDay( in int )

int main()
{
    char[][ 6 ] sMonths;
    sMonths[][ 0 ] = "January";
    sMonths[][ 1 ] = "February";
    sMonths[][ 2 ] = "March"; 
    sMonths[][ 3 ] = "April"; 
    sMonths[][ 4 ] = "May";
    sMonths[][ 5 ] = "June";
    
    int iAshWedMonth       = 0;
    int iAshWedDay         = 0;
    int iPalmSunMonth      = 0;
    int iPalmSunDay        = 0;
    int iMaundyThrMonth    = 0;
    int iMaundyThrDay      = 0;
    int iGoodFriMonth      = 0;
    int iGoodFriDay        = 0;
    int iEasterSunMonth    = 0;
    int iEasterSunDay      = 0;
    int iAscensionThrMonth = 0;
    int iAscensionThrDay   = 0;
    int iPentecostMonth    = 0;
    int iPentecostDay      = 0;
    
    for ( int iyear = 1996; iyear <= 2020; iyear++ )
    { 
        getAshWednesday( iyear, iAshWedMonth, iAshWedDay );
        getPalmSunday( iyear, iPalmSunMonth, iPalmSunDay );
        getMaundyThursday(  iyear, iMaundyThrMonth, iMaundyThrDay );
        getGoodFriday( iyear, iGoodFriMonth, iGoodFriDay );
        getEasterSunday( iyear, iEasterSunMonth, iEasterSunDay );
        getAscensionThursday( iyear, iAscensionThrMonth, iAscensionThrDay );
        getPentecost( iyear, iPentecostMonth, iPentecostDay );
        
        writefln( "For %d Ash Wednesday      is on %s %d\n"
                  "         Palm Sunday        is on %s %d\n"
                  "         Maundy Thursday    is on %s %d\n"
                  "         Good Friday        is on %s %d\n"
                  "         Easter Sunday      is on %s %d\n"
                  "         Ascension Thursday is on %s %d\n"
                  "         Pentecost          is on %s %d", 
                  iyear,
                  sMonths[ iAshWedMonth - 1  ], iAshWedDay, 
                  sMonths[ iPalmSunMonth - 1 ], iPalmSunDay, 
                  sMonths[ iMaundyThrMonth - 1  ], iMaundyThrDay, 
                  sMonths[ iGoodFriMonth - 1 ], iGoodFriDay, 
                  sMonths[ iEasterSunMonth - 1 ], iEasterSunDay,
                  sMonths[ iAscensionThrMonth - 1 ], iAscensionThrDay,
                  sMonths[ iPentecostMonth - 1 ], iPentecostDay ); 
              
        writefln();
    }    
 
    return 0;
    
} // end int main()
C:\dmd\MKoD_ex>..\bin\dmd getEasterDates.d
C:\dmd\bin\..\..\dm\bin\link.exe getEasterDates,,,user32+kernel32/noi;

C:\dmd>geteasterdates
For 1996 Ash Wednesday      is on February 21
         Palm Sunday        is on March 31
         Maundy Thursday    is on April 4
         Good Friday        is on April 5
         Easter Sunday      is on April 7
         Ascension Thursday is on May 16
         Pentecost          is on May 26

For 1997 Ash Wednesday      is on February 12
         Palm Sunday        is on March 23
         Maundy Thursday    is on March 27
         Good Friday        is on March 28
         Easter Sunday      is on March 30
         Ascension Thursday is on May 8
         Pentecost          is on May 18

For 1998 Ash Wednesday      is on February 25
         Palm Sunday        is on April 5
         Maundy Thursday    is on April 9
         Good Friday        is on April 10
         Easter Sunday      is on April 12
         Ascension Thursday is on May 21
         Pentecost          is on May 31

For 1999 Ash Wednesday      is on February 17
         Palm Sunday        is on March 28
         Maundy Thursday    is on April 1
         Good Friday        is on April 2
         Easter Sunday      is on April 4
         Ascension Thursday is on May 13
         Pentecost          is on May 23

For 2000 Ash Wednesday      is on March 8
         Palm Sunday        is on April 16
         Maundy Thursday    is on April 20
         Good Friday        is on April 21
         Easter Sunday      is on April 23
         Ascension Thursday is on June 1
         Pentecost          is on June 11

For 2001 Ash Wednesday      is on February 28
         Palm Sunday        is on April 8
         Maundy Thursday    is on April 12
         Good Friday        is on April 13
         Easter Sunday      is on April 15
         Ascension Thursday is on May 24
         Pentecost          is on June 3

For 2002 Ash Wednesday      is on February 13
         Palm Sunday        is on March 24
         Maundy Thursday    is on March 28
         Good Friday        is on March 29
         Easter Sunday      is on March 31
         Ascension Thursday is on May 9
         Pentecost          is on May 19

For 2003 Ash Wednesday      is on March 5
         Palm Sunday        is on April 13
         Maundy Thursday    is on April 17
         Good Friday        is on April 18
         Easter Sunday      is on April 20
         Ascension Thursday is on May 29
         Pentecost          is on June 8

For 2004 Ash Wednesday      is on February 25
         Palm Sunday        is on April 4
         Maundy Thursday    is on April 8
         Good Friday        is on April 9
         Easter Sunday      is on April 11
         Ascension Thursday is on May 20
         Pentecost          is on May 30

For 2005 Ash Wednesday      is on February 9
         Palm Sunday        is on March 20
         Maundy Thursday    is on March 24
         Good Friday        is on March 25
         Easter Sunday      is on March 27
         Ascension Thursday is on May 5
         Pentecost          is on May 15

For 2006 Ash Wednesday      is on March 1
         Palm Sunday        is on April 9
         Maundy Thursday    is on April 13
         Good Friday        is on April 14
         Easter Sunday      is on April 16
         Ascension Thursday is on May 25
         Pentecost          is on June 4

For 2007 Ash Wednesday      is on February 21
         Palm Sunday        is on April 1
         Maundy Thursday    is on April 5
         Good Friday        is on April 6
         Easter Sunday      is on April 8
         Ascension Thursday is on May 17
         Pentecost          is on May 27

For 2008 Ash Wednesday      is on February 6
         Palm Sunday        is on March 16
         Maundy Thursday    is on March 20
         Good Friday        is on March 21
         Easter Sunday      is on March 23
         Ascension Thursday is on May 1
         Pentecost          is on May 11

For 2009 Ash Wednesday      is on February 25
         Palm Sunday        is on April 5
         Maundy Thursday    is on April 9
         Good Friday        is on April 10
         Easter Sunday      is on April 12
         Ascension Thursday is on May 21
         Pentecost          is on May 31

For 2010 Ash Wednesday      is on February 17
         Palm Sunday        is on March 28
         Maundy Thursday    is on April 1
         Good Friday        is on April 2
         Easter Sunday      is on April 4
         Ascension Thursday is on May 13
         Pentecost          is on May 23

For 2011 Ash Wednesday      is on March 9
         Palm Sunday        is on April 17
         Maundy Thursday    is on April 21
         Good Friday        is on April 22
         Easter Sunday      is on April 24
         Ascension Thursday is on June 2
         Pentecost          is on June 12

For 2012 Ash Wednesday      is on February 22
         Palm Sunday        is on April 1
         Maundy Thursday    is on April 5
         Good Friday        is on April 6
         Easter Sunday      is on April 8
         Ascension Thursday is on May 17
         Pentecost          is on May 27

For 2013 Ash Wednesday      is on February 13
         Palm Sunday        is on March 24
         Maundy Thursday    is on March 28
         Good Friday        is on March 29
         Easter Sunday      is on March 31
         Ascension Thursday is on May 9
         Pentecost          is on May 19

For 2014 Ash Wednesday      is on March 5
         Palm Sunday        is on April 13
         Maundy Thursday    is on April 17
         Good Friday        is on April 18
         Easter Sunday      is on April 20
         Ascension Thursday is on May 29
         Pentecost          is on June 8

For 2015 Ash Wednesday      is on February 18
         Palm Sunday        is on March 29
         Maundy Thursday    is on April 2
         Good Friday        is on April 3
         Easter Sunday      is on April 5
         Ascension Thursday is on May 14
         Pentecost          is on May 24

For 2016 Ash Wednesday      is on February 10
         Palm Sunday        is on March 20
         Maundy Thursday    is on March 24
         Good Friday        is on March 25
         Easter Sunday      is on March 27
         Ascension Thursday is on May 5
         Pentecost          is on May 15

For 2017 Ash Wednesday      is on March 1
         Palm Sunday        is on April 9
         Maundy Thursday    is on April 13
         Good Friday        is on April 14
         Easter Sunday      is on April 16
         Ascension Thursday is on May 25
         Pentecost          is on June 4

For 2018 Ash Wednesday      is on February 14
         Palm Sunday        is on March 25
         Maundy Thursday    is on March 29
         Good Friday        is on March 30
         Easter Sunday      is on April 1
         Ascension Thursday is on May 10
         Pentecost          is on May 20

For 2019 Ash Wednesday      is on March 6
         Palm Sunday        is on April 14
         Maundy Thursday    is on April 18
         Good Friday        is on April 19
         Easter Sunday      is on April 21
         Ascension Thursday is on May 30
         Pentecost          is on June 9

For 2020 Ash Wednesday      is on February 26
         Palm Sunday        is on April 5
         Maundy Thursday    is on April 9
         Good Friday        is on April 10
         Easter Sunday      is on April 12
         Ascension Thursday is on May 21
         Pentecost          is on May 31
C:\dmd\MKoD_ex>
Mars: fourth Rock from the Sun.