Skip to content

Commit

Permalink
fix: Use unix seconds to record update time
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Oct 18, 2021
1 parent 6d76f13 commit 2b9bcdf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private void UpdateNodeCheckerNewNodeFound(object sender, EventArgs e)
{
foreach (var serverSubscribe in config.ServerSubscribes.Where(serverSubscribe => serverSubscribe.Url == Global.UpdateNodeChecker.SubscribeTask.Url))
{
serverSubscribe.LastUpdateTime = (ulong)DateTimeOffset.Now.ToUnixTimeSeconds();
serverSubscribe.LastUpdateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}

var defaultServer = new Server();
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/Model/ServerSubscribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ServerSubscribe : ViewModelBase
{
private string _url;
private string _tag;
private ulong _lastUpdateTime;
private long _lastUpdateTime;
private bool _autoCheckUpdate;
private HttpRequestProxyType _proxyType;

Expand Down Expand Up @@ -58,7 +58,7 @@ public string Tag
}
}

public ulong LastUpdateTime
public long LastUpdateTime
{
get => _lastUpdateTime;
set
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/View/SubscribeWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Shadowsocks.View.SubscribeWindow"
<Window x:Class="Shadowsocks.View.SubscribeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:model="clr-namespace:Shadowsocks.Model"
Expand Down Expand Up @@ -36,7 +36,7 @@
</DockPanel>
</StackPanel>
</DataTemplate>
<valueConverter:UlongToDateTimeString x:Key="UlongToDateTimeString" />
<valueConverter:UnixSecondsToString x:Key="UlongToDateTimeString" />
<valueConverter:ProxyTypeConverter x:Key="ProxyTypeConverter" />
</ResourceDictionary>
</Window.Resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

namespace Shadowsocks.View.ValueConverter
{
public class UlongToDateTimeString : IValueConverter
public class UnixSecondsToString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is ulong lastUpdateTime && targetType == typeof(string))
if (value is long lastUpdateTime && targetType == typeof(string))
{
if (lastUpdateTime != 0)
if (lastUpdateTime is not 0)
{
var now = new DateTime(1970, 1, 1, 0, 0, 0);
now = now.AddSeconds(lastUpdateTime);
return $@"{now.ToLongDateString()} {now.ToLongTimeString()}";
return DateTimeOffset.FromUnixTimeSeconds(lastUpdateTime).ToLocalTime().ToString();
}
}
return @"(`・ω・´)";
Expand Down

0 comments on commit 2b9bcdf

Please sign in to comment.