Created
June 9, 2019 14:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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