Merge pull request #358 from willduff/issue262

Issue #224 - Google Blogger scheduled post is scheduled at the wrong time
This commit is contained in:
Will Duff 2016-02-13 15:06:33 -06:00
commit e53b05bfea
1 changed files with 21 additions and 13 deletions

View File

@ -80,7 +80,6 @@ namespace OpenLiveWriter.BlogClient.Clients
Permalink = page.Url, Permalink = page.Url,
Contents = page.Content, Contents = page.Content,
DatePublished = page.Published.Value, DatePublished = page.Published.Value,
//Keywords = string.Join(LabelDelimiter, page.Labels)
}; };
} }
@ -97,33 +96,41 @@ namespace OpenLiveWriter.BlogClient.Clients
}; };
} }
private static Page ConvertToGoogleBloggerPage(BlogPost page) private static Page ConvertToGoogleBloggerPage(BlogPost page, IBlogClientOptions clientOptions)
{ {
return new Page() return new Page()
{ {
Content = page.Contents, Content = page.Contents,
// TODO:OLW - DatePublishedOverride didn't work quite right. Either the date published override was off by several hours, Published = GetDatePublishedOverride(page, clientOptions),
// needs to be normalized to UTC or the Blogger website thinks I'm in the wrong time zone.
Published = page.HasDatePublishedOverride ? page?.DatePublishedOverride : null,
Title = page.Title, Title = page.Title,
}; };
} }
private static Post ConvertToGoogleBloggerPost(BlogPost post) private static Post ConvertToGoogleBloggerPost(BlogPost post, IBlogClientOptions clientOptions)
{ {
var labels = post.Categories?.Select(x => x.Name).ToList(); var labels = post.Categories?.Select(x => x.Name).ToList();
labels?.AddRange(post.NewCategories?.Select(x => x.Name) ?? new List<string>()); labels?.AddRange(post.NewCategories?.Select(x => x.Name) ?? new List<string>());
return new Post() return new Post()
{ {
Content = post.Contents, Content = post.Contents,
Labels = labels ?? new List<string>(), Labels = labels ?? new List<string>(),
// TODO:OLW - DatePublishedOverride didn't work quite right. Either the date published override was off by several hours, Published = GetDatePublishedOverride(post, clientOptions),
// needs to be normalized to UTC or the Blogger website thinks I'm in the wrong time zone.
Published = post.HasDatePublishedOverride ? post?.DatePublishedOverride : null,
Title = post.Title, Title = post.Title,
}; };
} }
private static DateTime? GetDatePublishedOverride(BlogPost post, IBlogClientOptions clientOptions)
{
DateTime? datePublishedOverride = post.HasDatePublishedOverride ? post?.DatePublishedOverride : null;
if (datePublishedOverride.HasValue && clientOptions.UseLocalTime)
{
datePublishedOverride = DateTimeHelper.UtcToLocal(datePublishedOverride.Value);
}
return datePublishedOverride;
}
private static PageInfo ConvertToPageInfo(Page page) private static PageInfo ConvertToPageInfo(Page page)
{ {
// Google Blogger doesn't support parent/child pages, so we pass string.Empty. // Google Blogger doesn't support parent/child pages, so we pass string.Empty.
@ -160,6 +167,7 @@ namespace OpenLiveWriter.BlogClient.Clients
clientOptions.SupportsGetKeywords = false; clientOptions.SupportsGetKeywords = false;
clientOptions.SupportsPages = true; clientOptions.SupportsPages = true;
clientOptions.SupportsExtendedEntries = true; clientOptions.SupportsExtendedEntries = true;
clientOptions.UseLocalTime = true;
_clientOptions = clientOptions; _clientOptions = clientOptions;
_nsMgr = new XmlNamespaceManager(new NameTable()); _nsMgr = new XmlNamespaceManager(new NameTable());
@ -417,7 +425,7 @@ namespace OpenLiveWriter.BlogClient.Clients
throw new BlogClientPostAsDraftUnsupportedException(); throw new BlogClientPostAsDraftUnsupportedException();
} }
var bloggerPost = ConvertToGoogleBloggerPost(post); var bloggerPost = ConvertToGoogleBloggerPost(post, _clientOptions);
var newPostRequest = GetService().Posts.Insert(bloggerPost, blogId); var newPostRequest = GetService().Posts.Insert(bloggerPost, blogId);
newPostRequest.IsDraft = !publish; newPostRequest.IsDraft = !publish;
@ -437,7 +445,7 @@ namespace OpenLiveWriter.BlogClient.Clients
throw new BlogClientPostAsDraftUnsupportedException(); throw new BlogClientPostAsDraftUnsupportedException();
} }
var bloggerPost = ConvertToGoogleBloggerPost(post); var bloggerPost = ConvertToGoogleBloggerPost(post, _clientOptions);
var updatePostRequest = GetService().Posts.Update(bloggerPost, blogId, post.Id); var updatePostRequest = GetService().Posts.Update(bloggerPost, blogId, post.Id);
updatePostRequest.Publish = publish; updatePostRequest.Publish = publish;
@ -543,7 +551,7 @@ namespace OpenLiveWriter.BlogClient.Clients
throw new BlogClientPostAsDraftUnsupportedException(); throw new BlogClientPostAsDraftUnsupportedException();
} }
var bloggerPage = ConvertToGoogleBloggerPage(page); var bloggerPage = ConvertToGoogleBloggerPage(page, _clientOptions);
var newPageRequest = GetService().Pages.Insert(bloggerPage, blogId); var newPageRequest = GetService().Pages.Insert(bloggerPage, blogId);
newPageRequest.IsDraft = !publish; newPageRequest.IsDraft = !publish;
@ -563,7 +571,7 @@ namespace OpenLiveWriter.BlogClient.Clients
throw new BlogClientPostAsDraftUnsupportedException(); throw new BlogClientPostAsDraftUnsupportedException();
} }
var bloggerPage = ConvertToGoogleBloggerPage(page); var bloggerPage = ConvertToGoogleBloggerPage(page, _clientOptions);
var updatePostRequest = GetService().Pages.Update(bloggerPage, blogId, page.Id); var updatePostRequest = GetService().Pages.Update(bloggerPage, blogId, page.Id);
updatePostRequest.Publish = publish; updatePostRequest.Publish = publish;