SVGHMI: prevent exception with date/time formating in sprintf.js if lang wasn't already set.
authorEdouard Tisserant
Wed, 25 May 2022 09:52:50 +0200
changeset 3486 0d5bb9038e5b
parent 3485 5f417d3c2d03
child 3487 efa45e7cb04b
SVGHMI: prevent exception with date/time formating in sprintf.js if lang wasn't already set.
svghmi/sprintf.js
--- a/svghmi/sprintf.js	Wed May 25 09:51:22 2022 +0200
+++ b/svghmi/sprintf.js	Wed May 25 09:52:50 2022 +0200
@@ -114,8 +114,14 @@
 
                         /* get lang from globals */
                         let lang = get_current_lang_code();
-                        arg = Date(arg).toLocaleString('en-US', options);
-                        
+                        let f;
+                        try{
+                            f = new Intl.DateTimeFormat(lang, options);
+                        } catch(e) {
+                            f = new Intl.DateTimeFormat('en-US', options);
+                        }
+                        arg = f.format(arg);
+
                         /*    
                             TODO: select with padding char
                                   a: absolute time and date (default)