Skip to content

Commit

Permalink
Auto handle PHP timezone setting (closes #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
berrnd committed Jul 29, 2023
1 parent 7de65cb commit 88f2edb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion grocy-desktop/Management/GrocyManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GrocyDesktop.Helpers;
using GrocyDesktop.Helpers;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -86,6 +86,15 @@ public void Setup()
File.Copy(Path.Combine(this.BasePath, "config-dist.php"), Path.Combine(this.DataPath, "config.php"), true);
File.Copy(Path.Combine(this.BasePath, "config-dist.php"), Path.Combine(this.BasePath, "data", "config.php"), true); // Dummy

// Set the PHP timezone to the system ones by adding code calling date_default_timezone_set to (the end of) config.php
int utcOffsetHours = DateTimeOffset.Now.Offset.Hours;
string isDst = "0";
if (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Now))
{
isDst = "1";
}
File.AppendAllText(Path.Combine(this.DataPath, "config.php"), $"{System.Environment.NewLine}date_default_timezone_set(timezone_name_from_abbr(\"\", {utcOffsetHours}*3600, {isDst}));");

foreach (string item in Directory.GetFiles(Path.Combine(this.DataPath, "viewcache")))
{
File.Delete(item);
Expand Down

0 comments on commit 88f2edb

Please sign in to comment.