}
[Fact]
+ public void ToLocalTime()
+ {
+ var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
+ var expected = new DateTimeOffset(2018, 5, 6, 11, 22, 33, 111, TimeSpan.Zero).ToLocalTime();
+
+ Assert.Equal(expected, utc.ToLocalTime());
+ }
+
+ [Fact]
public void CompareTo_Test()
{
var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
public DateTimeOffset ToDateTimeOffset()
=> new DateTimeOffset(this.datetime);
+ public DateTimeOffset ToLocalTime()
+ => this.ToDateTimeOffset().ToLocalTime();
+
public DateTime ToDateTimeUnsafe()
=> this.datetime;
public class LogEntry
{
public LogLevel LogLevel { get; }
- public DateTime Timestamp { get; }
+ public DateTimeUtc Timestamp { get; }
public string Summary { get; }
public string Detail { get; }
- public LogEntry(LogLevel logLevel, DateTime timestamp, string summary, string detail)
+ public LogEntry(LogLevel logLevel, DateTimeUtc timestamp, string summary, string detail)
{
this.LogLevel = logLevel;
this.Timestamp = timestamp;
this.Detail = detail;
}
- public LogEntry(DateTime timestamp, string summary) : this(LogLevel.Debug, timestamp, summary, summary)
+ public LogEntry(DateTimeUtc timestamp, string summary) : this(LogLevel.Debug, timestamp, summary, summary)
{
}
public override string ToString()
{
- return Timestamp.ToString("T") + ": " + Summary;
+ return Timestamp.ToLocalTime().ToString("T") + ": " + Summary;
}
}
get { return base.Text; }
set
{
- _logs.AddLast(new LogEntry(DateTime.Now, value));
+ _logs.AddLast(new LogEntry(DateTimeUtc.Now, value));
while (_logs.Count > MAXCNT)
{
_logs.RemoveFirst();