|
|
|
@ -2,7 +2,7 @@ import {each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseD
|
|
|
|
|
import {replaceAll} from "./string"; |
|
|
|
|
import {getFullDayName, getMonthName, getTimezone} from "./date"; |
|
|
|
|
|
|
|
|
|
var _global; |
|
|
|
|
let _global; |
|
|
|
|
if (typeof window !== "undefined") { |
|
|
|
|
_global = window; |
|
|
|
|
} else if (typeof global !== "undefined") { |
|
|
|
@ -47,12 +47,12 @@ function _eFormat(text, fmt) {
|
|
|
|
|
* @returns {*} |
|
|
|
|
*/ |
|
|
|
|
function eFormat(num, format) { |
|
|
|
|
var neg = num < 0 ? (num *= -1, "-") : "", |
|
|
|
|
let neg = num < 0 ? (num *= -1, "-") : "", |
|
|
|
|
magnitudeNeg = ""; |
|
|
|
|
|
|
|
|
|
var funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1
|
|
|
|
|
const funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1
|
|
|
|
|
// 数量级
|
|
|
|
|
var magnitude = Math[funcName](Math.log(num) / Math.log(10)); |
|
|
|
|
let magnitude = Math[funcName](Math.log(num) / Math.log(10)); |
|
|
|
|
|
|
|
|
|
if (!isFinite(magnitude)) { |
|
|
|
|
return format.replace(/#/ig, "").replace(/\.e/ig, "E"); |
|
|
|
@ -67,15 +67,15 @@ function _eFormat(text, fmt) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级
|
|
|
|
|
var integerLen = getInteger(magnitude, format); |
|
|
|
|
const integerLen = getInteger(magnitude, format); |
|
|
|
|
integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); |
|
|
|
|
|
|
|
|
|
magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); |
|
|
|
|
|
|
|
|
|
// 获取科学计数法精确到的位数
|
|
|
|
|
var precision = getPrecision(format); |
|
|
|
|
const precision = getPrecision(format); |
|
|
|
|
// 判断num经过四舍五入之后是否有进位
|
|
|
|
|
var isValueCarry = isValueCarried(num); |
|
|
|
|
const isValueCarry = isValueCarried(num); |
|
|
|
|
|
|
|
|
|
num *= Math.pow(10, precision); |
|
|
|
|
num = Math.round(num); |
|
|
|
@ -104,8 +104,8 @@ function _eFormat(text, fmt) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了
|
|
|
|
|
var isAllZero = true; |
|
|
|
|
for (var i = 0, len = num.length; i < len; i++) { |
|
|
|
|
let isAllZero = true; |
|
|
|
|
for (let i = 0, len = num.length; i < len; i++) { |
|
|
|
|
if (!isAllZero) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -121,7 +121,7 @@ function _eFormat(text, fmt) {
|
|
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
var arr = format.split(/e/ig)[0].split("."); |
|
|
|
|
const arr = format.split(/e/ig)[0].split("."); |
|
|
|
|
|
|
|
|
|
return arr.length > 1 ? arr[1].length : 0; |
|
|
|
|
} |
|
|
|
@ -134,8 +134,8 @@ function _eFormat(text, fmt) {
|
|
|
|
|
} |
|
|
|
|
// return format.split(/e/ig)[0].split(".")[0].length;
|
|
|
|
|
|
|
|
|
|
var formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; |
|
|
|
|
var valueLeftLen = 0; |
|
|
|
|
let formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; |
|
|
|
|
let valueLeftLen = 0; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
|
f = formatLeft.charAt(i); |
|
|
|
@ -150,7 +150,7 @@ function _eFormat(text, fmt) {
|
|
|
|
|
|
|
|
|
|
// 判断num通过round函数之后是否有进位
|
|
|
|
|
function isValueCarried(num) { |
|
|
|
|
var roundNum = Math.round(num); |
|
|
|
|
let roundNum = Math.round(num); |
|
|
|
|
num = (num + "").split(".")[0]; |
|
|
|
|
roundNum = (roundNum + "").split(".")[0]; |
|
|
|
|
return num.length !== roundNum.length; |
|
|
|
@ -160,13 +160,13 @@ function _eFormat(text, fmt) {
|
|
|
|
|
//'#.##'之类的格式处理 1.324e-18 这种的科学数字
|
|
|
|
|
function _dealNumberPrecision(text, fright) { |
|
|
|
|
if (/[eE]/.test(text)) { |
|
|
|
|
var precision = 0, i = 0, ch; |
|
|
|
|
let precision = 0, i = 0, ch; |
|
|
|
|
|
|
|
|
|
if (/[%‰]$/.test(fright)) { |
|
|
|
|
precision = /[%]$/.test(fright) ? 2 : 3; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (var len = fright.length; i < len; i++) { |
|
|
|
|
for (let len = fright.length; i < len; i++) { |
|
|
|
|
if ((ch = fright.charAt(i)) == "0" || ch == "#") { |
|
|
|
|
precision++; |
|
|
|
|
} |
|
|
|
@ -181,7 +181,7 @@ function _dealNumberPrecision(text, fright) {
|
|
|
|
|
* 数字格式 |
|
|
|
|
*/ |
|
|
|
|
function _numberFormat(text, format) { |
|
|
|
|
var text = text + ""; |
|
|
|
|
text = text + ""; |
|
|
|
|
|
|
|
|
|
//在调用数字格式的时候如果text里没有任何数字则不处理
|
|
|
|
|
if (!(/[0-9]/.test(text)) || !format) { |
|
|
|
@ -189,7 +189,7 @@ function _numberFormat(text, format) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 数字格式,区分正负数
|
|
|
|
|
var numMod = format.indexOf(";"); |
|
|
|
|
const numMod = format.indexOf(";"); |
|
|
|
|
if (numMod > -1) { |
|
|
|
|
if (text >= 0) { |
|
|
|
|
return _numberFormat(text + "", format.substring(0, numMod)); |
|
|
|
@ -203,19 +203,19 @@ function _numberFormat(text, format) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; |
|
|
|
|
const fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; |
|
|
|
|
text = _dealNumberPrecision(text, fright); |
|
|
|
|
var tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; |
|
|
|
|
let tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; |
|
|
|
|
|
|
|
|
|
// 百分比,千分比的小数点移位处理
|
|
|
|
|
if (/[%‰]$/.test(format)) { |
|
|
|
|
var paddingZero = /[%]$/.test(format) ? "00" : "000"; |
|
|
|
|
let paddingZero = /[%]$/.test(format) ? "00" : "000"; |
|
|
|
|
tright += paddingZero; |
|
|
|
|
tleft += tright.substring(0, paddingZero.length); |
|
|
|
|
tleft = tleft.replace(/^0+/gi, ""); |
|
|
|
|
tright = tright.substring(paddingZero.length).replace(/0+$/gi, ""); |
|
|
|
|
} |
|
|
|
|
var right = _dealWithRight(tright, fright); |
|
|
|
|
let right = _dealWithRight(tright, fright); |
|
|
|
|
if (right.leftPlus) { |
|
|
|
|
// 小数点后有进位
|
|
|
|
|
tleft = parseInt(tleft) + 1 + ""; |
|
|
|
@ -223,7 +223,7 @@ function _numberFormat(text, format) {
|
|
|
|
|
tleft = isNaN(tleft) ? "1" : tleft; |
|
|
|
|
} |
|
|
|
|
right = right.num; |
|
|
|
|
var left = _dealWithLeft(tleft, fleft); |
|
|
|
|
let left = _dealWithLeft(tleft, fleft); |
|
|
|
|
if (!(/[0-9]/.test(left))) { |
|
|
|
|
left = left + "0"; |
|
|
|
|
} |
|
|
|
@ -242,10 +242,10 @@ function _numberFormat(text, format) {
|
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
function _dealWithRight(tright, fright) { |
|
|
|
|
var right = "", j = 0, i = 0; |
|
|
|
|
for (var len = fright.length; i < len; i++) { |
|
|
|
|
var ch = fright.charAt(i); |
|
|
|
|
var c = tright.charAt(j); |
|
|
|
|
let right = "", j = 0, i = 0; |
|
|
|
|
for (let len = fright.length; i < len; i++) { |
|
|
|
|
const ch = fright.charAt(i); |
|
|
|
|
let c = tright.charAt(j); |
|
|
|
|
switch (ch) { |
|
|
|
|
case "0": |
|
|
|
|
if (isEmpty(c)) { |
|
|
|
@ -263,16 +263,16 @@ function _dealWithRight(tright, fright) {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
var rll = tright.substring(j); |
|
|
|
|
var result = {}; |
|
|
|
|
const rll = tright.substring(j); |
|
|
|
|
const result = {}; |
|
|
|
|
if (!isEmpty(rll) && rll.charAt(0) > 4) { |
|
|
|
|
// 有多余字符,需要四舍五入
|
|
|
|
|
result.leftPlus = true; |
|
|
|
|
var numReg = right.match(/^[0-9]+/); |
|
|
|
|
const numReg = right.match(/^[0-9]+/); |
|
|
|
|
if (numReg) { |
|
|
|
|
var num = numReg[0]; |
|
|
|
|
var orilen = num.length; |
|
|
|
|
var newnum = parseInt(num) + 1 + ""; |
|
|
|
|
const num = numReg[0]; |
|
|
|
|
const orilen = num.length; |
|
|
|
|
let newnum = parseInt(num) + 1 + ""; |
|
|
|
|
// 进位到整数部分
|
|
|
|
|
if (newnum.length > orilen) { |
|
|
|
|
newnum = newnum.substring(1); |
|
|
|
@ -295,13 +295,14 @@ function _dealWithRight(tright, fright) {
|
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
function _dealWithLeft(tleft, fleft) { |
|
|
|
|
var left = ""; |
|
|
|
|
var j = tleft.length - 1; |
|
|
|
|
var combo = -1, last = -1; |
|
|
|
|
var i = fleft.length - 1; |
|
|
|
|
let newstr; |
|
|
|
|
let left = ""; |
|
|
|
|
let j = tleft.length - 1; |
|
|
|
|
let combo = -1, last = -1; |
|
|
|
|
let i = fleft.length - 1; |
|
|
|
|
for (; i >= 0; i--) { |
|
|
|
|
var ch = fleft.charAt(i); |
|
|
|
|
var c = tleft.charAt(j); |
|
|
|
|
const ch = fleft.charAt(i); |
|
|
|
|
let c = tleft.charAt(j); |
|
|
|
|
switch (ch) { |
|
|
|
|
case "0": |
|
|
|
|
if (isEmpty(c)) { |
|
|
|
@ -319,7 +320,7 @@ function _dealWithLeft(tleft, fleft) {
|
|
|
|
|
case ",": |
|
|
|
|
if (!isEmpty(c)) { |
|
|
|
|
// 计算一个,分隔区间的长度
|
|
|
|
|
var com = fleft.match(/,[#0]+/); |
|
|
|
|
const com = fleft.match(/,[#0]+/); |
|
|
|
|
if (com) { |
|
|
|
|
combo = com[0].length - 1; |
|
|
|
|
} |
|
|
|
@ -333,19 +334,20 @@ function _dealWithLeft(tleft, fleft) {
|
|
|
|
|
} |
|
|
|
|
if (last > -1) { |
|
|
|
|
// 处理剩余字符
|
|
|
|
|
var tll = tleft.substring(0, j + 1); |
|
|
|
|
const tll = tleft.substring(0, j + 1); |
|
|
|
|
left = left.substring(0, last) + tll + left.substring(last); |
|
|
|
|
} |
|
|
|
|
if (combo > 0) { |
|
|
|
|
// 处理,分隔区间
|
|
|
|
|
var res = left.match(/[0-9]+,/); |
|
|
|
|
let res = left.match(/[0-9]+,/); |
|
|
|
|
if (res) { |
|
|
|
|
res = res[0]; |
|
|
|
|
var newstr = "", n = res.length - 1 - combo; |
|
|
|
|
newstr = ""; |
|
|
|
|
let n = res.length - 1 - combo; |
|
|
|
|
for (; n >= 0; n = n - combo) { |
|
|
|
|
newstr = res.substring(n, combo) + "," + newstr; |
|
|
|
|
} |
|
|
|
|
var lres = res.substring(0, n + combo); |
|
|
|
|
const lres = res.substring(0, n + combo); |
|
|
|
|
if (!isEmpty(lres)) { |
|
|
|
|
newstr = lres + "," + newstr; |
|
|
|
|
} |
|
|
|
@ -361,9 +363,9 @@ export const cjkEncode = function (text) {
|
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var newText = ""; |
|
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
|
var code = text.charCodeAt(i); |
|
|
|
|
let newText = ""; |
|
|
|
|
for (let i = 0; i < text.length; i++) { |
|
|
|
|
const code = text.charCodeAt(i); |
|
|
|
|
if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]".
|
|
|
|
|
newText += "[" + code.toString(16) + "]"; |
|
|
|
|
} else { |
|
|
|
@ -386,17 +388,17 @@ export const cjkDecode = function (text) {
|
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
// 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
|
|
|
|
|
if (!isNaN(text) || text.indexOf("[") == -1) { |
|
|
|
|
if (!isNaN(text) || text.indexOf("[") === -1) { |
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var newText = ""; |
|
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
|
var ch = text.charAt(i); |
|
|
|
|
if (ch == "[") { |
|
|
|
|
var rightIdx = text.indexOf("]", i + 1); |
|
|
|
|
let newText = ""; |
|
|
|
|
for (let i = 0; i < text.length; i++) { |
|
|
|
|
let ch = text.charAt(i); |
|
|
|
|
if (ch === "[") { |
|
|
|
|
const rightIdx = text.indexOf("]", i + 1); |
|
|
|
|
if (rightIdx > i + 1) { |
|
|
|
|
var subText = text.substring(i + 1, rightIdx); |
|
|
|
|
let subText = text.substring(i + 1, rightIdx); |
|
|
|
|
// james:主要是考虑[CDATA[]]这样的值的出现
|
|
|
|
|
if (subText.length > 0) { |
|
|
|
|
ch = String.fromCharCode(eval("0x" + subText)); |
|
|
|
@ -419,7 +421,7 @@ const SPECIAL_TAGS = {
|
|
|
|
|
"<": "<", |
|
|
|
|
">": ">", |
|
|
|
|
"\x20": " ", |
|
|
|
|
"\n": " " |
|
|
|
|
"\n": " ", |
|
|
|
|
}; |
|
|
|
|
export const htmlEncode = function (text) { |
|
|
|
|
return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
@ -450,7 +452,7 @@ export const htmlDecode = function (text) {
|
|
|
|
|
|
|
|
|
|
export const cjkEncodeDO = function (o) { |
|
|
|
|
if (isPlainObject(o)) { |
|
|
|
|
var result = {}; |
|
|
|
|
let result = {}; |
|
|
|
|
each(o, function (v, k) { |
|
|
|
|
if (!(typeof v === "string")) { |
|
|
|
|
v = jsonEncode(v); |
|
|
|
@ -466,25 +468,25 @@ export const cjkEncodeDO = function (o) {
|
|
|
|
|
|
|
|
|
|
export const jsonEncode = function (o) { |
|
|
|
|
// james:这个Encode是抄的EXT的
|
|
|
|
|
var useHasOwn = !!{}.hasOwnProperty; |
|
|
|
|
let useHasOwn = !!{}.hasOwnProperty; |
|
|
|
|
|
|
|
|
|
// crashes Safari in some instances
|
|
|
|
|
// var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
|
|
|
|
|
|
|
|
|
|
var m = { |
|
|
|
|
let m = { |
|
|
|
|
"\b": "\\b", |
|
|
|
|
"\t": "\\t", |
|
|
|
|
"\n": "\\n", |
|
|
|
|
"\f": "\\f", |
|
|
|
|
"\r": "\\r", |
|
|
|
|
"\"": "\\\"", |
|
|
|
|
"\\": "\\\\" |
|
|
|
|
"\\": "\\\\", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var encodeString = function (s) { |
|
|
|
|
let encodeString = function (s) { |
|
|
|
|
if (/["\\\x00-\x1f]/.test(s)) { |
|
|
|
|
return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { |
|
|
|
|
var c = m[b]; |
|
|
|
|
let c = m[b]; |
|
|
|
|
if (c) { |
|
|
|
|
return c; |
|
|
|
|
} |
|
|
|
@ -497,8 +499,8 @@ export const jsonEncode = function (o) {
|
|
|
|
|
return "\"" + s + "\""; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var encodeArray = function (o) { |
|
|
|
|
var a = ["["], b, i, l = o.length, v; |
|
|
|
|
let encodeArray = function (o) { |
|
|
|
|
let a = ["["], b, i, l = o.length, v; |
|
|
|
|
for (i = 0; i < l; i += 1) { |
|
|
|
|
v = o[i]; |
|
|
|
|
switch (typeof v) { |
|
|
|
@ -528,7 +530,7 @@ export const jsonEncode = function (o) {
|
|
|
|
|
* 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 |
|
|
|
|
*/ |
|
|
|
|
return jsonEncode({ |
|
|
|
|
__time__: o.getTime() |
|
|
|
|
__time__: o.getTime(), |
|
|
|
|
}); |
|
|
|
|
} else if (typeof o === "string") { |
|
|
|
|
return encodeString(o); |
|
|
|
@ -539,7 +541,7 @@ export const jsonEncode = function (o) {
|
|
|
|
|
} else if (isFunction(o)) { |
|
|
|
|
return String(o); |
|
|
|
|
} |
|
|
|
|
var a = ["{"], b, i, v; |
|
|
|
|
let a = ["{"], b, i, v; |
|
|
|
|
for (i in o) { |
|
|
|
|
if (!useHasOwn || o.hasOwnProperty(i)) { |
|
|
|
|
v = o[i]; |
|
|
|
@ -564,8 +566,9 @@ export const jsonEncode = function (o) {
|
|
|
|
|
|
|
|
|
|
export const jsonDecode = function (text) { |
|
|
|
|
|
|
|
|
|
let jo; |
|
|
|
|
try { |
|
|
|
|
var jo = JSON.parse(text); |
|
|
|
|
jo = JSON.parse(text); |
|
|
|
|
if (jo == null) { |
|
|
|
|
jo = {}; |
|
|
|
|
} |
|
|
|
@ -601,8 +604,8 @@ export const jsonDecode = function (text) {
|
|
|
|
|
if (o && o.__time__ != null) { |
|
|
|
|
return new Date(o.__time__); |
|
|
|
|
} |
|
|
|
|
for (var a in o) { |
|
|
|
|
if (o[a] == o || typeof o[a] === "object" || isFunction(o[a])) { |
|
|
|
|
for (const a in o) { |
|
|
|
|
if (o[a] === o || typeof o[a] === "object" || isFunction(o[a])) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
o[a] = parse(o[a]); |
|
|
|
@ -641,7 +644,7 @@ export const encodeURIComponent = function (url) {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const decodeURIComponent = function (url) { |
|
|
|
|
var reserveSpecialCharsMap = {}; |
|
|
|
|
const reserveSpecialCharsMap = {}; |
|
|
|
|
each(BI.specialCharsMap, function (initialChar, encodeChar) { |
|
|
|
|
reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; |
|
|
|
|
}); |
|
|
|
@ -657,7 +660,7 @@ export const contentFormat = function (cv, fmt) {
|
|
|
|
|
// 原值为空,返回空字符
|
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
var text = cv.toString(); |
|
|
|
|
let text = cv.toString(); |
|
|
|
|
if (isEmpty(fmt)) { |
|
|
|
|
// 格式为空,返回原字符
|
|
|
|
|
return text; |
|
|
|
@ -677,7 +680,7 @@ export const contentFormat = function (cv, fmt) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!isInvalidDate(cv) && !isNull(cv)) { |
|
|
|
|
var needTrim = fmt.match(/^DT/); |
|
|
|
|
const needTrim = fmt.match(/^DT/); |
|
|
|
|
text = date2Str(cv, fmt.substring(needTrim ? 2 : 1)); |
|
|
|
|
} |
|
|
|
|
} else if (fmt.match(/E/)) { |
|
|
|
@ -749,7 +752,7 @@ export const str2Date = function (str, format) {
|
|
|
|
|
if (typeof str != "string" || typeof format != "string") { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
var fmt = parseFmt(format); |
|
|
|
|
const fmt = parseFmt(format); |
|
|
|
|
return parseDateTime(str, fmt); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -767,16 +770,16 @@ export const date2Str = function (date, format) {
|
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
// O(len(format))
|
|
|
|
|
var len = format.length, result = ""; |
|
|
|
|
let len = format.length, result = ""; |
|
|
|
|
if (len > 0) { |
|
|
|
|
var flagch = format.charAt(0), start = 0, str = flagch; |
|
|
|
|
for (var i = 1; i < len; i++) { |
|
|
|
|
var ch = format.charAt(i); |
|
|
|
|
let flagch = format.charAt(0), start = 0, str = flagch; |
|
|
|
|
for (let i = 1; i < len; i++) { |
|
|
|
|
const ch = format.charAt(i); |
|
|
|
|
if (flagch !== ch) { |
|
|
|
|
result += compileJFmt({ |
|
|
|
|
char: flagch, |
|
|
|
|
str: str, |
|
|
|
|
len: i - start |
|
|
|
|
len: i - start, |
|
|
|
|
}, date); |
|
|
|
|
flagch = ch; |
|
|
|
|
start = i; |
|
|
|
@ -788,13 +791,13 @@ export const date2Str = function (date, format) {
|
|
|
|
|
result += compileJFmt({ |
|
|
|
|
char: flagch, |
|
|
|
|
str: str, |
|
|
|
|
len: len - start |
|
|
|
|
len: len - start, |
|
|
|
|
}, date); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
function compileJFmt(jfmt, date) { |
|
|
|
|
var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; |
|
|
|
|
let str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; |
|
|
|
|
switch (ch) { |
|
|
|
|
case "E": // 星期
|
|
|
|
|
str = getFullDayName(date.getDay()); |
|
|
|
@ -823,7 +826,7 @@ export const date2Str = function (date, format) {
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "h": // 时(12)
|
|
|
|
|
var hour = date.getHours() % 12; |
|
|
|
|
let hour = date.getHours() % 12; |
|
|
|
|
if (hour === 0) { |
|
|
|
|
hour = 12; |
|
|
|
|
} |
|
|
|
@ -875,7 +878,7 @@ export const object2Number = function (value) {
|
|
|
|
|
if (typeof value === "number") { |
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
var str = value + ""; |
|
|
|
|
const str = value + ""; |
|
|
|
|
if (str.indexOf(".") === -1) { |
|
|
|
|
return parseInt(str); |
|
|
|
|
} |
|
|
|
@ -891,9 +894,9 @@ export const object2Date = function (obj) {
|
|
|
|
|
} else if (typeof obj === "number") { |
|
|
|
|
return new Date(obj); |
|
|
|
|
} |
|
|
|
|
var str = obj + ""; |
|
|
|
|
let str = obj + ""; |
|
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
|
var dt = new Date(str); |
|
|
|
|
const dt = new Date(str); |
|
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
|
return dt; |
|
|
|
|
} |
|
|
|
@ -909,9 +912,9 @@ export const object2Time = function (obj) {
|
|
|
|
|
if (obj instanceof Date) { |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
var str = obj + ""; |
|
|
|
|
let str = obj + ""; |
|
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
|
var dt = new Date(str); |
|
|
|
|
let dt = new Date(str); |
|
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
|
return dt; |
|
|
|
|
} |
|
|
|
|