【修复】修复.net 6的TimeZone相关调整导致datetime计算错误的问题
【调整】新增datetime的等价类型名time 【调整】Luban.Server的Dockerfile不再拷备localtime文件main
parent
9cc489ecfd
commit
f6b8b32123
|
|
@ -38,6 +38,9 @@ namespace Luban.ClientServer
|
|||
|
||||
[Option('t', "template_search_path", Required = false, HelpText = "string template search path.")]
|
||||
public string TemplateSearchPath { get; set; }
|
||||
|
||||
[Option("timezone", Required = false, HelpText = "default timezone")]
|
||||
public string DefaultTimeZone { get; set; } = "Asia/Shanghai";
|
||||
}
|
||||
|
||||
private static void PrintUsage(string err)
|
||||
|
|
@ -170,7 +173,7 @@ Options:
|
|||
StringTemplateUtil.AddTemplateSearchPath(options.TemplateSearchPath);
|
||||
}
|
||||
StringTemplateUtil.AddTemplateSearchPath(FileUtil.GetPathRelateApplicationDirectory("Templates"));
|
||||
|
||||
TimeZoneUtil.DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById(options.DefaultTimeZone);
|
||||
GenServer.Ins.Start(true, options.Port, ProtocolStub.Factories);
|
||||
|
||||
GenServer.Ins.RegisterJob("cfg", new Luban.Job.Cfg.JobController());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Common.Utils
|
||||
{
|
||||
public static class TimeZoneUtil
|
||||
{
|
||||
public static TimeZoneInfo DefaultTimeZone { get; set; } = TimeZoneInfo.Utc;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using Luban.Common.Utils;
|
||||
using Luban.Job.Cfg.DataVisitors;
|
||||
using Luban.Job.Cfg.Utils;
|
||||
using System;
|
||||
|
|
@ -15,10 +16,11 @@ namespace Luban.Job.Cfg.Datas
|
|||
|
||||
public DDateTime(DateTime time)
|
||||
{
|
||||
|
||||
this.Time = time;
|
||||
// time.Kind == DateTimeKind.Unspecified
|
||||
// DateTimeOffset把它当作Local处理
|
||||
this._localTime = (int)new DateTimeOffset(time).ToUnixTimeSeconds();
|
||||
this._localTime = (int)new DateTimeOffset(TimeZoneInfo.ConvertTime(time, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc)).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Luban.Common.Utils;
|
||||
using Luban.Job.Cfg.Datas;
|
||||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Cfg.TypeVisitors;
|
||||
|
|
@ -61,6 +62,7 @@ namespace Luban.Job.Cfg.Utils
|
|||
public static DDateTime CreateDateTime(string x)
|
||||
{
|
||||
DateTime dateTime = DateTime.ParseExact(x, dateTimeFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
|
||||
//return new DDateTime(TimeZoneInfo.ConvertTime(dateTime, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc));
|
||||
return new DDateTime(dateTime);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ namespace Luban.Job.Common.Defs
|
|||
case "vector2": return TVector2.Create(nullable, tags);
|
||||
case "vector3": return TVector3.Create(nullable, tags);
|
||||
case "vector4": return TVector4.Create(nullable, tags);
|
||||
case "time":
|
||||
case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型");
|
||||
default:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
"TestTemplate": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-t D:\\workspace\\luban_examples\\Projects\\CustomTemplates"
|
||||
},
|
||||
"timezone-utc": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--timezone \"Etc/UTC\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,6 @@ COPY nuget.config ./nuget.config
|
|||
RUN dotnet publish -c Release -o out
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS runtime
|
||||
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/Luban.Server/out ./
|
||||
EXPOSE 8899/tcp
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ namespace Luban.Server
|
|||
|
||||
[Option('t', "template_search_path", Required = false, HelpText = "additional template search path")]
|
||||
public string TemplateSearchPath { get; set; }
|
||||
|
||||
[Option("timezone", Required = false, HelpText = "default timezone")]
|
||||
public string DefaultTimeZone { get; set; } = "Asia/Shanghai";
|
||||
}
|
||||
|
||||
private static CommandLineOptions ParseOptions(String[] args)
|
||||
|
|
@ -56,6 +59,8 @@ namespace Luban.Server
|
|||
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
||||
TimeZoneUtil.DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById(options.DefaultTimeZone);
|
||||
|
||||
GenServer.Ins.Start(false, options.Port, ProtocolStub.Factories);
|
||||
|
||||
GenServer.Ins.RegisterJob("cfg", new Luban.Job.Cfg.JobController());
|
||||
|
|
|
|||
Loading…
Reference in New Issue