Skip to content

Instantly share code, notes, and snippets.

@gareth-cheeseman
Created June 9, 2019 14:15
Show Gist options
  • Save gareth-cheeseman/dbeed3ef110929a4770d874458f521a6 to your computer and use it in GitHub Desktop.
Save gareth-cheeseman/dbeed3ef110929a4770d874458f521a6 to your computer and use it in GitHub Desktop.
Class used in UI testing to calculate months and days till passed in day for selecting on UI calendar
public class CalendarInfo
{
public string DateFromString { get; }
public int MonthsTillDateFrom { get; }
public string DateUntilString { get; }
public int MonthsTillUntilDate { get; }
public DateTime DateFromDateTime { get; }
public DateTime DateUntilDateTime { get; }
public CalendarInfo(string day, int daysInFuture)
{
var now = DateTime.Now;
switch (day.ToLower())
{
case "today":
this.DateFromDateTime = DateTime.Now;
break;
case "tomorrow":
this.DateFromDateTime = DateTime.Now.AddDays(1);
break;
default:
this.DateFromDateTime = DateTime.Parse(day, Configuration.Instance.Culture);
break;
}
this.DateUntilDateTime = DateFromDateTime.Add(TimeSpan.FromDays(daysInFuture));
this.DateFromString = $"{DateFromDateTime:MMMM d, yyyy}";
this.MonthsTillDateFrom = DateFromDateTime.Month - now.Month;
this.DateUntilString = $"{DateUntilDateTime:MMMM d, yyyy}";
this.MonthsTillUntilDate = DateUntilDateTime.Month - now.Month;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment