public IList <FeastDate> GetFeastsForYear(string year) { //Debug.WriteLine($"DatabaseModel.GetFeastsForYear( {year} )"); //DateTime yearDateTime = new DateTime(Int32.Parse(year), 1, 1); // get feast dates for the year IList <FeastDateObject> feastDates = (string.IsNullOrEmpty(year)) ? _realm.All <FeastDateObject>().ToList <FeastDateObject>() : FeastsForYear(year); // get the feast details i.e. the filenames for the feasts IList <FeastInfoObject> feasts = _realm.All <FeastInfoObject>().ToList(); if (_bTest) { Debug.WriteLine("FeastDateObjects"); foreach (FeastDateObject fdo2 in feastDates) { Debug.WriteLine($"{fdo2.ToString()}"); } Debug.WriteLine("\nFeastInfoObjects"); foreach (FeastInfoObject f in feasts) { Debug.WriteLine($"{f.ToString()}"); } Debug.WriteLine("\nIterating over FeastDates, and getting the FeastInfoObject for it"); } // iter over the feast dates, and FeastDate record which has the date, and the filename for that feast IList <FeastDate> listFeastDates = new List <FeastDate>(); foreach (FeastDateObject fdo in feastDates) //.ToList<FeastDateObject>()) { if (_bTest) { Debug.WriteLine($"{fdo.ToString()}"); } // we get the feast details for the filename from the feastdate var feastDetails = feasts.Where(d => d.Filename == fdo.FeastKey).FirstOrDefault <FeastInfoObject>(); if (feastDetails == null) { //Debug.WriteLine("No feast found for " + fdo.FeastKey); continue; } FeastDate feastDate = new FeastDate(fdo.DayMonthYearAmPm, fdo.Filename, feastDetails); listFeastDates.Add(feastDate); } IEnumerable <FeastDate> sorted = listFeastDates.OrderBy(f => f.date); IList <FeastDate> sortedList = sorted.ToList(); //Debug.WriteLine($"DatabaseModel.GetFeastsForYear( {year} ) Fin"); return(sortedList); }
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); }