Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14: Make PostDateGmt and PostModifiedGmt nullable because they can contain empty values #15

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Nullable>enable</Nullable>

<!-- NuGet -->
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Authors>Armin Reiter; Jon Sagara</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class WordPressExportItem
/// <summary>
/// The post_date_gmt element's value.
/// </summary>
public DateTime PostDateGmt { get; set; }
public DateTime? PostDateGmt { get; set; }

/// <summary>
/// The post_modified element's value.
Expand All @@ -41,7 +41,7 @@ public class WordPressExportItem
/// <summary>
/// The post_modified_gmt element's value.
/// </summary>
public DateTime PostModifiedGmt { get; set; }
public DateTime? PostModifiedGmt { get; set; }

/// <summary>
/// The comment_status element's value.
Expand Down Expand Up @@ -109,9 +109,14 @@ public WordPressExportItem(XElement itemElement)

PostId = Helpers.TryParseLong(itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_id"))!.Value;
PostDate = Helpers.TryParseDateTime(itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_date"))!.Value;
PostDateGmt = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_date_gmt").ParseUtcOrDefault()!.Value;

// We can't assume that a post will have a valid GMT date. One of my entries did not.
PostDateGmt = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_date_gmt").ParseUtcOrDefault();

PostModified = Helpers.TryParseDateTime(itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_modified"))!.Value;
PostModifiedGmt = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_modified_gmt").ParseUtcOrDefault()!.Value;

// We can't assume that a post will have a valid GMT date. One of my entries did not.
PostModifiedGmt = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "post_modified_gmt").ParseUtcOrDefault();

CommentStatus = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "comment_status")!;
PingStatus = itemElement.GetChildElementValue(namespacePrefix: WordPressExportChannel.NamespacePrefix, elementName: "ping_status")!;
Expand Down