OSDN Git Service

UserInfoクラスで扱う日時の型をDateTimeUtcに変更
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 8 May 2018 01:37:05 +0000 (10:37 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 9 May 2018 01:24:09 +0000 (10:24 +0900)
OpenTween.Tests/DateTimeUtcTest.cs
OpenTween/DateTimeUtc.cs
OpenTween/ListManage.cs
OpenTween/UserInfo.cs

index ef2904c..cbcebc8 100644 (file)
@@ -146,6 +146,23 @@ namespace OpenTween
         }
 
         [Fact]
+        public void ToString_FormatTest()
+        {
+            var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
+
+            Assert.Equal("2018-05-06 11:22:33.111 +00:00", utc.ToString("yyyy-MM-dd HH:mm:ss.fff zzz"));
+        }
+
+        [Fact]
+        public void ToLocalString_FormatTest()
+        {
+            var localDatetime = new DateTime(2018, 5, 6, 11, 22, 33, 111, DateTimeKind.Local);
+            var utc = new DateTimeUtc(localDatetime.ToUniversalTime());
+
+            Assert.Equal(localDatetime.ToString("O"), utc.ToLocalTimeString("O"));
+        }
+
+        [Fact]
         public void OperatorPlus_Test()
         {
             var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
index f5b8408..a28ca03 100644 (file)
@@ -94,6 +94,15 @@ namespace OpenTween
         public override int GetHashCode()
             => this.datetime.GetHashCode();
 
+        public override string ToString()
+            => this.ToDateTimeOffset().ToString();
+
+        public string ToString(string format)
+            => this.ToDateTimeOffset().ToString(format);
+
+        public string ToLocalTimeString(string format)
+            => this.ToLocalTime().ToString(format);
+
         public static DateTimeUtc operator +(DateTimeUtc a, TimeSpan b)
             => new DateTimeUtc(a.datetime + b);
 
index 9371d09..ec06f75 100644 (file)
@@ -322,7 +322,7 @@ namespace OpenTween
                 this.UserProfile.Text = user.Description;
                 if (!String.IsNullOrEmpty(user.RecentPost))
                 {
-                    this.UserTweetDateTime.Text = user.PostCreatedAt.ToString("yy/MM/dd HH:mm");
+                    this.UserTweetDateTime.Text = user.PostCreatedAt.ToLocalTimeString("yy/MM/dd HH:mm");
                     this.UserTweet.Text = user.RecentPost;
                 }
                 else
index 71f3734..a026174 100644 (file)
@@ -55,13 +55,13 @@ namespace OpenTween
             this.Protect = user.Protected;
             this.FriendsCount = user.FriendsCount;
             this.FollowersCount = user.FollowersCount;
-            this.CreatedAt = MyCommon.DateTimeParse(user.CreatedAt);
+            this.CreatedAt = new DateTimeUtc(MyCommon.DateTimeParse(user.CreatedAt).ToUniversalTime());
             this.StatusesCount = user.StatusesCount;
             this.Verified = user.Verified;
             if (user.Status != null)
             {
                 this.RecentPost = user.Status.FullText;
-                this.PostCreatedAt = MyCommon.DateTimeParse(user.Status.CreatedAt);
+                this.PostCreatedAt = new DateTimeUtc(MyCommon.DateTimeParse(user.Status.CreatedAt).ToUniversalTime());
                 this.PostSource = user.Status.Source;
             }
         }
@@ -76,11 +76,11 @@ namespace OpenTween
         public int FriendsCount = 0;
         public int FollowersCount = 0;
         public int FavoriteCount = 0;
-        public DateTime CreatedAt = new DateTime();
+        public DateTimeUtc CreatedAt;
         public int StatusesCount = 0;
         public bool Verified = false;
         public string RecentPost = "";
-        public DateTime PostCreatedAt = new DateTime();
+        public DateTimeUtc PostCreatedAt;
         public string PostSource = "";        // html形式 "<a href="http://sourceforge.jp/projects/tween/wiki/FrontPage" rel="nofollow">Tween</a>"
         public bool isFollowing = false;
         public bool isFollowed = false;