Skip to content

Commit

Permalink
Merge pull request #2 from ChiiAyano/fix/crash-on-next-is-tomorrow
Browse files Browse the repository at this point in the history
次の更新が翌日だったときに死ぬのを修正
  • Loading branch information
ChiiAyano committed Apr 24, 2020
2 parents 12ed5de + 4efc8f4 commit 4109006
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ObsClock/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,17 @@ private static DateTimeOffset NextShowClockTime(int interval)
var now = DateTimeOffset.Now;

// 計算で次の間隔にする
// 例えば 15 分間隔で、今が 10 時 40 分だった場合、 40 + (15 -(40 % 15)) = 40 + 5 = 45
// 例えば 15 分間隔で、今が 10 時 40 分だった場合、 40 + (15 - (40 % 15)) = 40 + 5 = 45
var n = now.Minute + (interval - (now.Minute % interval));
var hourOffset = 0;

return new DateTimeOffset(now.Year, now.Month, now.Day, (n >= 60 ? now.Hour + 1 : now.Hour), (n >= 60 ? 60 - n : n), 0, now.Offset);
if (n >= 60)
{
n -= 60;
hourOffset = 1;
}

return new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, n, 0, now.Offset).AddHours(hourOffset);
}

private static bool IsAlwaysShowClockTime
Expand Down

0 comments on commit 4109006

Please sign in to comment.