Skip to content

Commit

Permalink
Fix issue #373 (update manager version check bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
genemars committed Mar 18, 2019
1 parent f28336b commit df67e55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions HomeGenie/Service/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ public List<ReleaseInfo> GetGitHubUpdates()
{
if (relFile.browser_download_url.ToString().EndsWith(".tgz"))
{
var releaseDate = DateTime.ParseExact(relFile.updated_at.ToString(), "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
if (currentRelease.ReleaseDate < releaseDate && remoteUpdates.Count == 0)
DateTime releaseDate = DateTime.ParseExact(relFile.updated_at.ToString(), "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
releaseDate = releaseDate.Round(DateTimeExtensions.RoundTo.Minute);
if (currentRelease.ReleaseDate.Round(DateTimeExtensions.RoundTo.Minute) < releaseDate && remoteUpdates.Count == 0)
{
var r = new ReleaseInfo();
r.Name = githubRepository;
Expand Down
30 changes: 30 additions & 0 deletions HomeGenie/Service/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
}
return dt.AddDays(-1 * diff).Date;
}
public static DateTime Round(this DateTime d, RoundTo rt)
{
DateTime dtRounded = new DateTime();
switch (rt)
{
case RoundTo.Second:
dtRounded = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second);
if (d.Millisecond >= 500) dtRounded = dtRounded.AddSeconds(1);
break;
case RoundTo.Minute:
dtRounded = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0);
if (d.Second >= 30) dtRounded = dtRounded.AddMinutes(1);
break;
case RoundTo.Hour:
dtRounded = new DateTime(d.Year, d.Month, d.Day, d.Hour, 0, 0);
if (d.Minute >= 30) dtRounded = dtRounded.AddHours(1);
break;
case RoundTo.Day:
dtRounded = new DateTime(d.Year, d.Month, d.Day, 0, 0, 0);
if (d.Hour >= 12) dtRounded = dtRounded.AddDays(1);
break;
}

return dtRounded;
}

public enum RoundTo
{
Second, Minute, Hour, Day
}
}

[Serializable()]
Expand Down

0 comments on commit df67e55

Please sign in to comment.