Skip to content

Commit

Permalink
[refactor] DDateTime::UnixTimeOfCurrentContext移到DataExtensions中
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed Mar 16, 2024
1 parent 1afe411 commit 66fc1d0
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Luban.Bson/BsonDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Accept(DString type, BsonDataWriter x)

public virtual void Accept(DDateTime type, BsonDataWriter x)
{
x.WriteValue(type.UnixTimeOfCurrentContext);
x.WriteValue(type.UnixTimeOfCurrentContext());
}

public virtual void Accept(DBean type, BsonDataWriter x)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.Core/DataVisitors/ToLiteralVisitorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public virtual string Accept(DString type)

public virtual string Accept(DDateTime type)
{
return type.UnixTimeOfCurrentContext.ToString();
return type.UnixTimeOfCurrentContext().ToString();
}

public abstract string Accept(DBean type);
Expand Down
4 changes: 1 addition & 3 deletions src/Luban.Core/Datas/DDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public DDateTime(DateTime time)
this.Time = time;
}

public long UnixTimeOfCurrentContext => GetUnixTime(GenerationContext.Current.TimeZone);

public override bool Equals(object obj)
{
return obj is DDateTime d && Time == d.Time;
Expand Down Expand Up @@ -45,7 +43,7 @@ public string ToFormatString()
public long GetUnixTime(TimeZoneInfo asTimeZone)
{
var destDateTime = TimeZoneInfo.ConvertTime(Time, asTimeZone, TimeZoneInfo.Utc);
return (long)new DateTimeOffset(destDateTime).ToUnixTimeSeconds();
return new DateTimeOffset(destDateTime).ToUnixTimeSeconds();
}

public override void Apply<T>(IDataActionVisitor<T> visitor, T x)
Expand Down
16 changes: 16 additions & 0 deletions src/Luban.Core/Utils/DataExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Luban.Datas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Luban.Utils;

public static class DataExtensions
{
public static long UnixTimeOfCurrentContext(this DDateTime dateTime)
{
return dateTime.GetUnixTime(GenerationContext.Current.TimeZone);
}
}
2 changes: 1 addition & 1 deletion src/Luban.DataTarget.Builtin/Binary/BinaryDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Accept(DString type, ByteBuf x)

public void Accept(DDateTime type, ByteBuf x)
{
x.WriteLong(type.UnixTimeOfCurrentContext);
x.WriteLong(type.UnixTimeOfCurrentContext());
}

public void Accept(DBean type, ByteBuf x)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.DataTarget.Builtin/Json/JsonDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Accept(DString type, Utf8JsonWriter x)

public virtual void Accept(DDateTime type, Utf8JsonWriter x)
{
x.WriteNumberValue(type.UnixTimeOfCurrentContext);
x.WriteNumberValue(type.UnixTimeOfCurrentContext());
}

public virtual void Accept(DBean type, Utf8JsonWriter x)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.DataTarget.Builtin/Xml/XmlDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Accept(DString type, XmlWriter w)

public void Accept(DDateTime type, XmlWriter w)
{
w.WriteValue(type.UnixTimeOfCurrentContext);
w.WriteValue(type.UnixTimeOfCurrentContext());
}

public void Accept(DBean type, XmlWriter w)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.DataTarget.Builtin/Yaml/YamlDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public YamlNode Accept(DString type)

public YamlNode Accept(DDateTime type)
{
return ToPlainNode(type.UnixTimeOfCurrentContext.ToString());
return ToPlainNode(type.UnixTimeOfCurrentContext().ToString());
}

public YamlNode Accept(DBean type)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.MsgPack/MsgPackDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void Accept(DString type, ref MessagePackWriter writer)

public void Accept(DDateTime type, ref MessagePackWriter writer)
{
writer.Write(type.UnixTimeOfCurrentContext);
writer.Write(type.UnixTimeOfCurrentContext());
}

public void Accept(DBean type, ref MessagePackWriter writer)
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.Protobuf/DataVisitors/ProtobufBinDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Accept(DEnum type, CodedOutputStream x)

public void Accept(DDateTime type, CodedOutputStream x)
{
x.WriteInt64(type.UnixTimeOfCurrentContext);
x.WriteInt64(type.UnixTimeOfCurrentContext());
}

public void Accept(DString type, CodedOutputStream x)
Expand Down

0 comments on commit 66fc1d0

Please sign in to comment.