| OLD | NEW |
| (Empty) |
| 1 // | |
| 2 // Additional formats for ChartNew.js | |
| 3 // | |
| 4 // see https://github.com/FVANCOP/ChartNew.js/wiki/900_010_format.js | |
| 5 // | |
| 6 function fmtChartJSPerso(config, value, fmt) { | |
| 7 switch (fmt.split(/[\s,]+/)[0].toUpperCase()) { | |
| 8 case "DATE": | |
| 9 spltdt = fmt.replace(/,/g, " ").replace(/:/g, " ").split
(/[\s,]+/); | |
| 10 var options = new Array(); | |
| 11 for (var i = 1; i < spltdt.length; i++) { | |
| 12 switch (spltdt[i].toUpperCase()) { | |
| 13 case "WEEKDAY": | |
| 14 case "YEAR": | |
| 15 case "MONTH": | |
| 16 case "DAY": | |
| 17 options[spltdt[i]] = spltdt[i +
1]; | |
| 18 break; | |
| 19 default: | |
| 20 break; | |
| 21 } | |
| 22 } | |
| 23 return_value = value.toLocaleDateString(fmt.split(" ")[1
], options); | |
| 24 break; | |
| 25 case "FMTDATE": | |
| 26 spltdt = fmt.split(/[\s,]+/)[1].toUpperCase(); | |
| 27 return_value = spltdt.replaceArray(["DD", "MM", "YYYY",
"YY"], [value.getDate(), 1 + value.getMonth(), value.getFullYear(), value.getYea
r() % 100]); | |
| 28 break; | |
| 29 case "TIME": | |
| 30 return_value = value.toLocaleTimeString(); | |
| 31 break; | |
| 32 case "FMTTIME": | |
| 33 spltdt = fmt.split(/[\s,]+/)[1].toUpperCase(); | |
| 34 return_value = spltdt.replaceArray(["HH", "MM", "SS"], [ | |
| 35 value.getHours() < 10 ? '0' + value.getHours() :
value.getHours(), | |
| 36 value.getMinutes() < 10 ? '0' + value.getMinutes
() : value.getMinutes(), | |
| 37 value.getSeconds() < 10 ? '0' + value.getSeconds
() : value.getSeconds() | |
| 38 ]); | |
| 39 break; | |
| 40 case "FMTDATETIME": | |
| 41 spltdt = fmt.splitLimit(/[\s,]+/, 2)[1]; | |
| 42 return_value = spltdt.replaceArray(["DD", "MM", "YYYY",
"YY", "HH", "mm", "ss"], [ | |
| 43 value.getDate(), 1 + value.getMonth(), value.get
FullYear(), value.getYear() % 100, | |
| 44 value.getHours() < 10 ? '0' + value.getHours() :
value.getHours(), | |
| 45 value.getMinutes() < 10 ? '0' + value.getMinutes
() : value.getMinutes(), | |
| 46 value.getSeconds() < 10 ? '0' + value.getSeconds
() : value.getSeconds() | |
| 47 ]); | |
| 48 break; | |
| 49 default: | |
| 50 return_value = value; | |
| 51 break; | |
| 52 } | |
| 53 return (return_value); | |
| 54 } | |
| 55 String.prototype.replaceArray = function(find, replace) { | |
| 56 var replaceString = this; | |
| 57 var regex; | |
| 58 for (var i = 0; i < find.length; i++) { | |
| 59 regex = new RegExp(find[i], "g"); | |
| 60 replaceString = replaceString.replace(regex, replace[i]); | |
| 61 } | |
| 62 return replaceString; | |
| 63 }; | |
| 64 /** | |
| 65 * split a string into an array with limit entries | |
| 66 * The last entry contains the last part of the string, which can contain the se
parator) | |
| 67 * @param separator {string} string separator | |
| 68 * @param limit {integer} number of entries in the array | |
| 69 * @return array of separated strings | |
| 70 */ | |
| 71 String.prototype.splitLimit = function(separator, limit) { | |
| 72 var splitString = this; | |
| 73 var result = []; | |
| 74 var pos = splitString.search(separator); | |
| 75 if (pos < 0) return false; | |
| 76 result.push(splitString.substring(0, pos)); | |
| 77 result.push(splitString.substring(pos + 1)); | |
| 78 return result; | |
| 79 } | |
| OLD | NEW |