Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct BirthdayInfo {
- DateTime _today;
- DateTime _birthday;
- TimeSpan _fromToday;
- string _name;
- public BirthdayInfo(DateTime birthday,string name) {
- _today = DateTime.Now;
- _birthday = birthday;
- _fromToday = TimeSpan.Zero;
- _name = name;
- }
- public BirthdayInfo(DateTime birthday)
- : this(birthday,null) {
- _name = null;
- }
- public string Name {
- get { return _name; }
- set { _name = value; }
- }
- public DateTime Today {
- get { return _today; }
- set {
- _today = value;
- _fromToday = TimeSpan.Zero;
- }
- }
- public DateTime Birthday {
- get { return _birthday; }
- set {
- _birthday = value;
- _fromToday = TimeSpan.Zero;
- }
- }
- public int YearsFromToday {
- get {
- DateTime thisYear = new DateTime(Today.Year,Birthday.Month,Birthday.Day,Birthday.Hour,Birthday.Minute,0);
- if(Today > thisYear)
- return thisYear.Year - Birthday.Year;
- else
- return (thisYear.Year - Birthday.Year) - 1;
- }
- }
- public int DaysFromToday {
- get {
- return this.FromToday.Days;
- }
- }
- public int MinutesFromToday {
- get {
- return (int)this.FromToday.TotalMinutes;
- }
- }
- public long SecondsFromToday {
- get {
- return (long)this.FromToday.TotalSeconds;
- }
- }
- public TimeSpan FromToday {
- get {
- if(_fromToday == TimeSpan.Zero)
- _fromToday = _today.Subtract(_birthday);
- return _fromToday;
- }
- }
- public override string ToString() {
- var info = this;
- StringBuilder builder = new StringBuilder();
- Action<string,object> output = (a,b) => builder.AppendLine(string.Format("{0,-20} = {1,20}",a,b));
- output("{0}'s BirthDay".FormatWith(info.Name),info.Birthday);
- output("Years since birth",info.YearsFromToday.ToString("#,#") + " years");
- output("Days since birth",info.DaysFromToday.ToString("#,#") + " days");
- output("Minutes since birth",info.DaysFromToday.ToString("#,#") + " minutes");
- output("Seconds since birth",info.SecondsFromToday.ToString("#,#") + " seconds");
- return builder.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment