From: Kimura Youichi Date: Tue, 8 May 2018 01:37:05 +0000 (+0900) Subject: UserInfoクラスで扱う日時の型をDateTimeUtcに変更 X-Git-Tag: OpenTween_v1.4.2~10^2~6 X-Git-Url: http://git.osdn.net/view?p=opentween%2Fopen-tween.git;a=commitdiff_plain;h=e382a86289aeeef3d807356bc1569147dd827eca UserInfoクラスで扱う日時の型をDateTimeUtcに変更 --- diff --git a/OpenTween.Tests/DateTimeUtcTest.cs b/OpenTween.Tests/DateTimeUtcTest.cs index ef2904c3..cbcebc8a 100644 --- a/OpenTween.Tests/DateTimeUtcTest.cs +++ b/OpenTween.Tests/DateTimeUtcTest.cs @@ -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); diff --git a/OpenTween/DateTimeUtc.cs b/OpenTween/DateTimeUtc.cs index f5b84082..a28ca03d 100644 --- a/OpenTween/DateTimeUtc.cs +++ b/OpenTween/DateTimeUtc.cs @@ -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); diff --git a/OpenTween/ListManage.cs b/OpenTween/ListManage.cs index 9371d092..ec06f75d 100644 --- a/OpenTween/ListManage.cs +++ b/OpenTween/ListManage.cs @@ -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 diff --git a/OpenTween/UserInfo.cs b/OpenTween/UserInfo.cs index 71f37346..a026174f 100644 --- a/OpenTween/UserInfo.cs +++ b/OpenTween/UserInfo.cs @@ -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形式 "Tween" public bool isFollowing = false; public bool isFollowed = false;