feat: 添加YJ历时间转换

This commit is contained in:
uye
2022-12-19 02:09:36 +08:00
parent 1c69a97899
commit bad80da309
5 changed files with 82 additions and 15 deletions

View File

@@ -0,0 +1,66 @@
// <copyright file="Utils.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
// </copyright>
using System;
namespace MaaWpfGui
{
public static class Utils
{
/// <summary>
/// 获取yj历时间
/// </summary>
/// <returns>yj历时间</returns>
public static DateTime GetYJTimeNow()
{
return DateTime.UtcNow.AddHours(4);
}
/// <summary>
/// 获取yj历时间字符串
/// </summary>
/// <returns>yj历时间的字符串表示形式</returns>
public static string GetYJTimeNowString()
{
return GetYJTimeNow().ToString();
}
/// <summary>
/// 获取yj历日期
/// </summary>
/// <returns>yj历日期</returns>
public static DateTime GetYJTimeDate()
{
return GetYJTimeNow().Date;
}
/// <summary>
/// 获取yj历日期字符串
/// </summary>
/// <returns>yj历日期的字符串表示形式</returns>
public static string GetYJTimeDateString()
{
return GetYJTimeDate().ToString();
}
/// <summary>
/// 将日期转换为yj历日期
/// </summary>
/// <param name="dt"></param>
/// <returns>yj历格式的时间</returns>
public static DateTime ToYJTime(DateTime dt)
{
return dt.AddHours(4);
}
}
}

View File

@@ -103,6 +103,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Helper\Utils.cs" />
<Compile Include="Main\Bootstrapper.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Main\AsstProxy.cs" />

View File

@@ -500,7 +500,7 @@ namespace MaaWpfGui
}
else if (taskChain == "Mall")
{
settingsModel.LastCreditFightTaskTime = DateTime.UtcNow.AddHours(4).Date.ToString();
settingsModel.LastCreditFightTaskTime = Utils.GetYJTimeDateString();
}
mainModel.AddLog(Localization.GetString("CompleteTask") + taskChain);

View File

@@ -1032,7 +1032,7 @@ namespace MaaWpfGui
}
/* 访问好友设置 */
private string _lastCreditFightTaskTime = ViewStatusStorage.Get("Visit.LastCreditFightTaskTime", DateTime.UtcNow.AddHours(4).Date.AddDays(-1).ToString());
private string _lastCreditFightTaskTime = ViewStatusStorage.Get("Visit.LastCreditFightTaskTime", Utils.GetYJTimeDate().AddDays(-1).ToString());
public string LastCreditFightTaskTime
{
@@ -1053,7 +1053,7 @@ namespace MaaWpfGui
{
get
{
if (DateTime.UtcNow.AddHours(4).Date > DateTime.Parse(LastCreditFightTaskTime).Date)
if (Utils.GetYJTimeDate() > DateTime.Parse(LastCreditFightTaskTime).Date)
{
return _creditFightTaskEnabled;
}

View File

@@ -309,26 +309,26 @@ namespace MaaWpfGui
private bool NeedToUpdateDatePrompt()
{
var now = DateTime.UtcNow.AddHours(8);
var now = Utils.GetYJTimeNow();
var hour = now.Hour;
var min = now.Minute;
if (hour >= 0 && hour < 4)
{
now = now.AddDays(-1);
}
if (min == 0 && hour == 16)
// yj历的16点
if (min == 0 && hour == 12)
{
return true;
}
else if (_curDayOfWeek == now.DayOfWeek)
{
return false;
}
else
{
_curDayOfWeek = now.DayOfWeek;
return true;
if (_curDayOfWeek == now.DayOfWeek)
{
return false;
}
else
{
_curDayOfWeek = now.DayOfWeek;
return true;
}
}
}