SOLVED API Call to Change Date and Time Format

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
Does anyone know the API call used to change the date and time formats in TrueNAS Scale? You would assume it's the system.general API which seems to include everything related to the System Settings -> General page, however, it doesn't include the date or time formats settings.

Thanks,
Harry
 

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,471
There is a "timezone" parameter under system/general.

1640811832535.png


There is also a timezone_choices API that will give you the list of valid options.

1640811885047.png
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
There is a "timezone" parameter under system/general.

View attachment 51873

There is also a timezone_choices API that will give you the list of valid options.

View attachment 51874
Hi, that's the API call that I would have assumed would allow you to change the date and time format, however, if you look at the key/value pairs available, none of them actually set the date or time format. It's either missing from the documentation or another API call is used to change the date and time formats.

Thanks,
Harry

EDIT: Just to clarify, by date and time formats, I mean changing MM/DD/YYYY to DD/MM/YYYY for example, or changing from 24 hour time to AM/PM time.
 
Last edited:

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
So far I've been able to track the GUI process for changing the time format and date format to this function:

Which in turn ends up here:

However, this last call interacts with an observable object and registers an event with it which means the trail can't be followed via code because I don't know who is subscribed to this observable object and acts on the event. If anyone familiar with the TrueNAS Scale (or possibly Core) code would mind helping a bit here to see where the trail continues that would be much appreciated.

Thanks,
Harry
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
So after a bit more digging into the code I was able to track down the API call responsible. Apparently the date and time formats are user specific so the API call that sets them is user.set_attribute. However, it uses nested attributes which I'm having trouble specifying to the API call. I've posted a separate question about this issue here: https://www.truenas.com/community/t...-attribute-with-user-set_attribute-api.97806/

Thanks,
Harry
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
So it looks like there's more to the issue. Changing the timeFormat and dateFormat user attributes using the user.set_attribute API call doesn't actually result in the GUI using the updated setting in the GUI itself or in the settings page that shows the time and date format selection.

Thanks,
Harry
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
One last update. It looks like the time and date format are also stored in the browser's local storage which can't be reproduced via the API. That means in order for the changes made via the user.set_attribute API call to take effect, the browser cache for the server's domain/IP needs to be cleared including local storage.

Hope this helps someone out there.

Thanks,
Harry
 
Top