From e77604b7a99a17ddf7db127c89935f635c12af6f Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Sat, 13 Nov 2021 19:55:16 -0500 Subject: [PATCH 1/4] Fixes for the display date and time... - We save everything as UTC, we do not really do timezones, I will resolve that later ... hopefully --- source/DasBlog.Services/IDasBlogSettings.cs | 1 + source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs | 5 +++++ source/DasBlog.Web.UI/Controllers/BlogPostController.cs | 4 ++-- source/DasBlog.Web.UI/Mappers/ProfilePost.cs | 8 ++++---- source/DasBlog.Web.UI/Settings/DasBlogSettings.cs | 9 +++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/source/DasBlog.Services/IDasBlogSettings.cs b/source/DasBlog.Services/IDasBlogSettings.cs index e2c95b9d..bff52ae8 100644 --- a/source/DasBlog.Services/IDasBlogSettings.cs +++ b/source/DasBlog.Services/IDasBlogSettings.cs @@ -47,5 +47,6 @@ public interface IDasBlogSettings bool IsAdmin(string gravatarhash); string GeneratePostUrl(Entry entry); SendMailInfo GetMailInfo(MailMessage emailmessage); + DateTime GetDisplayTime(DateTime datetime); } } diff --git a/source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs b/source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs index 7a7a9b8a..c181189f 100644 --- a/source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs +++ b/source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs @@ -262,5 +262,10 @@ public SendMailInfo GetMailInfo(MailMessage emailmessage) { throw new NotImplementedException(); } + + public DateTime GetDisplayTime(DateTime datetime) + { + throw new NotImplementedException(); + } } } diff --git a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs index afefe956..b688671a 100644 --- a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs +++ b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs @@ -443,10 +443,10 @@ public IActionResult AddComment(AddCommentViewModel addcomment) var commt = mapper.Map(addcomment); commt.AuthorIPAddress = HttpContext.Connection.RemoteIpAddress.ToString(); commt.AuthorUserAgent = HttpContext.Request.Headers["User-Agent"].ToString(); - commt.CreatedUtc = commt.ModifiedUtc = DateTime.UtcNow; commt.EntryId = Guid.NewGuid().ToString(); commt.IsPublic = !dasBlogSettings.SiteConfiguration.CommentsRequireApproval; - + commt.CreatedUtc = commt.ModifiedUtc = DateTime.Now.ToUniversalTime(); + logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment CONTENT DUMP", commt.Content)); var state = blogManager.AddComment(addcomment.TargetEntryId, commt); diff --git a/source/DasBlog.Web.UI/Mappers/ProfilePost.cs b/source/DasBlog.Web.UI/Mappers/ProfilePost.cs index 595630e4..60073314 100644 --- a/source/DasBlog.Web.UI/Mappers/ProfilePost.cs +++ b/source/DasBlog.Web.UI/Mappers/ProfilePost.cs @@ -35,8 +35,8 @@ public ProfilePost(IDasBlogSettings dasBlogSettings) .ForMember(dest => dest.PermaLink, opt => opt.MapFrom(src => _dasBlogSettings.GeneratePostUrl(src))) .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.Content.FindFirstImage())) .ForMember(dest => dest.VideoUrl, opt => opt.MapFrom(src => src.Content.FindFirstYouTubeVideo())) - .ForMember(dest => dest.CreatedDateTime, opt => opt.MapFrom(src => src.CreatedLocalTime)) - .ForMember(dest => dest.ModifiedDateTime, opt => opt.MapFrom(src => src.ModifiedLocalTime)); + .ForMember(dest => dest.CreatedDateTime, opt => opt.MapFrom(src => _dasBlogSettings.GetDisplayTime(src.CreatedUtc))) + .ForMember(dest => dest.ModifiedDateTime, opt => opt.MapFrom(src => _dasBlogSettings.GetDisplayTime(src.ModifiedUtc))); CreateMap() .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title)) @@ -61,7 +61,7 @@ public ProfilePost(IDasBlogSettings dasBlogSettings) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Author)) .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Content)) .ForMember(dest => dest.GravatarHashId, opt => opt.MapFrom(src => Utils.GetGravatarHash(src.AuthorEmail))) - .ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.CreatedLocalTime)) + .ForMember(dest => dest.Date, opt => opt.MapFrom(src => _dasBlogSettings.GetDisplayTime(src.CreatedUtc))) .ForMember(dest => dest.HomePageUrl, opt => opt.MapFrom(src => src.AuthorHomepage)) .ForMember(dest => dest.BlogPostId, opt => opt.MapFrom(src => src.TargetEntryId)) .ForMember(dest => dest.CommentId, opt => opt.MapFrom(src => src.EntryId)) @@ -72,7 +72,7 @@ public ProfilePost(IDasBlogSettings dasBlogSettings) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Author)) .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Content)) .ForMember(dest => dest.GravatarHashId, opt => opt.MapFrom(src => Utils.GetGravatarHash(src.AuthorEmail))) - .ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.CreatedLocalTime)) + .ForMember(dest => dest.Date, opt => opt.MapFrom(src => _dasBlogSettings.GetDisplayTime(src.CreatedUtc))) .ForMember(dest => dest.HomePageUrl, opt => opt.MapFrom(src => src.AuthorHomepage)) .ForMember(dest => dest.BlogPostId, opt => opt.MapFrom(src => src.TargetEntryId)) .ForMember(dest => dest.CommentId, opt => opt.MapFrom(src => src.EntryId)) diff --git a/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs b/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs index 0c94db4c..d2c2fb60 100644 --- a/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs +++ b/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs @@ -288,5 +288,14 @@ public SendMailInfo GetMailInfo(MailMessage emailmessage) SiteConfiguration.EnableSmtpAuthentication, SiteConfiguration.UseSSLForSMTP, SiteConfiguration.SmtpUserName, SiteConfiguration.SmtpPassword, SiteConfiguration.SmtpPort); } + + public DateTime GetDisplayTime(DateTime datetime) + { + if (SiteConfiguration.AdjustDisplayTimeZone) + { + return datetime.AddHours(SiteConfiguration.DisplayTimeZoneIndex); + } + return datetime; + } } } From fd70e1835f55d172d7fffd10061df84a10d40949 Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Sat, 13 Nov 2021 20:30:12 -0500 Subject: [PATCH 2/4] Changing the defaults to be UTC --- source/DasBlog.Services/Site/TimeZoneProvider.cs | 6 +++--- source/DasBlog.Web.UI/Config/site.Development.config | 4 ++-- source/DasBlog.Web.UI/Config/site.config | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/DasBlog.Services/Site/TimeZoneProvider.cs b/source/DasBlog.Services/Site/TimeZoneProvider.cs index 763d65e2..a316b0da 100644 --- a/source/DasBlog.Services/Site/TimeZoneProvider.cs +++ b/source/DasBlog.Services/Site/TimeZoneProvider.cs @@ -6,7 +6,7 @@ namespace DasBlog.Services.Site public class TimeZoneProvider : ITimeZoneProvider { private bool adjustDisplayTimeZone; - private decimal displayTimeZoneIndex; // this seems to be a misnomer - I think this is just an offset in hours + private decimal displayTimeZoneIndex; public TimeZoneProvider(IOptions opt) { adjustDisplayTimeZone = opt.Value.AdjustDisplayTimeZone; @@ -17,8 +17,8 @@ public DateTimeZone GetConfiguredTimeZone() // currently Sept 2018 displayTimeZoneIndex is always an int. if (adjustDisplayTimeZone) { - return DateTimeZone.ForOffset(Offset.FromHoursAndMinutes((int)displayTimeZoneIndex - , (int)(displayTimeZoneIndex % 1m * 60))); + return DateTimeZone.ForOffset(Offset.FromHoursAndMinutes((int)displayTimeZoneIndex, + (int)(displayTimeZoneIndex % 1m * 60))); } else { diff --git a/source/DasBlog.Web.UI/Config/site.Development.config b/source/DasBlog.Web.UI/Config/site.Development.config index 3d61e6ab..878b02c3 100644 --- a/source/DasBlog.Web.UI/Config/site.Development.config +++ b/source/DasBlog.Web.UI/Config/site.Development.config @@ -46,8 +46,8 @@ true true - 4 - true + -5 + false content logs content/binary diff --git a/source/DasBlog.Web.UI/Config/site.config b/source/DasBlog.Web.UI/Config/site.config index 94aa514c..0fd48ed5 100644 --- a/source/DasBlog.Web.UI/Config/site.config +++ b/source/DasBlog.Web.UI/Config/site.config @@ -46,8 +46,8 @@ true true - 4 - true + -5 + false content logs From f1f8d2aab34054ec23f94ecf43a8861f47a9a02a Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Sun, 14 Nov 2021 20:48:22 -0500 Subject: [PATCH 3/4] Default date associated with Create a post Lookahead includes offset --- source/DasBlog.Web.UI/Controllers/BlogPostController.cs | 9 +++++++++ source/DasBlog.Web.UI/Settings/DasBlogSettings.cs | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs index b688671a..05a04121 100644 --- a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs +++ b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs @@ -254,6 +254,15 @@ public IActionResult CreatePost(PostViewModel post, string submit) entry.Latitude = null; entry.Longitude = null; + if (dasBlogSettings.SiteConfiguration.AdjustDisplayTimeZone) + { + entry.CreatedUtc = entry.ModifiedUtc = post.CreatedDateTime.AddHours(-1 * dasBlogSettings.SiteConfiguration.DisplayTimeZoneIndex); + } + else + { + entry.CreatedUtc = entry.ModifiedUtc = post.CreatedDateTime; + } + var sts = blogManager.CreateEntry(entry); if (sts != NBR.EntrySaveState.Added) { diff --git a/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs b/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs index d2c2fb60..8d8b7abe 100644 --- a/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs +++ b/source/DasBlog.Web.UI/Settings/DasBlogSettings.cs @@ -168,7 +168,14 @@ public DateTimeZone GetConfiguredTimeZone() public DateTime GetContentLookAhead() { - return DateTime.UtcNow.AddDays(SiteConfiguration.ContentLookaheadDays); + if (SiteConfiguration.AdjustDisplayTimeZone) + { + return DateTime.UtcNow.AddHours(SiteConfiguration.DisplayTimeZoneIndex).AddDays(SiteConfiguration.ContentLookaheadDays); + } + else + { + return DateTime.UtcNow.AddDays(SiteConfiguration.ContentLookaheadDays); + } } public string FilterHtml(string input) From 8a67734e49458bdd03803975b5cc440b7ba82cec Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Sun, 14 Nov 2021 20:55:38 -0500 Subject: [PATCH 4/4] Version should not be double 00 --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a5d148ba..930d7c9c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ pool: variables: buildConfiguration: 'Release' - version: 3.00 + version: 3.0 steps: - task: UseDotNet@2