public DominicanSeason GetDominicanSeasonForYear(string year)
        {
            int             yearIdx = Int32.Parse(year) - _startYear;   // 2015
            DominicanSeason ds      = _calender[yearIdx];

            return(ds);
        }
Example #2
0
        List <FeastDateObject> GetAscensionDates(string year, int yr, DominicanSeason dominicanSeason)
        {
            // 7th Sunday of Easter
            DateTime easterDate    = dominicanSeason[DominicanSeasons.Easter];
            DateTime ascensionDate = easterDate.AddDays(42.0D);         // add 7 weeks to easter  ????

            if (ascensionDate.DayOfWeek != DayOfWeek.Sunday)
            {
                Debug.WriteLine($"{_Tag}.GetAscensionDates: calculated date NOT a Sunday!");
            }

            List <FeastDateObject> feastDates = SetFeastDates(ascensionDate, year, "ascension", true);

            return(feastDates);
        }
Example #3
0
        /*There are three ranks of feast in Catholic Church.They are in order Solemnity, Feast and Memorial.
         *
         * Solemnity has three types: solemnity of the Lord, solemnity of Our Lady and solemnity of other saints.
         * Solemnities of the Lord have precedence over those of Our Lady and those of Our Lady have precedence over those of other saints.
         * The solemnities of the Lord will replace the celebration of a Sunday in Ordinary Time.
         * The solemnities of Our Lady and the ones of other saints will be transferred to the next free day if it falls on a Sunday,
         *      except the following solemnities:
         *      - Blessed Virgin Mary Mother of God (01/01)
         *      - Assumption of Our Lady(15/08)
         *      - Nativity of St John the Baptism(24/06).
         *      - Sts Peter and Paul(29/06)
         * All feasts or memorial is transferred to the next free day if it falls on a Sunday or a same day of a higher ranking feast.
         * There are two types of memorial: normal and optional. An optional memorial is celebrated by the faithful's choice.
         *
         * - The Sunday between 02/01 and 08/01 is the Solemnity of Epiphany of the Lord.
         * - The Sunday after 06/01 is the Feast of Baptism of the Lord.
         * - The Sunday between 25/12 and 31/12 is the Feast of Holy Family.If there is no Sunday in that period then Holy Family is on 31/12.
         *
         * There are 4 solemnities for Lord in Ordinary Time period.
         *      -- Trinity Sunday: Sunday after Pentecost (17 May to 20 June).
         *      -- Most Holy Body and Blood of Christ or Corpus Christi: Sunday after Trinity Sunday
         *      -- Most Sacred Heart of Jesus: Friday after Corpus Christi.
         *      -- Our Lord Jesus Christ, King of the Universe: 34th Sunday of Ordinary Time.
         */
        public IList <FeastDateObject> CreateFeastsForYear(string year, DominicanSeason dominicanSeason)
        {
            //GetDominicanFeasts();

            //IList<FeastDate> feasts = new List<FeastDate>();
            _feastObjects = _databaseModel.GetFeasts();

            List <FeastDateObject> feastDateObjects = new List <FeastDateObject>();

            feastDateObjects.AddRange(CreateFixedFeasts(year));
            feastDateObjects.AddRange(CreateMovingFeasts(year, dominicanSeason));

            // debug check that its all worked
            //Debug.WriteLine($"CreateFeastsForYear({year}) - {_databaseModel.FeastsForYearToString(year)}\nFin");
            Debug.WriteLine($"CreateFeastsForYear({year}) - {feastDateObjects.Count}");

            return(feastDateObjects);
        }
        int CalcOT2StartWeek(DominicanSeason ds)
        {
            // To determine what week it is in we need to count from the first Sunday of Advent of church year e.g. 2016 - 2017, 27 / 11 / 2016.
            // The week before that first Sunday of Advent is always week 34 and count backward to 18/05/2016 and so it is in week 7 of Ordinary Time.
            int startWeek = -1;

            TimeSpan days = ds[DailyPrayer.DominicanSeasons.NextAdvent] - ds[DailyPrayer.DominicanSeasons.OT2];
            //Debug.WriteLine(string.Format("{0}.CalcOT2StartWeek: {1} - {2} = {3}",
            //    _Tag, ds[DailyPrayer.DominicanSeasons.NextAdvent].ToString(), ds[DailyPrayer.DominicanSeasons.OT2].ToString(), days.Days));
            int weeks = (days.Days) / 7;

            startWeek = 34 - weeks;

            DateTime dt = ds[DailyPrayer.DominicanSeasons.OT2];

            //Debug.WriteLine(string.Format("{0}.CalcOT2StartWeek: {1}, NumWeeks={2}, StartWeek={3}", _Tag, dt.Year, weeks, startWeek));

            return(startWeek);
        }
        void CreateCalender(DominicanDates dominicanDates)
        {
            Debug.WriteLine($"{_Tag}.CreateCalender()");

            string      dateFormat = "dd/MM/yyyy";
            CultureInfo provider   = CultureInfo.InvariantCulture;

            foreach (DominicanDates.DominicanYear dominicanYear in dominicanDates.years)
            {
                //Debug.WriteLine("{0}", dominicanYear.ToString());

                DominicanSeason ds = new DominicanSeason();
                //int nextYear = dominicanYear.year + 1;
                //ds[DominicanSeasons.Advent] = DateTime.ParseExact(dominicanYear.dates.advent + "/" + lastYear, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.Advent] = DateTime.ParseExact(dominicanYear.dates.advent + "/" + (dominicanYear.year - 1), dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.XMas]   = DateTime.ParseExact("25/12/" + (dominicanYear.year - 1), dateFormat, provider);
                //ds[DailyPrayer.DominicanSeasons.OctaveOfChristmas] = DateTime.ParseExact("25/12/" + (dominicanYear.year - 1), dateFormat, provider);
                //ds[DailyPrayer.DominicanSeasons.OctaveOfEpiphany] = DateTime.ParseExact("25/12/" + (dominicanYear.year - 1), dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.OT1] = DateTime.ParseExact(dominicanYear.dates.ot1 + "/" + dominicanYear.year, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.Ash_Wednesday_Week] = DateTime.ParseExact(dominicanYear.dates.ashwed + "/" + dominicanYear.year, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.Lent]      = ds[DailyPrayer.DominicanSeasons.Ash_Wednesday_Week].AddDays(4);
                ds[DailyPrayer.DominicanSeasons.Easter]    = DateTime.ParseExact(dominicanYear.dates.easter + "/" + dominicanYear.year, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.Holy_Week] = ds[DailyPrayer.DominicanSeasons.Easter].AddDays(-7);
                ds[DailyPrayer.DominicanSeasons.OT2]       = DateTime.ParseExact(dominicanYear.dates.pentecost + "/" + dominicanYear.year, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.XMas_II]   = DateTime.ParseExact("25/12/" + dominicanYear.year, dateFormat, provider);
                ds[DailyPrayer.DominicanSeasons.EndOfYear] = DateTime.ParseExact("01/01/" + (dominicanYear.year + 1), dateFormat, provider);
                //int index = dominicanYear.year - _startYear;

                if (_calender.Count > 0)
                {
                    // advent for the Catholic year starts in the previous year,
                    // but we also need the date in this year
                    DominicanSeason dsPrev = _calender[_calender.Count - 1];
                    dsPrev[DailyPrayer.DominicanSeasons.NextAdvent] = ds[DailyPrayer.DominicanSeasons.Advent];
                }

                _calender.Add(ds);
                //Debug.WriteLine($"{_Tag}.CreateCalender() - FIN");
            }
        }
