[change] 使用int64存储datetime类型,避免读取日期超过2038年出现问题 (#38)

main
wmltogether 2023-01-29 13:42:46 +08:00 committed by GitHub
parent ea30f8c202
commit ae87bf3f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 42 additions and 41 deletions

View File

@ -179,7 +179,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, ByteBuf x) public void Accept(DDateTime type, ByteBuf x)
{ {
x.WriteInt(type.UnixTimeOfCurrentAssembly); x.WriteLong(type.UnixTimeOfCurrentAssembly);
} }
} }
} }

View File

@ -87,7 +87,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, CodedOutputStream x) public void Accept(DDateTime type, CodedOutputStream x)
{ {
x.WriteInt32(type.UnixTimeOfCurrentAssembly); x.WriteInt64(type.UnixTimeOfCurrentAssembly);
} }
public void Accept(DString type, CodedOutputStream x) public void Accept(DString type, CodedOutputStream x)

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.Datas
public DateTime Time { get; } public DateTime Time { get; }
//public int UnixTime { get; } //public int UnixTime { get; }
private readonly int _localTime; private readonly long _localTime;
public override string TypeName => "datetime"; public override string TypeName => "datetime";
@ -21,7 +21,7 @@ namespace Luban.Job.Cfg.Datas
this.Time = time; this.Time = time;
// time.Kind == DateTimeKind.Unspecified // time.Kind == DateTimeKind.Unspecified
// DateTimeOffset°ÑËüµ±×÷Local´¦Àí // DateTimeOffset°ÑËüµ±×÷Local´¦Àí
this._localTime = (int)new DateTimeOffset(TimeZoneInfo.ConvertTime(time, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc)).ToUnixTimeSeconds(); this._localTime = (long)new DateTimeOffset(TimeZoneInfo.ConvertTime(time, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc)).ToUnixTimeSeconds();
} }
public override bool Equals(object obj) public override bool Equals(object obj)
@ -48,7 +48,7 @@ namespace Luban.Job.Cfg.Datas
return DataUtil.FormatDateTime(Time); return DataUtil.FormatDateTime(Time);
} }
public int GetUnixTime(TimeZoneInfo asTimeZone) public long GetUnixTime(TimeZoneInfo asTimeZone)
{ {
if (asTimeZone == null || asTimeZone == TimeZoneInfo.Local) if (asTimeZone == null || asTimeZone == TimeZoneInfo.Local)
{ {
@ -57,11 +57,11 @@ namespace Luban.Job.Cfg.Datas
else else
{ {
var destDateTime = TimeZoneInfo.ConvertTime(Time, asTimeZone, TimeZoneInfo.Utc); var destDateTime = TimeZoneInfo.ConvertTime(Time, asTimeZone, TimeZoneInfo.Utc);
return (int)new DateTimeOffset(destDateTime).ToUnixTimeSeconds(); return (long)new DateTimeOffset(destDateTime).ToUnixTimeSeconds();
} }
} }
public int UnixTimeOfCurrentAssembly => GetUnixTime(DefAssembly.LocalAssebmly.TimeZone); public long UnixTimeOfCurrentAssembly => GetUnixTime(DefAssembly.LocalAssebmly.TimeZone);
public override void Apply<T>(IDataActionVisitor<T> visitor, T x) public override void Apply<T>(IDataActionVisitor<T> visitor, T x)
{ {

View File

@ -120,7 +120,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
return $"if(!{bufName}.readInt({fieldName})) return false;"; return $"if(!{bufName}.readLong({fieldName})) return false;";
} }
} }
} }

View File

@ -150,7 +150,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string json, string x, int depth) public string Accept(TDateTime type, string json, string x, int depth)
{ {
return $"{x} = {json}.GetInt32();"; return $"{x} = {json}.GetInt64();";
} }
} }
} }

View File

@ -152,7 +152,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string json, string x, int depth) public string Accept(TDateTime type, string json, string x, int depth)
{ {
return $"{x} = {json}.getAsInt();"; return $"{x} = {json}.getAsLong();";
} }
} }
} }

View File

@ -127,7 +127,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.readInt();"; return $"{fieldName} = {bufName}.readLong();";
} }
} }
} }

View File

@ -125,7 +125,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string jsonVarName) public string Accept(TDateTime type, string jsonVarName)
{ {
return AsType(jsonVarName, "i32"); return AsType(jsonVarName, "i64");
} }
} }
} }

View File

@ -122,7 +122,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "int32"; return "int64";
} }
} }
} }

View File

@ -152,7 +152,7 @@ namespace Luban.Job.Common.TypeVisitors
{ {
return mapper.TargetTypeName; return mapper.TargetTypeName;
} }
return "int"; return "long";
} }
} }
} }

View File

@ -152,7 +152,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName, int depth) public string Accept(TDateTime type, string bufName, string fieldName, int depth)
{ {
string src = $"{bufName}.ReadInt()"; string src = $"{bufName}.ReadLong()";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("datetime", src)};"; return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("datetime", src)};";
} }
} }

View File

@ -122,7 +122,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
return $"{bufName}.WriteInt({fieldName});"; return $"{bufName}.WriteLong({fieldName});";
} }
} }
} }

