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
Label1.Text = d.ShortDate + " " + d.ShortTime
Label1.Text = ""
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.
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
What I understand from:
is that if I don’t create a date with GMTOffset, then I will get the GMTOffset of my computer time (-5.0 hrs)
So, if I change the new date object to GMT by setting that as 0, then the time will change to +5 hours, bringing the time to GMT.
I don’t know what else the docs can say to make that clearer.
Edit: something like this
Dim d As New Date // time 02:00:00
Dim g As Double = d.GMTOffset // g = -5.0
d.GMTOffset = 0 // time 07:00:00
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.
adding to the individual components of Date is fraught with peril
its sensitive to the order you add to day month year etc
[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.