Example #6
0
        List <FeastDateObject> CreateMovingFeasts(string year, DominicanSeason dominicanSeason)
        {
            /*
             * epiphany                - Sunday between 02 / 01 and 08 / 01
             * baptism _of_the_lord    - Sunday after 06 / 01.
             *  If Epiphany already occupy that Sunday then it will be celebrated on the first Monday after that Sunday.
             * ascension               - 7th Sunday of Easter
             * pentecost               - Nine days after Ascension on a Sunday.
             * trinity                 - First Sunday after Pentecost
             * Corpus Christi          - Thursday after Trinity. However it is usually celebrated on the second Sunday after Pentecost.
             * sacred_heart_jesus      - Friday following second Sunday after Pentecost
             * Jesus_the_king          - last Sunday in Ordinary Time.
             * holy_family             - Sunday between Christmas Day and New Year Day if there is. Otherwise 30 / 12.
             * sacred_heart_mary       - 9 days after Corpus Christi
             */

            DateTime pentecostDate;
            List <FeastDateObject> feastDateObjects = new List <FeastDateObject>();

            int yr = Int32.Parse(year);

            // get epiphany dates, and add to the list
            IList <FeastDateObject> epiphanyDates = GetEpiphanyDates(year, yr);

            feastDateObjects.AddRange(epiphanyDates);

            feastDateObjects.AddRange(GetBotLDates(year, yr, epiphanyDates));                 // baptism _of_the_lord
            IList <FeastDateObject> ascensionDates = GetAscensionDates(year, yr, dominicanSeason);

            feastDateObjects.AddRange(ascensionDates);
            feastDateObjects.AddRange(GetPentecostDates(year, yr, ascensionDates, out pentecostDate));
            feastDateObjects.AddRange(GetTrinityCorpusChristiDates(year, yr, pentecostDate));
            feastDateObjects.AddRange(GetSacredHeartJesusDates(year, yr, pentecostDate));
            feastDateObjects.AddRange(GetJesusTheKingDates(year, yr, dominicanSeason[DominicanSeasons.NextAdvent]));
            feastDateObjects.AddRange(GetHolyFamilyDates(year, yr));

            return(feastDateObjects);
        }