View File

@ -98,7 +98,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "int32"; return "int64";
} }
public string Accept(TBean type) public string Accept(TBean type)

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string fieldName, string bufName, string err) public string Accept(TDateTime type, string fieldName, string bufName, string err)
{ {
return $"{{ if {fieldName}, {err} = {bufName}.ReadInt(); {err} != nil {{ {err} = errors.New(\"{fieldName} error\"); return }} }}"; return $"{{ if {fieldName}, {err} = {bufName}.ReadLong(); {err} != nil {{ {err} = errors.New(\"{fieldName} error\"); return }} }}";
} }
public string Accept(TBean type, string fieldName, string bufName, string err) public string Accept(TBean type, string fieldName, string bufName, string err)

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string fieldName, string bufName) public string Accept(TDateTime type, string fieldName, string bufName)
{ {
return $"{bufName}.WriteInt({fieldName})"; return $"{bufName}.WriteLong({fieldName})";
} }
public string Accept(TBean type, string fieldName, string bufName) public string Accept(TBean type, string fieldName, string bufName)

View File

@ -119,7 +119,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "int32"; return "int64";
} }
} }
} }

View File

@ -58,7 +58,7 @@ namespace Luban.Job.Common.TypeVisitors
public override string Accept(TDateTime type) public override string Accept(TDateTime type)
{ {
return "Integer"; return "Long";
} }
public override string Accept(TEnum type) public override string Accept(TEnum type)

View File

@ -119,7 +119,7 @@ namespace Luban.Job.Common.TypeVisitors
public virtual string Accept(TDateTime type) public virtual string Accept(TDateTime type)
{ {
return type.IsNullable ? "Integer" : "int"; return type.IsNullable ? "Long" : "long";
} }
} }
} }

View File

@ -149,7 +149,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName, int depth) public string Accept(TDateTime type, string bufName, string fieldName, int depth)
{ {
return $"{fieldName} = {bufName}.readInt();"; return $"{fieldName} = {bufName}.readLong();";
} }
} }
} }

View File

@ -122,7 +122,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
return $"{bufName}.writeInt({fieldName});"; return $"{bufName}.writeLong({fieldName});";
} }
} }
} }

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "readInt"; return "readLong";
} }
} }
} }

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "writeInt"; return "writeLong";
} }
} }
} }

View File

@ -98,7 +98,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "int32"; return "int64";
} }
public string Accept(TBean type) public string Accept(TBean type)

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "i32"; return "i64";
} }
} }
} }

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "INT"; return "LONG";
} }
} }
} }

View File

@ -166,7 +166,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufVarName, string fieldName) public string Accept(TDateTime type, string bufVarName, string fieldName)
{ {
return $"{fieldName} = {bufVarName}.ReadInt()"; return $"{fieldName} = {bufVarName}.ReadLong()";
} }
} }
} }

View File

@ -93,7 +93,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufVarName, string fieldName) public string Accept(TDateTime type, string bufVarName, string fieldName)
{ {
return $"{bufVarName}.WriteInt({fieldName})"; return $"{bufVarName}.WriteLong({fieldName})";
} }
public virtual string Accept(TBean type, string bufVarName, string fieldName) public virtual string Accept(TBean type, string bufVarName, string fieldName)

View File

@ -151,7 +151,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadInt();"; return $"{fieldName} = {bufName}.ReadLong();";
} }
} }
} }

View File

@ -150,9 +150,9 @@ namespace Luban.Job.Db.TypeVisitors
return $"{bufName}.WriteVector4({fieldName});"; return $"{bufName}.WriteVector4({fieldName});";
} }
public string Accept(TDateTime type, string x, string y) public string Accept(TDateTime type, string bufName, string fieldName)
{ {
throw new NotImplementedException(); return $"{bufName}.WriteLong({fieldName});";
} }
} }
} }

View File

@ -128,7 +128,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "Bright.Common.SerializationUtil.DeserializeInt"; return "Bright.Common.SerializationUtil.DeserializeLong";
} }
} }
} }

View File

@ -131,7 +131,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type, string fieldName) public string Accept(TDateTime type, string fieldName)
{ {
throw new NotSupportedException(); return $"{fieldName} = default;";
} }
} }
} }

View File

@ -128,7 +128,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "Bright.Common.SerializationUtil.SerializeInt"; return "Bright.Common.SerializationUtil.SerializeLong";
} }
} }
} }

View File

@ -128,7 +128,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "SerializeFactory.deserializeInt"; return "SerializeFactory.deserializeLong";
} }
} }
} }

View File

@ -130,9 +130,10 @@ namespace Luban.Job.Db.TypeVisitors
return $"{fieldName} = new Vector4()"; return $"{fieldName} = new Vector4()";
} }
public string Accept(TDateTime type, string x, string y) public string Accept(TDateTime type, string fieldName, string logType
)
{ {
throw new NotSupportedException(); return $"{fieldName} = 0";
} }
} }
} }

View File

@ -128,7 +128,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "SerializeFactory.serializeInt"; return "SerializeFactory.serializeLong";
} }
} }
} }