1function DateFormatter(id, format) { 2 var date = document.getElementById(id); 3 4 function checkValue(str, max) { 5 if (str.charAt(0) !== '0' || str == '00') { 6 var num = parseInt(str); 7 if (isNaN(num) || num <= 0 || num > max) num = 1; 8 str = num > parseInt(max.toString().charAt(0)) && num.toString().length == 1 ? '0' + num : num.toString(); 9 }; 10 return str; 11 }; 12 13 date.addEventListener('input', function (e) { 14 this.type = 'text'; 15 var input = this.value; 16 if (/\D\/$/.test(input)) input = input.substr(0, input.length - 3); 17 var values = input.split('/').map(function (v) { 18 return v.replace(/\D/g, '') 19 }); 20 if (format == "DD/MM/YYYY") { 21 if (values[0]) values[0] = checkValue(values[0], 31); 22 if (values[1]) values[1] = checkValue(values[1], 12); 23 } 24 else { 25 if (values[0]) values[0] = checkValue(values[0], 12); 26 if (values[1]) values[1] = checkValue(values[1], 31); 27 } 28 var output = values.map(function (v, i) { 29 return v.length == 2 && i < 2 ? v + ' / ' : v; 30 }); 31 this.value = output.join('').substr(0, 14); 32 }); 33 34 date.addEventListener('blur', function (e) { 35 this.type = 'text'; 36 var input = this.value; 37 var values = input.split('/').map(function (v, i) { 38 return v.replace(/\D/g, '') 39 }); 40 var output = ''; 41 42 if (values.length == 3) { 43 var year = values[2].length !== 4 ? parseInt(values[2]) + 2000 : parseInt(values[2]); 44 var month = "", day = ""; 45 if (format == "DD/MM/YYYY") { 46 day = parseInt(values[0]); 47 month = parseInt(values[1]) - 1; 48 } 49 else { 50 month = parseInt(values[0]) - 1; 51 day = parseInt(values[1]); 52 } 53 var d = new Date(year, month, day); 54 55 if (!isNaN(d)) { 56 var dates = [d.getMonth() + 1, d.getDate(), d.getFullYear()]; 57 output = moment(data.Record.Date).format(format); 58 }; 59 }; 60 this.value = output; 61 62 console.log(this.value); 63 }); 64} 65 66function toSystemDateFormat(date, timeFormat) { 67 if (typeof timeFormat != "undefined") { 68 if (timeFormat == "12hour") 69 return moment(date, $("#userDateFormat").val() + 'hh:mm A').format('YYYY/MM/DD hh:mm A'); 70 else 71 return moment(date, $("#userDateFormat").val() + 'HH:mm').format('YYYY/MM/DD HH:mm'); 72 } 73 else 74 return moment(date, $("#userDateFormat").val()).format('YYYY/MM/DD'); 75} 76 77function toLocalDateFormat(date, timeFormat) { 78 if (typeof timeFormat != "undefined") { 79 if (timeFormat == "12hour") 80 return moment(date).format($("#userDateFormat").val() + ' hh:mm A'); 81 else 82 return moment(date).format($("#userDateFormat").val() + ' HH:mm'); 83 } 84 else 85 return moment(date).format($("#userDateFormat").val()); 86}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.