sourcegit-scm / sourcegit

Windows/macOS/Linux GUI client for GIT users
MIT License
610 stars 66 forks source link

commit time doesn't take the right timezone #229

Closed ghiboz closed 3 days ago

ghiboz commented 4 days ago

I'm using with my custom server (i'm on CEST as timezone) and this is a gk list: image

and this is a sourcegit list: image

love-linger commented 3 days ago

Commit datetime gets from git log --pretty=format:"%ct", which outputs the Unix timestamp of commit time, and converts to the local time zone of your PC by this code:

 public string CommitterTimeStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd HH:mm:ss");
 public string CommitterTimeShortStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd");

 private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();

I don't know if the algorithm is wrong.

gadfly3173 commented 3 days ago

I don't know if the algorithm is wrong.

It may be because your _utcStart is converted to local time when it is initialized, instead of converting the calculated target time to local time. Daylight saving time changes will not be reflected in the UTC timestamp 0.

love-linger commented 3 days ago

I don't know if the algorithm is wrong.

It may be because your _utcStart is converted to local time when it is initialized, instead of converting the calculated target time to local time. Daylight saving time changes will not be reflected in the UTC timestamp 0.

Should I change the code to:

DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(...)
gadfly3173 commented 3 days ago
DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(...)

I am not familiar with time handling in C#, but it looks similar to what I usually do in Java (as shown below)

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp))
love-linger commented 3 days ago
DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(...)

I am not familiar with time handling in C#, but it looks similar to what I usually do in Java (as shown below)

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp))

Thanks for reply. I'll try to fix it by this way.

ghiboz commented 3 days ago

thanks! checked and works fine here now! 👏🏻