Skip to content

Commit

Permalink
Tweak first published
Browse files Browse the repository at this point in the history
  • Loading branch information
pschaeflein committed Jan 12, 2023
1 parent 95073f4 commit 2084567
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Models/SitePageFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,20 @@ public DateTimeOffset? FirstPublishedDateTime
var firstPublishedDateJsonElement = GetListItemFieldElement("FirstPublishedDate");
if (firstPublishedDateJsonElement.ValueKind == JsonValueKind.String)
{
var firstPublishedDateString = firstPublishedDateJsonElement.ToString();
if (DateTimeOffset.TryParse(firstPublishedDateString, out var firstPublishedDate))
{
return firstPublishedDate;
}

// we don't get a timezone offset. so forcing to utc
var forcedOffsetCreated = firstPublishedDateJsonElement.ToString() + "Z";
return DateTimeOffset.Parse(forcedOffsetCreated);
if (!firstPublishedDateString.EndsWith("Z"))
{
if (DateTimeOffset.TryParse($"{firstPublishedDateString}Z", out firstPublishedDate))
{
return firstPublishedDate;
}
}
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion test/Mocks/GetSitePageResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"Description": "Make a difference ",
"PromotedState": 0.0,
"FirstPublishedDate": "2022-05-25T16:07:42",
"FirstPublishedDate": "2022-05-25T16:07:42-08:00",
"LayoutWebpartsContent": "",
"OData__AuthorBylineId": null,
"_AuthorBylineStringId": null,
Expand Down

0 comments on commit 2084567

Please sign in to comment.