Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

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

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> [Logged] ScenEdit_SetTime(...) depends on locale? Page: [1]
Login
Message << Older Topic   Newer Topic >>
[Logged] ScenEdit_SetTime(...) depends on locale? - 1/31/2021 9:50:08 PM   
musurca

 

Posts: 112
Joined: 7/16/2020
Status: offline
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)

< Message edited by Rory Noonan -- 1/31/2021 11:57:24 PM >
Post #: 1
RE: ScenEdit_SetTime(...) depends on locale? - 1/31/2021 10:53:56 PM   
michaelm75au


Posts: 13472
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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"})





_____________________________

Michael

(in reply to musurca)
Post #: 2
RE: ScenEdit_SetTime(...) depends on locale? - 1/31/2021 11:23:04 PM   
WSBot

 

Posts: 182
Joined: 1/17/2021
Status: offline
0014378

(in reply to michaelm75au)
Post #: 3
RE: [Logged] ScenEdit_SetTime(...) depends on locale? - 2/1/2021 6:35:35 AM   
KnightHawk75

 

Posts: 1403
Joined: 11/15/2018
Status: offline
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.




< Message edited by KnightHawk75 -- 2/1/2021 8:38:13 PM >

(in reply to musurca)
Post #: 4
RE: [Logged] ScenEdit_SetTime(...) depends on locale? - 2/1/2021 8:37:28 PM   
musurca

 

Posts: 112
Joined: 7/16/2020
Status: offline
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())

(in reply to KnightHawk75)
Post #: 5
RE: [Logged] ScenEdit_SetTime(...) depends on locale? - 2/1/2021 8:48:23 PM   
KnightHawk75

 

Posts: 1403
Joined: 11/15/2018
Status: offline
Hopefully that was it, fingers crossed with you that it actually helped.


(in reply to musurca)
Post #: 6
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> [Logged] ScenEdit_SetTime(...) depends on locale? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.307