OSDN Git Service

ToolStripLabelHistoryで扱うログの日時をDateTimeUtcに変更
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 7 May 2018 04:03:44 +0000 (13:03 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 9 May 2018 01:24:05 +0000 (10:24 +0900)
OpenTween.Tests/DateTimeUtcTest.cs
OpenTween/DateTimeUtc.cs
OpenTween/ToolStripLabelHistory.cs

index b91577f..ef2904c 100644 (file)
@@ -100,6 +100,15 @@ namespace OpenTween
         }
 
         [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);
index 47a6452..f5b8408 100644 (file)
@@ -76,6 +76,9 @@ namespace OpenTween
         public DateTimeOffset ToDateTimeOffset()
             => new DateTimeOffset(this.datetime);
 
+        public DateTimeOffset ToLocalTime()
+            => this.ToDateTimeOffset().ToLocalTime();
+
         public DateTime ToDateTimeUnsafe()
             => this.datetime;
 
index b4e9eb8..553baeb 100644 (file)
@@ -49,11 +49,11 @@ namespace OpenTween.OpenTweenCustomControl
         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;
@@ -61,13 +61,13 @@ namespace OpenTween.OpenTweenCustomControl
                 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;
             }
         }
 
@@ -80,7 +80,7 @@ namespace OpenTween.OpenTweenCustomControl
             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();