There is a file that needs to be downloaded, the file is ready to download every day at 8pm, as it gets updated by a third party. The file is only downloaded when the user hits a certain page. This file is an external resource required to display the latest information. When the file is downloaded the time is stored with the file. So we know,
- when the file needs to be downloaded,
- what time the last file was downloaded,
- we know what the current time is. How would I make sure when to download the file or not based on what we know above.
Here is the test I tried, but this doesn't work:
DateTime currentFileDownloadedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 00, 0);
DateTime currentTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 01, 15);
DateTime downloadTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 0, 0);
if (currentFileDownloadedTime.Date.Day <= currentTime.Day &&
(currentTime.TimeOfDay.TotalMilliseconds > currentFileDownloadedTime.TimeOfDay.TotalMilliseconds) &&
(currentTime.TimeOfDay.TotalMilliseconds > downloadTime.TimeOfDay.TotalMilliseconds))
{
Console.WriteLine("Downloading File");
}