Skip to content

Commit 50ce9f5

Browse files
committed
Fixing TimeZone on posts
1 parent 712caf1 commit 50ce9f5

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

branches/DNN_5/Components/Utilities/ForumUtils.vb

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -957,45 +957,13 @@ Namespace DotNetNuke.Modules.Forum.Utilities
957957
Dim displayCreatedDate As DateTime = value
958958

959959
Try
960-
'Dim _portalSettings As Portals.PortalSettings = Portals.PortalController.GetCurrentPortalSettings
961-
962-
''Post Time is entered into the database using getdate so if your SQL Server
963-
'Dim Posttime As DateTime = value
964-
''We need to know the servers timezone, we will use this information to convert the post time to a GMT time & date
965-
'Dim tz As System.TimeZone = System.TimeZone.CurrentTimeZone
966-
'Dim LocalTimeZone As Double = tz.GetUtcOffset(DateTime.Parse("00:00")).TotalMinutes
967-
968-
'we also want to take into account Daylight savings time, since this will affect the calculation as well. we will calculate daylight savings time based on when the post was made and
969-
'not based on what the current date and time is. i.e was the post made when daylight savings time was in affect or not.
970-
'If tz.IsDaylightSavingTime(Posttime) Then
971-
' LocalTimeZone -= tz.GetDaylightChanges(Posttime.Year).Delta.TotalMinutes
972-
'End If
973-
974-
'we need to invert the timezone, when the timezone is GMT-8 for example we need to add 8 hours
975-
'to get GMT and if the timezone is GMT+2 for Example we need to deduct 2 hours to get GMT
976-
'Dim InvertedTimeZone As Double = 0 - LocalTimeZone
977-
'Calculate the GMT time that the post was made, all calculations will be based on this
978-
'Dim GMTTime As DateTime = Posttime.AddMinutes(InvertedTimeZone)
979-
'the portal time zone will be a our fallback timezone, this will allow you to use the portals configured timezone if all else fails
980-
'Dim PortalTimeZone As Double = _portalSettings.TimeZoneOffset
981-
'calculate the portal time that the post was made at
982-
'Dim PortalTime As DateTime = GMTTime.AddMinutes(PortalTimeZone)
983-
''we need to get the forums configured timezone, if the forum is not configured to allow us to use the users timezone this is what we will use
984-
'Dim ForumTimeZone As Double = objConfig.TimeZone
985-
'calculate the forum time that the post was made, using the forums timezone.
986-
'Dim ForumTime As DateTime = GMTTime.AddMinutes(ForumTimeZone)
987-
' Set the time and reset later if per user is enabled
988-
'displayCreatedDate = PortalTime
989-
990-
Dim postTime As DateTime = displayCreatedDate
991-
Dim GMTTime As DateTime = System.TimeZoneInfo.ConvertTimeToUtc(displayCreatedDate, GetPortalSettings().TimeZone)
992-
993960
If HttpContext.Current.Request.IsAuthenticated Then
961+
Dim GMTTime As DateTime = displayCreatedDate.ToUniversalTime()
994962
Dim objUser As Users.UserInfo = Users.UserController.Instance.GetCurrentUserInfo
995-
'Dim UserTimeZone As Double = objUser.Profile.TimeZone
996-
' Dim UserTime As DateTime = GMTTime.AddMinutes(UserTimeZone)
997-
' displayCreatedDate = UserTime
998963
displayCreatedDate = objUser.LocalTime(GMTTime)
964+
Else
965+
displayCreatedDate = TimeZoneInfo.ConvertTime(displayCreatedDate.ToUniversalTime(), TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById(Portals.PortalController.GetPortalSetting("TimeZone", GetPortalSettings().PortalId, GetPortalSettings().TimeZone.Id)))
966+
999967
End If
1000968
Catch
1001969
' The added or subtracted value results in an un-representable DateTime. Possibly a problem with TimeZone values.

0 commit comments

Comments
 (0)