using System;
namespace Contacts
{
///
/// Represents the birthday of a contact.
///
/// Josh A
public class Birthday : IEquatable
{
private readonly int day;
private readonly int month;
private readonly int year;
public int Age { get; }
///
/// Creates a new Birthday object.
///
///
///
public Birthday(int month, int day)
{
this.month = month;
this.day = day;
year = -1;
Age = -1;
}
///
/// Creates a new Birthday and determines the age.
///
///
///
///
public Birthday(int month, int day, int year)
{
this.month = month;
this.day = day;
this.year = year;
Age = 2023 - year;
}
///
/// Determines if two birthdays are equal, to avoid potential duplication.
///
/// Birthday to compare to. If null, returns false.
/// Whether or not the two birthdays are the same.
public bool Equals(Birthday? birthdayToCompare)
{
if (birthdayToCompare == null)
return false;
return this.ToString().Equals(birthdayToCompare.ToString());
}
///
/// Formats a birthday to "MM-DD" or "MM-DD-YYYY", if a birthyear was provided.
///
/// Formatted birthdate.
public override string ToString()
{
if (year == -1)
return month + "-" + day;
return month + "-" + day + "-" + year;
}
}
}