Example #7
0
        public IList <FeastDate> GetFeastsForYear(string year)
        {
            IList <FeastDate> feastsForYear = _databaseModel.GetFeastsForYear(year);

            if (feastsForYear.Count == 0)
            {
                // get feast name etc; NOT dates
                IList <FeastInfoObject> feasts = _databaseModel.GetFeasts();
                if (feasts.Count == 0)
                {
                    // not found, so load them from the json file
                    feasts = _databaseModel.SetFeasts(GetDominicanFeasts());
                }

                DominicanCalender dominicanCalender = FreshIOC.Container.Resolve <IDominicanCalender>() as DominicanCalender;

                // get the calender of dominican dates for that year
                DominicanSeason dominicanSeason = dominicanCalender.GetDominicanSeasonForYear(year);

                IList <FeastDateObject> feastDateObjects = CreateFeastsForYear(year, dominicanSeason);

                _databaseModel.SetFeastsForYear(year, feastDateObjects);
                feastsForYear = _databaseModel.GetFeastsForYear(year);

                if (_test)
                {
                    Debug.WriteLine($"{_Tag}.GetFeastForYear( {year} )");
                    foreach (FeastDate feastDate in feastsForYear)
                    {
                        Debug.WriteLine(feastDate.ToString());
                    }
                    Debug.WriteLine($"{_Tag}.GetFeastForYear( Fin )");
                }
            }

            return(feastsForYear);
        }
        public Place FindPlace(DateTime date)
        {
            //Debug.WriteLine("DominicanCalender.FindPlace - " + date.ToString("yyyy/MM/dd HH:mm"));

            Place place = new Place();
            // find the season, week, and day of the date in the Liturgical year
            int             yearIdx = date.Year - _startYear;
            DominicanSeason ds      = _calender[yearIdx + 1]; // get next years dates

            //Debug.WriteLine(string.Format("Year {0:yyyy/MM/dd HH:mm}", ds[DailyPrayer.DominicanSeasons.Advent]));

            int charYear = date.Year;                           // regarded as prev year till OT1

            if (date < ds[DailyPrayer.DominicanSeasons.Advent]) // check if date < advent start
            {
                ds       = _calender[yearIdx];                  // if not, get prev year
                charYear = date.Year - 1;
            }

            place.Morning    = date.Hour < 12.0;
            place.DayNo      = string.Format("{0}", (int)date.DayOfWeek + 1);                       // 0 == Sunday, but needs 2 b in range 1-7
            place.DayInMonth = date.Day;
            place.Month      = date.Month;
            place.YearChar   = (char)((int)'A' + (charYear % 3));

            // first check if the date is a feast date
            // if so, we don't need to bother with anything else
            FeastDate feast = _feastsModel.GetFeastForDate(date);

            if (feast != null)
            {
                //Debug.WriteLine("DominicanCalender.FindPlace: Found Feast " + feast.feast.Name);
                place.DomSeason = DailyPrayer.DominicanSeasons.Feasts;
                place.Filename  = feast.filename;
                place.Title     = feast.feast.Title;
                place.WeekNo    = "1";                      // just a dummy value, not used for feasts
                return(place);
            }

            // not a feast
            int      idx        = -1;
            DateTime seasonDate = new DateTime();

            for (DailyPrayer.DominicanSeasons j = DailyPrayer.DominicanSeasons.Advent; j < DailyPrayer.DominicanSeasons.EndOfYear; j++)
            {
                //Debug.WriteLine(string.Format("between {0:yyyy/MM/dd HH:mm} - {1:yyyy/MM/dd HH:mm} ?", ds[j], ds[j+1]));
                if (date >= ds[j] && date < ds[j + 1])
                {
                    idx        = (int)j;
                    seasonDate = ds[j];
                    // BotL and Pentecost r the Feasts which start on the first day of OT1 & 2
                    if (j == DailyPrayer.DominicanSeasons.OT1 && date.Date == ds[j])
                    {
                        place.DomSeason = DailyPrayer.DominicanSeasons.Baptism_of_the_Lord;
                    }
                    else if (j == DailyPrayer.DominicanSeasons.OT2 && date.Date == ds[j])
                    {
                        place.DomSeason = DailyPrayer.DominicanSeasons.Pentecost;
                    }
                    else
                    {
                        place.DomSeason = j;
                    }

                    place.SeasonStr = place.DomSeason.ToString();
                    //Debug.WriteLine("found !!!");
                    break;
                }
            }

            if (idx < 0)
            {
                return(place);
            }

            int seasonWeekNo = (((idx == 0)?1:seasonDate.DayOfYear) - (int)seasonDate.DayOfWeek + 10) / 7;
            int dateWeekNo   = (date.DayOfYear - (int)date.DayOfWeek + 10) / 7;

            if (seasonWeekNo == 52 && dateWeekNo < 10)
            {
                dateWeekNo = (seasonWeekNo + dateWeekNo) - 1;
            }

            int weekNo = (dateWeekNo - seasonWeekNo) + 1;                                           // first week = week1, not week0

            if (weekNo < 0)
            {
                dateWeekNo = (seasonWeekNo + dateWeekNo) - 1;
                weekNo     = (dateWeekNo - seasonWeekNo) + 1;                                       // first week = week1, not week0
            }

            if (place.DomSeason == DailyPrayer.DominicanSeasons.OT2)
            {
                if (!_OT2StartWeeks.ContainsKey(date.Year))
                {
                    int startWeek = CalcOT2StartWeek(ds);
                    _OT2StartWeeks[date.Year] = startWeek;
                }
                weekNo += _OT2StartWeeks[date.Year];
            }
            else if (place.DomSeason == DailyPrayer.DominicanSeasons.XMas ||
                     place.DomSeason == DailyPrayer.DominicanSeasons.XMas_II)
            {
                //if (place.DomSeason == DominicanSeasons.XMas)
                //charYear--;

                DateTime holyFamilyFeast;
                DateTime xmas = ds[place.DomSeason];
                if (xmas.DayOfWeek == 0)                                                // if Xmas is on a Sunday
                {
                    holyFamilyFeast = new DateTime(xmas.Year, xmas.Month, 30);          // HFF is on the Friday
                }
                else
                {
                    holyFamilyFeast = new DateTime(xmas.Year, xmas.Month, 25);
                    holyFamilyFeast = holyFamilyFeast.AddDays(7 - (int)xmas.DayOfWeek);                    // HFF is following Sunday
                }

                if (date.Date == holyFamilyFeast.Date)
                {
                    place.DomSeason = DailyPrayer.DominicanSeasons.Holy_Family;
                }
                else if (place.DayNo == "1")
                {
                    // both these feasts r on Sundays after the respective dates
                    if (place.DayInMonth > 25)
                    {
                        place.DomSeason = DailyPrayer.DominicanSeasons.Holy_Family;
                    }
                    else if (place.DayInMonth > 1 && place.DayInMonth <= 8)
                    {
                        place.DomSeason = DailyPrayer.DominicanSeasons.Epiphany;
                    }
                }
                //if (place.DayInMonth == 1)                  // New Years Day
                //    place.DomSeason = DailyPrayer.DominicanSeasons.Mother_of_God;
            }


            place.WeekNo = string.Format("{0}", weekNo);                   // first week = week1, not week0

            if (place.DomSeason == DailyPrayer.DominicanSeasons.Advent)
            {
                /*int wkNo = weekNo % 4;
                 * if (wkNo == 0)
                 *  wkNo = 4;
                 * place.WeekNo = string.Format("{0}", wkNo);                   // first week = week1, not week0
                 */
                place.WeekNo = string.Format($"{seasonWeekNo}");                   // first week = week1, not week0;
            }
            else
            {
                place.WeekNo = string.Format($"{weekNo}");                   // first week = week1, not week0
            }
            return(place);
        }