svghmi/sprintf.js
changeset 3451 302efcf746e0
parent 3360 746e3e3f6537
child 3468 3725487d5468
equal deleted inserted replaced
3441:710eec6eb01c 3451:302efcf746e0
    13         numeric_arg: /[bcdiefguxX]/,
    13         numeric_arg: /[bcdiefguxX]/,
    14         json: /[j]/,
    14         json: /[j]/,
    15         not_json: /[^j]/,
    15         not_json: /[^j]/,
    16         text: /^[^\x25]+/,
    16         text: /^[^\x25]+/,
    17         modulo: /^\x25{2}/,
    17         modulo: /^\x25{2}/,
    18         placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
    18         placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxXD])/,
    19         key: /^([a-z_][a-z_\d]*)/i,
    19         key: /^([a-z_][a-z_\d]*)/i,
    20         key_access: /^\.([a-z_][a-z_\d]*)/i,
    20         key_access: /^\.([a-z_][a-z_\d]*)/i,
    21         index_access: /^\[(\d+)\]/,
    21         index_access: /^\[(\d+)\]/,
    22         sign: /^[+-]/
    22         sign: /^[+-]/
    23     }
    23     }
    75                         arg = String.fromCharCode(parseInt(arg, 10))
    75                         arg = String.fromCharCode(parseInt(arg, 10))
    76                         break
    76                         break
    77                     case 'd':
    77                     case 'd':
    78                     case 'i':
    78                     case 'i':
    79                         arg = parseInt(arg, 10)
    79                         arg = parseInt(arg, 10)
       
    80                         break
       
    81                     case 'D':
       
    82                         /*  
       
    83 
       
    84                             select date format with width
       
    85                             select time format with precision
       
    86                             %D  => 13:31 AM (default)
       
    87                             %1D  => 13:31 AM
       
    88                             %.1D  => 07/07/20
       
    89                             %1.1D  => 07/07/20, 13:31 AM
       
    90                             %1.2D  => 07/07/20, 13:31:55 AM
       
    91                             %2.2D  => May 5, 2022, 9:29:16 AM
       
    92                             %3.3D  => May 5, 2022 at 9:28:16 AM GMT+2
       
    93                             %4.4D  => Thursday, May 5, 2022 at 9:26:59 AM Central European Summer Time
       
    94 
       
    95                             see meaning of DateTimeFormat's options "datestyle" and "timestyle" in MDN 
       
    96                         */
       
    97 
       
    98                         let [datestyle, timestyle] = [ph.width, ph.precision].map(val => {
       
    99                             1: "short",
       
   100                             2: "medium",
       
   101                             3: "long",
       
   102                             4: "full"
       
   103                         }[val]);
       
   104 
       
   105                         if(timestyle === undefined && datestyle === undefined){
       
   106                             timestyle = "short";
       
   107                         }
       
   108 
       
   109                         let options = {
       
   110                             dateStyle: datestyle,
       
   111                             timeStyle: timestyle,
       
   112                             hour12: false
       
   113                         }
       
   114 
       
   115                         /* get lang from globals */
       
   116                         let lang = get_current_lang_code();
       
   117                         arg = Date(arg).toLocaleString('en-US', options);
       
   118                         
       
   119                         /*    
       
   120                             TODO: select with padding char
       
   121                                   a: absolute time and date (default)
       
   122                                   r: relative time
       
   123                         */
       
   124 
    80                         break
   125                         break
    81                     case 'j':
   126                     case 'j':
    82                         arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
   127                         arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
    83                         break
   128                         break
    84                     case 'e':
   129                     case 'e':