private static int GetNextAge(BirthdateEntry birthdayBoy) { DateTime bigDay = GetNextBirthday(birthdayBoy); int difference = birthdayBoy.birthdate.Year - bigDay.Year; return(-difference); }
private static int GetETAInDays(BirthdateEntry birthdayBoy) { DateTime bigDay = GetNextBirthday(birthdayBoy); int estimatedTimeOfArrival = bigDay.Subtract(DateTime.Now).Days; return(estimatedTimeOfArrival); }
private static bool WasThisBirthdayRemindedRecently(BirthdateEntry birthdayBoy) { int daysAgoReminded = DateTime.Now.Subtract(birthdayBoy.lastShown).Days; if (daysAgoReminded > birthdayBoy.remindEveryXDays) { return(false); } return(true); }
private static DateTime GetNextBirthday(BirthdateEntry birthdayBoy) { DateTime birthday = birthdayBoy.birthdate; birthday = birthday.AddYears(DateTime.Now.Year - birthday.Year); if (birthday < DateTime.Now) { birthday = birthday.AddYears(1); } return(birthday); }
//USER INPUT private static void EditBirthdateEntries(List <BirthdateEntry> allBirthdays) { PrintFirstEditHelp(); PrintEditHelp(allBirthdays); while (true) { string[] command = Console.ReadLine().Split(_inputFormatDelimiter); if (command[0] == _deleteInputKeyword) { int indexToRemove = Convert.ToInt32(command[1]); allBirthdays.RemoveAt(indexToRemove); SaveSettings(allBirthdays); } else if (command[0] == _addToStartupKeyword) { AddShortcutToStartup(); } else if (command.Length == 4) { BirthdateEntry newBirthday = new BirthdateEntry() { fullName = command[0], lastShown = DateTime.Now.AddYears(-1), checkFutureXDays = Convert.ToInt32(command[2]), remindEveryXDays = Convert.ToInt32(command[3]) }; bool parseResult = DateTime.TryParse( command[1], CultureInfo.CurrentCulture.DateTimeFormat, DateTimeStyles.None, out newBirthday.birthdate); if (!parseResult) { Console.Write("Could not understand the date. Try using the following format: " + CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + "\n\n-----------------------------------\n\n"); } else { allBirthdays.Add(newBirthday); SaveSettings(allBirthdays); } } PrintEditHelp(allBirthdays); } }
//FRONT END private static void PrintBirthdayBoys(List <BirthdateEntry> birthdayBoys) { if (birthdayBoys.Count == 0) { Console.WriteLine("No birthdays to show"); } else { BubbleSortBirthdayBoysByETA(birthdayBoys); for (int entryIndex = 0; entryIndex < birthdayBoys.Count; entryIndex++) { BirthdateEntry birthdayBoy = birthdayBoys[entryIndex]; Console.WriteLine("{0}: {1} is turning {2} in {3} days on {4} (born {5})\n\t-reminding you {6} days in advance every {7} days\n", entryIndex, birthdayBoy.fullName, GetNextAge(birthdayBoy), GetETAInDays(birthdayBoy), GetNextBirthday(birthdayBoy).ToShortDateString(), birthdayBoy.birthdate.ToShortDateString(), birthdayBoy.checkFutureXDays, birthdayBoy.remindEveryXDays); } } }