public static string GetFormattedString(MusicEra era) // Returns a user-friendly string representation of a MusicEras enum value { if (era == MusicEra.Unknown) { return("Unknown"); } // Gets the two boundary years of the era and replaces "_" with "-", for example: "2000-2004" return(era.ToString().Remove(0, "Years_".Length).Replace('_', '-')); }
public static bool IsDateInEra(int year, MusicEra era) // Determines if a given year is in a given era { if (year < 1940 || year > 2034) { throw new ArgumentOutOfRangeException(nameof(year), $"The date {year} is not in the supported range of eras."); } if (era == MusicEra.Unknown) { throw new ArgumentException("Cannot determine inclusion for unknown era.", nameof(era)); } string formattedEra = GetFormattedString(era); int minYear = Convert.ToInt32(formattedEra.Split('-')[0]); int maxYear = Convert.ToInt32(formattedEra.Split('-')[1]); return(minYear <= year && year <= maxYear); // minYear <= year <= maxYear }
public static bool IsNewMillenium(MusicEra era) // Return true if the era is after 2000, and false if it's earlier { if (era == MusicEra.Unknown) { throw new ArgumentOutOfRangeException(nameof(era), "Millenia cannot be determined about unknown era."); } int eraValue = (int)era; if (eraValue < 40) { return(true); // 1940 is the earliest supported date from 1900s } else { return(false); } }