Custom Date/Time Formats per language

0
I'm wondering, is there a way from a custom Dijit widget to get the configured date/time format for the current user's language? Or is the only way to get this kind of thing from the locale set in the browser? I have an instance where a custom widget is displaying a different time format than a date picker, because the custom time format in the Modeler for the language is set to US time (ie 11:00 pm), but I am in Europe, so my browser locale is set to display time as 23:00, which is how it displays in the widget. Is there a way in the widget to see what custom time format is set for the current language, and then to use that to display in the same way within the widget?
asked
1 answers
2

Hi David

"configured date/time format for the current user's language"

User time zone is not directly connected to the language

Time zone information of the browser is used to determine date time value of object .get .set function will automatically adjust when the date and time attribute attribute in your model has enabled the "localized yes"

https://apidocs.mendix.com/7/client/mendix_lib_MxObject.html#get

https://docs.mendix.com/refguide/attributes#localize-only-attributes-of-type-date-and-time

Some usefull information could also be found in the session

mx.session.sessionData.locale = {firstDayOfWeek: 0, code: "en_US"}

https://apidocs.mendix.com/7/client/mx.session.html

With the domain model the and user ID you could find the configured time zone etc. (though this relation is only used in some exceptional cases where the browser does not provide timezone session information to the server

Date formatting strings could be done via

https://apidocs.mendix.com/7/client/mx.parser.html#.formatValue

Found 2 snippets in the Mendix client for epoch calculations

function localizeEpoch(e) {
	var t = new Date(Number(e));
	return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds()).getTime()
}

function delocalizeEpoch(e) {
	var t = new Date(Number(e));
	return Date.UTC(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), t.getMilliseconds())
}

 

Custom widget can have translatable string. Which could be configured per language. This way, each form can be set per language a date formatting. https://docs.mendix.com/refguide6/xml-reference-guide#translatablestring using the format Value functions.

I hope the information get you to your answer.

Cheers,

Andries

answered