5 of 5 people found this helpful
When you created your Alpha and Omega AFTime objects, did you create them from DateTime objects in the constructor? If so, note that unless you specify the DateTimeKind of the DateTime struct, the default is DateTimeKind.Utc.
From your results I'm going to guess that your local timezone is UTC+3, and that you didn't specify DateTimeKind.Local when you initialised your DateTime structs in the AFTime constructors. Can you please confirm?
1 of 1 people found this helpful
John Messinger hit the nail on the head with his answer. The cause of your problem is you think your input DateTime values are in Local time, but in reality they are treated with Kind=Unspecified. When passing the an Unspecified DateTime to AFTime or AFTimeRange, the time is then assumed to be Utc. You may see this without touching AF objects first. Try:
Dim startTime As DateTime = Omega.LocalTime
Dim endTime As DateTime = Alpha.LocalTime.AddHours(23).AddMinutes(59).AddSeconds(59)
And you will discover your times are still 3 hours off. To learn more about the Why, see this blog on AFTime Constructor - Determining UTC versus Local Time.
One last thing, there may be little reason to specify 1 full day minus 1 second. You could simplify things with:
Dim endTime As DateTime = Alpha.LocalTime.AddHours(24)
But keep in mind that during Spring DST transition, the day has 25 hours and during Fall DST transition, the day has 23 hours. So you may consider:
Dim endTime As DateTime = Alpha.LocalTime.AddDays(1)
2 of 2 people found this helpful
In addition to what John said, you could add toString() to the end of your OmegaTime and AlphaTime and that should give you the expected results since AF always treats strings as local, unless the string contains timezone info in it. I would recommend though, specifying the kind.
Could you please provide more info on what Omega and Alpha are? I see you are asking for the LocalTime and that seems to me that it may be a remote server time, right? If you want to get the remote server local time you have to do a little bit different:
var dateTimeAsLocal = server.ServerTimeZone.ToLocalTime(server.ServerTime);
Where server is a PISystem object.
Also, why do you need the .LocalTime.AddHours(0).AddMinutes(0).AddSeconds(0)? It does absolutely nothing.