Skip to content

Commit 1dde69d

Browse files
committed
Cod eotpimization
1 parent 3571be6 commit 1dde69d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Comment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ internal Dictionary<string, string> ToDictionary() {
5959
var map = Author.ToDictionary();
6060
if (!string.IsNullOrWhiteSpace(Content)) map["comment_content"] = Content;
6161
// TODO if (Context.Count > 0) map["comment_context"] = string.Join(',', Context);
62-
if (Date is not null) map["comment_date_gmt"] = Date?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")!;
62+
if (Date is not null) map["comment_date_gmt"] = Date?.ToUniversalTime().ToString("o")!;
6363
if (Permalink is not null) map["permalink"] = Permalink.ToString();
64-
if (PostModified is not null) map["comment_post_modified_gmt"] = PostModified?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")!;
64+
if (PostModified is not null) map["comment_post_modified_gmt"] = PostModified?.ToUniversalTime().ToString("o")!;
6565
if (!string.IsNullOrWhiteSpace(RecheckReason)) map["recheck_reason"] = RecheckReason;
6666
if (Referrer is not null) map["referrer"] = Referrer.ToString();
6767
if (!string.IsNullOrWhiteSpace(Type)) map["comment_type"] = Type;

test/ClientTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public ClientTest() {
4949
UserAgent = "Spam Bot/6.6.6"
5050
};
5151

52-
spam = new Comment(spamAuthor) { Content = "Spam!", Type = CommentType.BlogPost };
52+
spam = new Comment(spamAuthor) {
53+
Content = "Spam!",
54+
Date = DateTime.Now,
55+
Type = CommentType.BlogPost
56+
};
5357
}
5458

5559
[TestMethod]

test/CommentTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace Belin.Akismet;
22

3+
using System.Globalization;
4+
35
/// <summary>
46
/// Tests the features of the <see cref="Comment"/> class.
57
/// </summary>
@@ -21,7 +23,7 @@ public void ToDictionary() {
2123

2224
var comment = new Comment(author) {
2325
Content = "A user comment.",
24-
Date = DateTime.Parse("2000-01-01T00:00:00.000Z"),
26+
Date = DateTime.Parse("2000-01-01T00:00:00Z", styles: DateTimeStyles.RoundtripKind),
2527
Referrer = new Uri("https://belin.io"),
2628
Type = "blog-post"
2729
};
@@ -30,7 +32,7 @@ public void ToDictionary() {
3032
AreEqual(7, map.Count);
3133
AreEqual("Cédric Belin", map["comment_author"]);
3234
AreEqual("A user comment.", map["comment_content"]);
33-
AreEqual("2000-01-01T00:00:00Z", map["comment_date_gmt"]);
35+
AreEqual("2000-01-01T00:00:00.0000000Z", map["comment_date_gmt"]);
3436
AreEqual("blog-post", map["comment_type"]);
3537
AreEqual("https://belin.io/", map["referrer"]);
3638
AreEqual("Doom/6.6.6", map["user_agent"]);

0 commit comments

Comments
 (0)