Skip to content

Commit 9dde524

Browse files
committed
Timezone and db provider refactorings
1 parent a81fd88 commit 9dde524

10 files changed

Lines changed: 1578 additions & 1564 deletions

File tree

BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ internal string NewPost(string blogId, string userName, string password, MWAPost
923923
}
924924

925925
post.DateCreated = sentPost.postDate == new DateTime() ?
926-
BlogSettings.Instance.ClientTime() : sentPost.postDate;
926+
BlogSettings.Instance.FromUtc() : sentPost.postDate;
927927

928928
post.Save();
929929

BlogEngine/BlogEngine.Core/BlogSettings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,9 @@ public enum CommentsBy
10861086
/// <summary>
10871087
/// Converts time passed from client into UTC server time
10881088
/// </summary>
1089-
/// <param name="localTime">Client time</param>
1089+
/// <param name="localTime">ToUtc</param>
10901090
/// <returns>Server time</returns>
1091-
public DateTime ServerTime(DateTime ? localTime = null)
1091+
public DateTime ToUtc(DateTime ? localTime = null)
10921092
{
10931093
if(localTime == null || localTime == new DateTime()) // no time sent in, use "now"
10941094
return DateTime.UtcNow;
@@ -1097,18 +1097,18 @@ public DateTime ServerTime(DateTime ? localTime = null)
10971097
}
10981098

10991099
/// <summary>
1100-
/// Converts time saved on the server to local user time
1100+
/// Converts time saved on the server from UTC to local user time offset by timezone
11011101
/// </summary>
1102-
/// <param name="serverTime">Server time</param>
1102+
/// <param name="serverTime">FromUtc</param>
11031103
/// <returns>Client time</returns>
1104-
public DateTime ClientTime(DateTime ? serverTime = null)
1104+
public DateTime FromUtc(DateTime ? serverTime = null)
11051105
{
11061106
if (serverTime == null || serverTime == new DateTime())
1107-
return DateTime.UtcNow;
1107+
serverTime = DateTime.UtcNow;
11081108

11091109
var zone = string.IsNullOrEmpty(Instance.TimeZoneId) ? "UTC" : Instance.TimeZoneId;
1110-
11111110
var tz = TimeZoneInfo.FindSystemTimeZoneById(zone);
1111+
serverTime = DateTime.SpecifyKind(serverTime.Value, DateTimeKind.Unspecified);
11121112

11131113
return TimeZoneInfo.ConvertTimeFromUtc(serverTime.Value, tz);
11141114
}

BlogEngine/BlogEngine.Core/Data/Models/Settings.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ public Settings() { }
6767
/// </summary>
6868
public string Culture { get; set; }
6969
/// <summary>
70-
/// Time zone
71-
/// </summary>
72-
public double Timezone { get; set; }
73-
/// <summary>
7470
/// Time zone id
7571
/// </summary>
7672
public string TimeZoneId { get; set; }

BlogEngine/BlogEngine.Core/Page.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public sealed class Page : BusinessBase<Page, Guid>, IPublishable
9999
public Page()
100100
{
101101
this.Id = Guid.NewGuid();
102-
this.DateCreated = BlogSettings.Instance.ClientTime();
102+
this.DateCreated = BlogSettings.Instance.FromUtc();
103103
}
104104

105105
static Page()

BlogEngine/BlogEngine.Core/Post.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ public bool IsVisible
671671
{
672672
if (this.IsDeleted)
673673
return false;
674-
else if (this.IsPublished && this.DateCreated <= BlogSettings.Instance.ClientTime())
674+
else if (this.IsPublished && this.DateCreated <= BlogSettings.Instance.FromUtc())
675675
return true;
676676
else if (Security.IsAuthorizedTo(Rights.ViewUnpublishedPosts))
677677
return true;
@@ -688,7 +688,7 @@ public bool IsVisibleToPublic
688688
get
689689
{
690690
return (this.IsPublished && this.IsDeleted == false &&
691-
this.DateCreated <= BlogSettings.Instance.ClientTime());
691+
this.DateCreated <= BlogSettings.Instance.FromUtc());
692692
}
693693
}
694694

0 commit comments

Comments
 (0)