Skip to content

Commit

Permalink
#26: Fixed Update check to dont depend on locale
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Jun 16, 2017
1 parent 81d59b0 commit 0fb4fd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Source/Terminals/Updates/UpdateChecksFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using Terminals.Configuration;

Expand All @@ -19,7 +20,7 @@ internal bool ShouldCheckForUpdate
if (File.Exists(releaseFile))
{
DateTime lastUpdate = this.ReadLastUpdate();
if (lastUpdate.Date >= DateTime.Now.Date)
if (lastUpdate.Date >= DateTime.UtcNow.Date)
return false;
}
return true;
Expand All @@ -30,13 +31,14 @@ internal DateTime ReadLastUpdate()
{
String text = File.ReadAllText(this.releaseFile).Trim();
DateTime lastUpdate = DateTime.MinValue;
DateTime.TryParse(text, out lastUpdate);
DateTime.TryParse(text, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out lastUpdate);
return lastUpdate;
}

internal void WriteLastCheck()
{
File.WriteAllText(this.releaseFile, DateTime.Now.ToString());
string contents = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
File.WriteAllText(this.releaseFile, contents);
}
}
}
4 changes: 2 additions & 2 deletions Source/Tests/UpdateManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UpdateManagerTest
{
private Version currentVersion = new Version(2, 0, 0);

private readonly DateTime yesterDay = DateTime.Today.AddDays(-1);
private readonly DateTime yesterDay = DateTime.UtcNow.Date.AddDays(-1);

[TestInitialize]
public void ConfigureTestLab()
Expand Down Expand Up @@ -57,7 +57,7 @@ public void OldestBuildDate_CheckForCodeplexRelease_ReturnsValidRelease()
[TestMethod]
public void TodayCheckedDate_CheckForCodeplexRelease_DoesnotUpdateCheckDate()
{
var previousCheck = DateTime.Today;
var previousCheck = DateTime.UtcNow.Date;
File.WriteAllText(FileLocations.LastUpdateCheck, previousCheck.ToString(CultureInfo.InvariantCulture));
ReleaseInfo checkResult = this.RunUpdateCheck();

Expand Down

0 comments on commit 0fb4fd2

Please sign in to comment.