Jump to content
The simFlight Network Forums

Set local time via SimConnect


Recommended Posts

Dear Pete,

 

this might not be the best forum for SimConnect questions, but this one might be an easy thing for you to get me some ideas on:

 

SimConnect offers:

  • CLOCK_SECONDS_ZERO
  • CLOCK_HOURS_SET
  • CLOCK_MINUTES_SET
  • ZULU_HOURS_SET
  • ZULU_MINUTES_SET
  • ZULU_DAY_SET
  • ZULU_YEAR_SET

So, no way to set a local year and day here. To set a local date and time by setting the time part with the CLOCK_xx events and the date part with the ZULU_xx events might end up in a wrong resulting local date/time with an offset of +/- one hour in case the new date has a different daylight saving time and therefore a different timezone bias.

 

Currently, I help myself in that I try to set the new time using the CLOCK_ and ZULU_ mix approach and afterwards I recheck the resulting local time against the wanted new local time. If they differ, I use the now updated "TIME ZONE OFFSET"  variable I receive from SimConnect to update the zulu time, causing the sim to reload the scenery a second time, which is of course not nice.

 

How are you dealing with this problem in your FSUIPC API? The whole problem seems to be around knowing the correct time zone bias for the current lat/lon and the desired date/time. I do not see how to get hold of this information other than asking some google web services and the like.

 

Any ideas would be very much appreciated.

 

Kind regards

 

Walter

Link to comment
Share on other sites

So, no way to set a local year and day here. To set a local date and time by setting the time part with the CLOCK_xx events and the date part with the ZULU_xx events might end up in a wrong resulting local date/time with an offset of +/- one hour in case the new date has a different daylight saving time and therefore a different timezone bias.

 

Currently, I help myself in that I try to set the new time using the CLOCK_ and ZULU_ mix approach and afterwards I recheck the resulting local time against the wanted new local time. If they differ, I use the now updated "TIME ZONE OFFSET"  variable I receive from SimConnect to update the zulu time, causing the sim to reload the scenery a second time, which is of course not nice.

 

How are you dealing with this problem in your FSUIPC API? The whole problem seems to be around knowing the correct time zone bias for the current lat/lon and the desired date/time. I do not see how to get hold of this information other than asking some google web services and the like.

 

I can only show you what appears to work using FSUIPC's Lua plug-in facilities. This code sets the current date and time correctly:

 

t = os.date("!*t")
minsdiff = ipc.readSW(0x246)
ipc.log("Date/Time Set: " .. os.date("!%c"))
lhour = t.hour - (minsdiff/60)
if (lhour < 0) then lhour = lhour + 24
elseif (lhour > 23) then lhour = lhour - 24 end
lmin = t.min - (minsdiff%60)
if (lmin < 0) then lmin = lmin + 60
elseif (lmin > 59) then lmin = lmin - 60 end


ipc.writeStruct(0x0238, "6UB", lhour, lmin, t.sec, t.hour, t.min, t.day,
"2UW", t.yday, t.year, 0x0246, "1SW", minsdiff)
 
Offsets used here are first 0238, 0239, 023A which makes:LOCAL TIME
023B, 023C which makes ZULU TIME 
023D  ZULU DAY OF MONTH
023E  ZULU DAY OF YEAR
0240  ZULU YEAR
0246  TIME ZONE OFFSET
 
So, what I think you need to do is set Zulu data and the time zone offset, at minimum. When setting it to other times (eg with my Boeing 737NG clocks) I read the current offset and write it back with the new time.
 
It took some experimentation to get this working.
 
Pete
Link to comment
Share on other sites

Dear Pete,

 

thank you so much for your input! But this confuses me. With

 

ipc.writeStruct( ... , 0x0246, "1SW", minsdiff)

 

you actually write the time zone offset (minsdiff) back? The corresponding SimConnect variable TIME ZONE OFFSET is documented to be not writeable, as well as offset 0x0246 as per your docs. Did your experiments prove that wrong? This might in fact do the trick, to force a particular time zone, even if it is a wrong one...

 

Kind regards

 

Walter

Edited by wweyers
Link to comment
Share on other sites

Dear Pete,

 

thank you so much for your input! But this confuses me. With

 

ipc.writeStruct( ... , 0x0246, "1SW", minsdiff)

 

you actually write the time zone offset (minsdiff) back? The corresponding SimConnect variable TIME ZONE OFFSET is documented to be not writeable, as well as offset 0x0246 as per your docs. Did your experiments prove that wrong? This might in fact do the trick, to force a particular time zone, even if it is a wrong one..

 

Sorry, I don't know what "did the trick". I just found that the code I gave worked and didn't think to check whether things I was writing actually did change things. Checking FSUIPC's internal table, yes, I agree, writing to 0246 probably doesn't do anything. Maybe just writing the correct Local and Zulu times does the trick. Or even just one or the other.

 

FSUIPC itself doesn't actually have anything writing time -- I use that Lua code from my Clocks and I believe the program "FSRealTime" does something very similar.

 

Probably you cannot force a time zone other than the one the aircraft is actually in, which makes sense in any case.

 

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.