Skip to content

Commit

Permalink
Merge pull request #586 from poppastring/lookahead-offset-fix
Browse files Browse the repository at this point in the history
Lookahead offset fix

close #578
  • Loading branch information
poppastring authored Nov 15, 2021
2 parents 34938f0 + 8a67734 commit 19b7de9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pool:

variables:
buildConfiguration: 'Release'
version: 3.00
version: 3.0

steps:
- task: UseDotNet@2
Expand Down
1 change: 1 addition & 0 deletions source/DasBlog.Services/IDasBlogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public interface IDasBlogSettings
bool IsAdmin(string gravatarhash);
string GeneratePostUrl(Entry entry);
SendMailInfo GetMailInfo(MailMessage emailmessage);
DateTime GetDisplayTime(DateTime datetime);
}
}
6 changes: 3 additions & 3 deletions source/DasBlog.Services/Site/TimeZoneProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeZoneProviderOptions> opt)
{
adjustDisplayTimeZone = opt.Value.AdjustDisplayTimeZone;
Expand All @@ -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
{
Expand Down
5 changes: 5 additions & 0 deletions source/DasBlog.Tests/UnitTests/DasBlogSettingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,10 @@ public SendMailInfo GetMailInfo(MailMessage emailmessage)
{
throw new NotImplementedException();
}

public DateTime GetDisplayTime(DateTime datetime)
{
throw new NotImplementedException();
}
}
}
4 changes: 2 additions & 2 deletions source/DasBlog.Web.UI/Config/site.Development.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<EntryTitleAsLink>true</EntryTitleAsLink>
<ObfuscateEmail>true</ObfuscateEmail>

<DisplayTimeZoneIndex>4</DisplayTimeZoneIndex>
<AdjustDisplayTimeZone>true</AdjustDisplayTimeZone>
<DisplayTimeZoneIndex>-5</DisplayTimeZoneIndex>
<AdjustDisplayTimeZone>false</AdjustDisplayTimeZone>
<ContentDir>content</ContentDir>
<LogDir>logs</LogDir>
<BinariesDir>content/binary</BinariesDir>
Expand Down
4 changes: 2 additions & 2 deletions source/DasBlog.Web.UI/Config/site.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<EntryTitleAsLink>true</EntryTitleAsLink>
<ObfuscateEmail>true</ObfuscateEmail>

<DisplayTimeZoneIndex>4</DisplayTimeZoneIndex>
<AdjustDisplayTimeZone>true</AdjustDisplayTimeZone>
<DisplayTimeZoneIndex>-5</DisplayTimeZoneIndex>
<AdjustDisplayTimeZone>false</AdjustDisplayTimeZone>

<ContentDir>content</ContentDir>
<LogDir>logs</LogDir>
Expand Down
13 changes: 11 additions & 2 deletions source/DasBlog.Web.UI/Controllers/BlogPostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -443,10 +452,10 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
var commt = mapper.Map<NBR.Comment>(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);
Expand Down
8 changes: 4 additions & 4 deletions source/DasBlog.Web.UI/Mappers/ProfilePost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostViewModel, Entry>()
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
18 changes: 17 additions & 1 deletion source/DasBlog.Web.UI/Settings/DasBlogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -288,5 +295,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;
}
}
}

0 comments on commit 19b7de9

Please sign in to comment.