I’ve got 2 customers where Xojo.Core.Date is crashing or giving a runtime error in Xojo 2019r3. Therefore, I had the idea to use the MBS plugin instead.
Old code:
[code]'make a time difference in seconds
dim theMinutes as Integer = Val(TimeOffset.Right(2))
dim RestOffset as String = Mid(TimeOffset, 1, TimeOffset.Length - 2)
dim theHours as Integer = Val(RestOffset.Right(2))
if TimeOffset.Left(1) = “-” then theHours = - theHours
'make a timezone
dim TimeDifference as Integer = theMinutes * 60 + (theHours * 60 * 60)
dim theTimeZone as new Xojo.Core.TimeZone(TimeDifference)
'the core date handles time zones automatically
dim CoreDate as new Xojo.Core.Date(theDate.Year, theDate.Month, theDate.Day, theDate.Hour, theDate.Minute, theDate.Second, theTimeZone)
if CoreDate = Nil then Return
'make a date with the local timezone
dim localDate as new Xojo.Core.Date(CoreDate.SecondsFrom1970, Xojo.Core.TimeZone.Current)
'make new date in the old framework
theDate = Nil
theDate = new Date
theDate.Year = localDate.Year
theDate.Month = localDate.Month
theDate.Day = localDate.Day
theDate.Hour = localDate.Hour
theDate.Minute = localDate.Minute
theDate.Second = localDate.Second
[/code]
New code:
[code]'make a time difference in seconds
dim theMinutes as Integer = Val(TimeOffset.Right(2))
dim RestOffset as String = Mid(TimeOffset, 1, TimeOffset.Length - 2)
dim theHours as Integer = Val(RestOffset.Right(2))
if TimeOffset.Left(1) = “-” then theHours = - theHours
'make a timezone
dim TimeDifference as Integer = theMinutes * 60 + (theHours * 60 * 60)
'make a date
dim theTimeZoneMBS as NSTimeZoneMBS = NSTimeZoneMBS.timeZoneForSecondsFromGMT(TimeDifference)
dim CoreDateMBS as new NSDateComponentsMBS
CoreDateMBS.year = theDate.Year
CoreDateMBS.month = theDate.Month
CoreDateMBS.day = theDate.Day
CoreDateMBS.Hour = theDate.Hour
CoreDateMBS.minute = theDate.Minute
CoreDateMBS.second = theDate.Second
CoreDateMBS.timeZone = theTimeZoneMBS
dim newDate as Date = CoreDateMBS.date[/code]
The last line of code doesn’t work. So I had to get back the result with a bit more code:
dim newDate as new Date
newDate.Year = CoreDateMBS.year
newDate.Month = CoreDateMBS.month
newDate.Day = CoreDateMBS.day
newDate.Hour = CoreDateMBS.hour
newDate.Minute = CoreDateMBS.minute
newDate.Second = CoreDateMBS.second
But I’m not sure if what I’m doing is correct here. This is the date I’m trying to parse:
original date string: Sat, 26 May 2018 10:18:36 +0900
The result in the debugger are:
theDate: 2018-05-26 03:18:36
newDate: 2018-05-26 10:18:36
theDate is the original result which I know is correct. newDate doesn’t seem to do anything with the timezone at all.
What am I doing wrong? Xojo 2019r3. High Sierra, MBS 19.5.