The documentation for the recently added GMTOffset property in the old framework Date function lead me to believe that I should enter the number of hours I am away from GMT to get GMT time. Instead I get GMT time when I enter 0. I created a short program where I type the local time of day in TextField1 and the GMTOffset in TextField2. The TextChanged event calls this method
Private Sub Update()
dim d As new date
dim i as Integer = InStr(TextField1.text, ":")
if i > 1 then
d.Hour = TextField1.Text.Left(i-1).CDbl
d.Minute = TextField1.Text.Mid(i+1,2).CDbl
d.GMTOffset =TextField2.Text.CDbl
Label1.Text = d.ShortDate + " " + d.ShortTime
Else
Label1.Text = ""
end if
End Sub
This is a very nice feature as I don’t have to figure out what time zone I am in and whether or not it is daylight savings time to get Zulu time. I hope the docs will be changed to match how it works rather than the changing Xojo to work like the docs say. The name does seem to be a bit misleading however.
For clarity, GMTOffset is not new. You are supposed to set the GMTOffset before setting a time value, because changing the GMTOffset will change the time value. Here’s the documentation link for those who are interested in more information http://documentation.xojo.com/api/deprecated/date.html.GMTOffset
Not just time. Dates can also change if you are close enough to midnight.
When you set it depends on what you need though. If the date you are constructing is already gmt, set it first. If youre converting the to gmt, change it after setting the date.
GMTOffset has been there for a long time as a property on the old format Date
At least since 2009r5 (maybe before that)
I just checked those docs and its there
I think the docs need to make this clearer. I got bitten by this recently, although stepping through made it clearer what was going on, especially as the one example has the GMTOffset being done last.
[quote=439328:@Norman Palardy]adding to the individual components of Date is fraught with peril
its sensitive to the order you add to day month year etc[/quote]
Hmm, even more reason for detailed docs, including what happens if, having set the month to Feb, you set the day to >29 or the day=29 when it’s not a leap year. And so on.