[Logged] ScenEdit_SetTime(...) depends on locale? (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support



Message


musurca -> [Logged] ScenEdit_SetTime(...) depends on locale? (1/31/2021 9:50:08 PM)

Hi -- the Command Lua documentation for the function ScenEdit_SetTime() states that it takes an argument, new_time, which is "the desired UTC datetime as a table in MM:DD:YYYY & HH:MM:SS or MM.DD.YYYY & HH.MM.SS format."

So as I understand it, calling

ScenEdit_SetTime({Date="06.01.1985", Time="14.00.00"})

should always set the scenario date to June 1st, 1985 1400hrs UTC, no matter what your computer's preferred date locale format is.

However, one of the users of IKE is having an issue where calling ScenEdit_SetTime() with the exact same Date parameter makes the scenario date become January 6th, 1985. In other words, the month and the day are transposed. This would imply that the argument to ScenEdit_SetTime() is actually locale-dependent, and should follow the order of the preferred date format for the user's locale. (As discoverable by the output of os.date("%x").)

My question is: is the documentation correct that new_time should always be in the form "MM.DD.YYYY", or is it actually locale dependent? And is that WAD?

Thanks!
(hard to provide a .save file for this since it changes based on locale—sorry)




michaelm75au -> RE: ScenEdit_SetTime(...) depends on locale? (1/31/2021 10:53:56 PM)

The SE code is using the format MM.DD.YYYY regardless of locale.
I have tried this changing the region but it comes out the same 1 June 1985

German_Germany.1252
print(os.setlocale(""))
ScenEdit_SetTime({Date="06.01.1985", Time="14.00.00"})

English_Australia.1252
print(os.setlocale(""))
ScenEdit_SetTime({Date="06.01.1985", Time="14.00.00"})







WSBot -> RE: ScenEdit_SetTime(...) depends on locale? (1/31/2021 11:23:04 PM)

0014378




KnightHawk75 -> RE: [Logged] ScenEdit_SetTime(...) depends on locale? (2/1/2021 6:35:35 AM)

Could be I'm miss reading the question\problem but.. I get the same results as michaelm when changing to German, or Korean,etc. Always got 486482400 as the time after the change.

If you are calculating the time though, and it's not just hard coded like the example given, however in-game before feeding it to SetTime(), based on using os.date, MAKE SURE if you want UTC and only UTC you prefix your format string with !, it tell Lua to ignore system locality\region settings offsets.

For example (where newtimeUnixSeconds is the time you want):
local adjustedUTCDateTime = os.date("!%m:%d:%Y %H:%M:%S",newtimeUnixSeconds)
local adjustedUTCDate = os.date("!%m:%d:%Y",newtimeUnixSeconds)
local adjustedUTCTime = os.date("!%H:%M:%S",newtimeUnixSeconds)
ScenEdit_SetTime({Date=adjustedUTCDate,Time=adjustedUTCTime})

I definitely had some issues when not doing that, especially when trying to get the correct UTC time to set the scene to for a desired actual "local" time in-game in a time zone.






musurca -> RE: [Logged] ScenEdit_SetTime(...) depends on locale? (2/1/2021 8:37:28 PM)

quote:

I get the same results as michaelm when changing to German, or Korean,etc.


Same here, actually -- I'm having a hard time reproducing it, but the person reporting it sent me a .save file where this had occurred, so thought it was worth mentioning.

quote:

however in-game before feeding it to SetTime(), based on using os.date, MAKE SURE if you want UTC and only UTC you prefix your format string with !, it tell Lua to ignore system locality\region settings.


Ah-ha! Thanks, I wasn't aware of that syntax. I've gone ahead and switched to that. Fingers crossed that this will solve the issue.

If anyone else is experiencing this with my use case-- resetting the scenario time to the start time--this is the code I'm using, adapted from KnightHawk75's suggestion:

function StartTimeToUTC()
    local date_str = os.date("!%m.%d.%Y", VP_GetScenario().StartTimeNum)
    local time_str = os.date("!%H.%M.%S", VP_GetScenario().StartTimeNum)
    return {Date=date_str, Time=time_str}
end

ScenEdit_SetTime(StartTimeToUTC())




KnightHawk75 -> RE: [Logged] ScenEdit_SetTime(...) depends on locale? (2/1/2021 8:48:23 PM)

Hopefully that was it, fingers crossed with you that it actually helped. [:)]





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.71875