From f9ef11e78ba488707b059383e236216078aaaabb Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Sun, 25 Feb 2018 18:37:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?toast=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/base/tip/demo.toast.js | 3 +- dist/base.css | 13 ++ dist/base.js | 10 +- dist/bundle.css | 13 ++ dist/bundle.js | 16 +- dist/demo.js | 30 ++-- dist/fineui.css | 13 ++ dist/fineui.js | 179 ++++++++++++++++------- src/base/foundation/message.js | 10 +- src/css/base/foundation/bi.css | 13 ++ src/less/base/foundation/bi.message.less | 14 ++ 11 files changed, 233 insertions(+), 81 deletions(-) diff --git a/demo/js/base/tip/demo.toast.js b/demo/js/base/tip/demo.toast.js index d5cda36fc..9d0352a6f 100644 --- a/demo/js/base/tip/demo.toast.js +++ b/demo/js/base/tip/demo.toast.js @@ -31,7 +31,8 @@ Demo.Toast = BI.inherit(BI.Widget, { height: 30, handler: function () { BI.Msg.toast("这是一条非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的数据", { - level: "warning" + level: "warning", + autoClose: false }); } } diff --git a/dist/base.css b/dist/base.css index 7e4dca748..7aa6f9854 100644 --- a/dist/base.css +++ b/dist/base.css @@ -862,6 +862,19 @@ li.CodeMirror-hint-active { .bi-message-close { font-size: 25px; } +.bi-message-animate { + -webkit-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -moz-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -o-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; +} +.bi-message-enter { + opacity: 1; +} +.bi-message-leave { + opacity: 0; + transform: translateY(-100%); +} .bi-message-title { font-size: 16px; cursor: pointer; diff --git a/dist/base.js b/dist/base.js index 8498bf5ce..57b42600c 100644 --- a/dist/base.js +++ b/dist/base.js @@ -14768,6 +14768,7 @@ $.extend(BI, { var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; var toast = BI.createWidget({ type: "bi.toast", + cls: "bi-message-animate bi-message-leave", level: level, autoClose: autoClose, text: message @@ -14782,10 +14783,13 @@ $.extend(BI, { }] }); toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); - toast.element.show(); + toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); + autoClose && BI.delay(function () { - toast.element.hide(); - toast.destroy(); + toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); + BI.delay(function () { + toast.destroy(); + }, 1000); }, 5000); }, _show: function (hasCancel, title, message, callback) { diff --git a/dist/bundle.css b/dist/bundle.css index a89403918..42f3532b7 100644 --- a/dist/bundle.css +++ b/dist/bundle.css @@ -2909,6 +2909,19 @@ li.CodeMirror-hint-active { .bi-message-close { font-size: 25px; } +.bi-message-animate { + -webkit-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -moz-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -o-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; +} +.bi-message-enter { + opacity: 1; +} +.bi-message-leave { + opacity: 0; + transform: translateY(-100%); +} .bi-message-title { font-size: 16px; cursor: pointer; diff --git a/dist/bundle.js b/dist/bundle.js index 60777edef..fe40a5443 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -40467,6 +40467,7 @@ $.extend(BI, { var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; var toast = BI.createWidget({ type: "bi.toast", + cls: "bi-message-animate bi-message-leave", level: level, autoClose: autoClose, text: message @@ -40481,13 +40482,14 @@ $.extend(BI, { }] }); toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); - toast.element.slideDown(500, function () { - autoClose && BI.delay(function () { - toast.element.slideUp(500, function () { - toast.destroy(); - }); - }, 5000); - }); + toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); + + autoClose && BI.delay(function () { + toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); + BI.delay(function () { + toast.destroy(); + }, 1000); + }, 5000); }, _show: function (hasCancel, title, message, callback) { $mask = $("
").css({ diff --git a/dist/demo.js b/dist/demo.js index 9ff8f2246..8a5304139 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -1627,7 +1627,8 @@ BI.shortcut("demo.title", Demo.Title);Demo.Toast = BI.inherit(BI.Widget, { height: 30, handler: function () { BI.Msg.toast("这是一条非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的数据", { - level: "warning" + level: "warning", + autoClose: false }); } } @@ -10692,7 +10693,9 @@ BI.shortcut("demo.tmp", Demo.Func); var model = Fix.define({ name: "原始属性", arr: [{ - n: "a" + n: { + ss: "a" + } }, { n: 0 }] @@ -10703,13 +10706,13 @@ BI.shortcut("demo.tmp", Demo.Func); return model; }, watch: { - "*.*.n": function () { - debugger - }, - "**": function () { - debugger - }, - "arr.1.*": function () { + // "*.*.n": function () { + // debugger + // }, + // "**": function () { + // debugger + // }, + "arr.*.n.*": function () { this.button.setText(this.model.name + "-" + this.model.arr[1].n); } }, @@ -10724,8 +10727,8 @@ BI.shortcut("demo.tmp", Demo.Func); self.button = this; }, handler: function () { - self.model.arr[0].n += 1; - self.model.arr[1].n += 1; + self.model.arr[0].n.ss += 1; + // self.model.arr[1].n += 1; }, text: this.model.name + "-" + this.model.arr[1].n } @@ -11206,6 +11209,11 @@ BI.shortcut("demo.tmp", Demo.Func); this.button.setText(this.model.b); } }, + + // 首先create demo.Fix,按stores数据流走,这样的话,会在原本的init调用前做一些工作,然后再原本的render前也做些工作。 + // 原本的render执行时会create return的内容,此时布局被create + // 布局不走store数据流,create时对items逐个addElement,即create每个item,然后add进父亲(此时确定父子关系) + // 对item的button进行create,button指定element进行create render: function () { var self = this; return { diff --git a/dist/fineui.css b/dist/fineui.css index 7384a260c..3d0c409b6 100644 --- a/dist/fineui.css +++ b/dist/fineui.css @@ -2909,6 +2909,19 @@ li.CodeMirror-hint-active { .bi-message-close { font-size: 25px; } +.bi-message-animate { + -webkit-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -moz-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -o-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; +} +.bi-message-enter { + opacity: 1; +} +.bi-message-leave { + opacity: 0; + transform: translateY(-100%); +} .bi-message-title { font-size: 16px; cursor: pointer; diff --git a/dist/fineui.js b/dist/fineui.js index cb68136c7..04ca5cf03 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -25907,6 +25907,8 @@ Data.Source = BISource = { function noop(a, b, c) {} + //程序自带的,二进制代码,无法看到方法体,显示的是native code + // alert(Array.prototype.sort) function isNative(Ctor) { return typeof Ctor === 'function' && /native code/.test(Ctor.toString()); } @@ -25968,6 +25970,7 @@ Data.Source = BISource = { return; } var segments = path.split('.'); + // 把形如a.*.b中的b对应value拿到手 return function (obj) { for (var i = 0; i < segments.length; i++) { if (!obj) return; @@ -26005,8 +26008,8 @@ Data.Source = BISource = { setImmediate(nextTickHandler); }; } else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || - // PhantomJS - MessageChannel.toString() === '[object MessageChannelConstructor]')) { + // PhantomJS + MessageChannel.toString() === '[object MessageChannelConstructor]')) { var channel = new MessageChannel(); var port = channel.port2; channel.port1.onmessage = nextTickHandler; @@ -26014,19 +26017,19 @@ Data.Source = BISource = { port.postMessage(1); }; } else - /* istanbul ignore next */ - if (typeof Promise !== 'undefined' && isNative(Promise)) { - // use microtask in non-DOM environments, e.g. Weex - var p = Promise.resolve(); - timerFunc = function timerFunc() { - p.then(nextTickHandler); - }; - } else { - // fallback to setTimeout - timerFunc = function timerFunc() { - setTimeout(nextTickHandler, 0); - }; - } + /* istanbul ignore next */ + if (typeof Promise !== 'undefined' && isNative(Promise)) { + // use microtask in non-DOM environments, e.g. Weex + var p = Promise.resolve(); + timerFunc = function timerFunc() { + p.then(nextTickHandler); + }; + } else { + // fallback to setTimeout + timerFunc = function timerFunc() { + setTimeout(nextTickHandler, 0); + }; + } return function queueNextTick(cb, ctx) { var _resolve = void 0; @@ -26068,6 +26071,7 @@ Data.Source = BISource = { * directives subscribing to it. */ +// 订阅器 var Dep = function () { function Dep() { _classCallCheck(this, Dep); @@ -26084,6 +26088,7 @@ Data.Source = BISource = { remove(this.subs, sub); }; + //target是全局唯一的watcher对象,watcher对象的addDep会distinct地addSub当前Dep对象 Dep.prototype.depend = function depend() { if (Dep.target) { Dep.target.addDep(this); @@ -26200,7 +26205,7 @@ Data.Source = BISource = { if (isIE9Below) { var VBClassPool = {}; window.execScript([// jshint ignore:line - 'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码 + 'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码 ].join('\n'), 'VBScript'); var VBMediator = function VBMediator(instance, accessors, name, value) { @@ -26216,7 +26221,7 @@ Data.Source = BISource = { // jshint ignore:line var buffer = []; buffer.push('\tPrivate [$vbsetter]', '\tPublic [$accessors]', '\tPublic Default Function [$vbthis](ac' + timeBucket + ', s' + timeBucket + ')', '\t\tSet [$accessors] = ac' + timeBucket + ': set [$vbsetter] = s' + timeBucket, '\t\tSet [$vbthis] = Me', //链式调用 - '\tEnd Function'); + '\tEnd Function'); //添加普通属性,因为VBScript对象不能像JS那样随意增删属性,必须在这里预先定义好 var uniq = { $vbthis: true, @@ -26229,19 +26234,19 @@ Data.Source = BISource = { uniq[name] = true; } } - //添加访问器属性 + //添加访问器属性 for (name in accessors) { if (uniq[name]) { continue; } uniq[name] = true; buffer.push( - //由于不知对方会传入什么,因此set, let都用上 - '\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter - '\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Set [' + name + '](val' + timeBucket + ')', //setter - '\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter - '\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回 - '\t\tSet[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tIf Err.Number <> 0 Then', '\t\t[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tEnd If', '\tOn Error Goto 0', '\tEnd Property'); + //由于不知对方会传入什么,因此set, let都用上 + '\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter + '\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Set [' + name + '](val' + timeBucket + ')', //setter + '\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter + '\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回 + '\t\tSet[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tIf Err.Number <> 0 Then', '\t\t[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tEnd If', '\tOn Error Goto 0', '\tEnd Property'); } for (name in properties) { @@ -26259,7 +26264,7 @@ Data.Source = BISource = { className = makeHashCode('VBClass'); window.parseVB('Class ' + className + body); window.parseVB(['Function ' + className + 'Factory(acc, vbm)', //创建实例并传入两个关键的参数 - '\tDim o', '\tSet o = (New ' + className + ')(acc, vbm)', '\tSet ' + className + 'Factory = o', 'End Function'].join('\r\n')); + '\tDim o', '\tSet o = (New ' + className + ')(acc, vbm)', '\tSet ' + className + 'Factory = o', 'End Function'].join('\r\n')); VBClassPool[body] = className; } var ret = window[className + 'Factory'](accessors, VBMediator); //得到其产品 @@ -26293,14 +26298,18 @@ Data.Source = BISource = { */ var Observer = function () { + //传入想要构造成ob对象的{} function Observer(value) { _classCallCheck(this, Observer); + // value, dep, vmCount三个私有属性 this.value = value; this.dep = new Dep(); this.vmCount = 0; + //处理数组类型 if (_.isArray(value)) { var augment = hasProto ? protoAugment : copyAugment; + //替换数组中的原型方法 augment(value, arrayMethods, arrayKeys); this.model = this.observeArray(value); } else { @@ -26342,16 +26351,23 @@ Data.Source = BISource = { } } + //将正常的对象变成ob对象 + // value为parentKey对应初始值,parentOb为Observer对象(对应想要构造成Ob的obj),parentKey为obj重的key function observe(value, parentObserver, parentKey) { + //value不是对象的话没有必要把他也ob化 if (!_.isObject(value)) { return; } var ob = void 0; + //如果value已经Ob化 if (value.__ob__ instanceof Observer) { ob = value.__ob__; + //observerState.shouldConvert默认为true,貌似也没有谁改过他 } else if (observerState.shouldConvert && (_.isArray(value) || isPlainObject(value))) { + //数组或者对象,递归以value创建Ob ob = new Observer(value); } + //建立子到父的映射 ob.parent = parentObserver || ob.parent; ob.parentKey = parentKey; return ob; @@ -26387,6 +26403,8 @@ Data.Source = BISource = { } } + //@1再Observer构造函数中调用walk的时候调用此函数的情况 + //@1 obj为传入Observer构造函数的plainObj, observer为当前构造的Observer对象的引用,调用walk时shallow并没有传递 function defineReactive(obj, observer, shallow) { var props = {}; var model = void 0; @@ -26438,12 +26456,17 @@ Data.Source = BISource = { // }) // } _.each(obj, function (val, key) { + //跳过对象中的_ob_ if (key in $$skipArray) { return; } + //给当前obj的每个子属性也添加dep(子属性也要ob化),以__dep+key的形式确定当前key是否已经ob化 var dep = observer && observer['__dep' + key] || new Dep(); + //赋予当前observer以__dep+key属性,对应为新建或者之前已将添加过的Dep对象 observer && (observer['__dep' + key] = dep); + //@1 必走observe,如果value是非对象,直接出来 var childOb = !shallow && observe(val, observer, key); + //属性转化成存取器属性 props[key] = { enumerable: true, configurable: true, @@ -26612,6 +26635,7 @@ Data.Source = BISource = { // vm._watchers || (vm._watchers = []) // vm._watchers.push(this) // options + // user初始默认为true,其他是undefined if (options) { this.deep = !!options.deep; this.user = !!options.user; @@ -26630,6 +26654,7 @@ Data.Source = BISource = { this.newDepIds = new Set(); this.expression = ''; // parse expression for getter + //形如a.*.b的正则那么传进来的就是function if (typeof expOrFn === 'function') { this.getter = expOrFn; } else { @@ -26675,6 +26700,7 @@ Data.Source = BISource = { } }; + //交换newXXX和XXX,并清空newXXX Watcher.prototype.cleanupDeps = function cleanupDeps() { var i = this.deps.length; while (i--) { @@ -26708,10 +26734,10 @@ Data.Source = BISource = { if (this.active) { var value = this.get(); if (value !== this.value || - // Deep watchers and watchers on Object/Arrays should fire even - // when the value is the same, because the value may - // have mutated. - _.isObject(value) || this.deep) { + // Deep watchers and watchers on Object/Arrays should fire even + // when the value is the same, because the value may + // have mutated. + _.isObject(value) || this.deep) { // set new value var oldValue = this.value; this.value = value; @@ -26812,7 +26838,7 @@ Data.Source = BISource = { } function routeToRegExp(route) { - route = route.replace(/\*./g, '[a-zA-Z0-9_]+.'); + route = route.replace(/\*/g, '[a-zA-Z0-9_]+'); return '^' + route + '$'; } @@ -26895,35 +26921,45 @@ Data.Source = BISource = { }); return; } - if (/\*\*$|\*$/.test(exp)) { - throw new Error('not support'); - } + // if (/\*\*$|\*$/.test(exp)) { + // throw new Error('not support'); + // } //其他含有*的情况,如*.a,*.*.a,a.*.a if (/\*/.test(exp)) { var currentModel = model; //先获取到能获取到的对象 - var paths = exp.split("."); - for (var _i = 0, len = paths.length; _i < len; _i++) { - if (paths[_i] === "*") { - break; - } - currentModel = model[paths[_i]]; - } - exp = exp.substr(exp.indexOf("*")); - //补全路径 - var parent = currentModel.__ob__.parent, - root = currentModel.__ob__; - while (parent) { - exp = '*.' + exp; - root = parent; - parent = parent.parent; - } + // var paths = exp.split("."); + // //当前model中一层层剥取,尽量取到接近监听字符串的叶子 + // //比如arr.*.n model就剥到arr那一层 + // for (var _i = 0, len = paths.length; _i < len; _i++) { + // if (paths[_i] === "*") { + // break; + // } + // currentModel = model[paths[_i]]; + // } + // exp = exp.substr(exp.indexOf("*")); + // //补全路径 + // //初始父亲为当前剥取到的model的父亲,根为剥去到的model所在Ob(parent也是为了找根,辅助用的) + // var parent = currentModel.__ob__.parent, + // root = currentModel.__ob__; + // while (parent) { + // //用*来补全剥去的路径 + // exp = '*.' + exp; + // //向上溯源 + // root = parent; + // parent = parent.parent; + // } + var root = currentModel.__ob__; var regStr = routeToRegExp(exp); var _dep = new Dep(); + //Ob的构造函数中是没有_globalDeps的,初始化 root._globalDeps || (root._globalDeps = {}); root._globalDeps[regStr] = _dep; var _w = new Watcher(currentModel, function () { + //调用将_dep加入到全局Dep.target(此时是_w)的sub队列中 + //_dep的队列中将会有_w,_w会记录当前_dep在自己的属性中 + //双向绑定 _dep.depend(); return NaN; }, function (newValue, oldValue) { @@ -27178,11 +27214,14 @@ Data.Source = BISource = { var watch$$1 = this.watch; var actions = this.actions; var keys = _.keys(this.$$model).concat(_.keys(state)).concat(_.keys(computed)).concat(context || []); + // 为model对象添加model defineProps(this, keys); childContext && defineContext(this, childContext); this.$$model && (this.model.__ob__ = this.$$model.__ob__); this._init(); + //state中return的对象被包装成ob对象后,ob的model赋值给model的$$state initState(this, state); + //model中添加$$computed对象,里面的属性是存取器属性 initComputed(this, computed); initWatch(this, watch$$1); initMethods(this, actions); @@ -27257,20 +27296,25 @@ Data.Source = BISource = { exports.__esModule = true; });;(function () { + // vm 当前组件 watch 组件中定义的watch function initWatch (vm, watch) { + vm._watchers || (vm._watchers = []); for (var key in watch) { var handler = watch[key]; + // 居然还能是funtion 数组? if (BI.isArray(handler)) { for (var i = 0; i < handler.length; i++) { vm._watchers.push(createWatcher(vm, key, handler[i])); } } else { + // watch的各项存入数组 vm._watchers.push(createWatcher(vm, key, handler)); } } } + // vm 当前组件 key 组件中定义的watch的key值 handler key对应的方法回调 function createWatcher (vm, keyOrFn, handler) { return Fix.watch(vm.model, keyOrFn, _.bind(handler, vm), { store: vm.store @@ -27302,7 +27346,10 @@ Data.Source = BISource = { } var oldWatch = Fix.watch; + + //model 当前组件的model, exp为watch key值 cb为方法回调 options中有当前store Fix.watch = function (model, expOrFn, cb, options) { + // 为sync的传递服务 if (BI.isPlainObject(cb)) { options = cb; cb = cb.handler; @@ -27312,6 +27359,7 @@ Data.Source = BISource = { } return oldWatch.call(this, model, expOrFn, function () { options && options.store && pushTarget(options.store); + //每次watch调用前先将store压栈,之后再出栈 var res = cb.apply(this, arguments); options && options.store && popTarget(); return res; @@ -27348,18 +27396,26 @@ Data.Source = BISource = { }; var _init = BI.Widget.prototype._init; + //以老王的布局穿插理论来看,父子组件间的布局走着玩意是无视store啥的 + //另外,只有init的组件有element的在create时就指定了父亲 BI.Widget.prototype._init = function () { var self = this; var needPop = false; if (window.Fix && this._store) { + // @1.形如{type: "xxx"} 无context为null,此时返回null var store = findStore(this.options.element || context); if (store) { pushTarget(store); needPop = true; } + //widget中指定的store或者model this.store = this._store(); + + //@1则不走 needPop && popTarget(); needPop = false; + + //@1则赋值与全局target作为当前target(环境),入栈是在render入栈 为什么不在此处压栈? pushTarget(this.store); if (this.store instanceof Fix.Model) { this.model = this.store.model; @@ -27368,19 +27424,28 @@ Data.Source = BISource = { } needPop = true; } + //@2进入 _init.apply(this, arguments); + + //为true则必然之前将当前组件环境推进栈中,完成后出来时候要pop,以回到初始化当前组件前(父组件)所在状态,同@3,needPop也与3同步 + //对于没有render的组件,这个会直接执行,之后再搞子组件,而不是像render递归到最后 needPop && popTarget(); }; var _render = BI.Widget.prototype._render; + + // @2_init中走render BI.Widget.prototype._render = function () { var needPop = false; if (window.Fix && this._store) { needPop = true; + //入栈,可以想见,init中指定了全局的target,而这边会依据此target,将此target压入栈中 pushTarget(this.store); initWatch(this, this.watch); } + //子组件来一遍 _render.apply(this, arguments); + //@3如果当前组件没有指定store,加入数据流,那么他初始化完成的时候不应该去做出栈操作 needPop && popTarget(); }; @@ -42231,6 +42296,7 @@ $.extend(BI, { var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; var toast = BI.createWidget({ type: "bi.toast", + cls: "bi-message-animate bi-message-leave", level: level, autoClose: autoClose, text: message @@ -42245,13 +42311,14 @@ $.extend(BI, { }] }); toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); - toast.element.slideDown(500, function () { - autoClose && BI.delay(function () { - toast.element.slideUp(500, function () { - toast.destroy(); - }); - }, 5000); - }); + toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); + + autoClose && BI.delay(function () { + toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); + BI.delay(function () { + toast.destroy(); + }, 1000); + }, 5000); }, _show: function (hasCancel, title, message, callback) { $mask = $("
").css({ diff --git a/src/base/foundation/message.js b/src/base/foundation/message.js index 95172132e..82b05e6a0 100644 --- a/src/base/foundation/message.js +++ b/src/base/foundation/message.js @@ -25,6 +25,7 @@ $.extend(BI, { var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; var toast = BI.createWidget({ type: "bi.toast", + cls: "bi-message-animate bi-message-leave", level: level, autoClose: autoClose, text: message @@ -39,10 +40,13 @@ $.extend(BI, { }] }); toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); - toast.element.show(); + toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); + autoClose && BI.delay(function () { - toast.element.hide(); - toast.destroy(); + toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); + BI.delay(function () { + toast.destroy(); + }, 1000); }, 5000); }, _show: function (hasCancel, title, message, callback) { diff --git a/src/css/base/foundation/bi.css b/src/css/base/foundation/bi.css index 173116c05..ed7cdec87 100644 --- a/src/css/base/foundation/bi.css +++ b/src/css/base/foundation/bi.css @@ -17,3 +17,16 @@ .bi-message-close { font-size: 25px; } +.bi-message-animate { + -webkit-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -moz-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + -o-transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; + transition: opacity 0.3s, transform 0.4s, -webkit-transform 0.4s; +} +.bi-message-enter { + opacity: 1; +} +.bi-message-leave { + opacity: 0; + transform: translateY(-100%); +} diff --git a/src/less/base/foundation/bi.message.less b/src/less/base/foundation/bi.message.less index fe8993067..53692cbe1 100644 --- a/src/less/base/foundation/bi.message.less +++ b/src/less/base/foundation/bi.message.less @@ -16,4 +16,18 @@ .bi-message-close { font-size: 25px; +} + +.bi-message-animate { + @val: opacity .3s, transform .4s, -webkit-transform .4s; + .transition(@val); +} + +.bi-message-enter { + opacity: 1; +} + +.bi-message-leave { + opacity: 0; + transform: translateY(-100%); } \ No newline at end of file From 2bb9ede847b641aa67d809d1b2e646aaccac9749 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 26 Feb 2018 10:02:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BBString.js=E5=92=8CDate.js=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/case/demo.calendar.js | 4 +- dist/bundle.js | 930 +++++++++--------- dist/case.js | 34 +- dist/core.js | 762 +++++++------- dist/demo.js | 4 +- dist/fineui.js | 930 +++++++++--------- dist/widget.js | 134 +-- src/case/calendar/calendar.js | 22 +- src/case/calendar/calendar.year.js | 12 +- src/core/alias.js | 18 +- src/core/base.js | 355 ++++++- src/core/proto/date.js | 328 +----- src/core/proto/string.js | 57 -- src/core/utils/cache.js | 4 +- src/widget/date/calendar/picker.date.js | 8 +- .../date/calendar/popup.calendar.date.js | 2 +- src/widget/date/trigger.date.js | 42 +- src/widget/datepane/datepane.js | 4 +- src/widget/datetime/datetime.combo.js | 4 +- src/widget/datetime/datetime.popup.js | 4 +- src/widget/datetime/datetime.trigger.js | 4 +- .../multidate/abstract.multidate.datepane.js | 34 +- src/widget/multidate/multidate.combo.js | 6 +- src/widget/multidate/multidate.popup.js | 6 +- src/widget/timeinterval/timeinterval.js | 12 +- src/widget/year/popup.year.js | 6 +- src/widget/year/trigger.year.js | 2 +- utils/utils.js | 762 +++++++------- 28 files changed, 2240 insertions(+), 2250 deletions(-) diff --git a/demo/js/case/demo.calendar.js b/demo/js/case/demo.calendar.js index 8b747adc2..aca133fce 100644 --- a/demo/js/case/demo.calendar.js +++ b/demo/js/case/demo.calendar.js @@ -16,7 +16,7 @@ Demo.Func = BI.inherit(BI.Widget, { }, year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }; }, @@ -25,7 +25,7 @@ Demo.Func = BI.inherit(BI.Widget, { this.calendar.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); } }); diff --git a/dist/bundle.js b/dist/bundle.js index fe40a5443..16369e4aa 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -11695,7 +11695,7 @@ if (!window.BI) { // Date if (type === "[object Date]") { - return Date.getDate(obj.getTime()); + return BI.getDate(obj.getTime()); } var i, clone, key; @@ -11931,7 +11931,7 @@ if (!window.BI) { if (Date.now) { return Date.now(); } - return Date.getDate().getTime(); + return BI.getDate().getTime(); @@ -12195,6 +12195,357 @@ if (!window.BI) { prand = (mult * prand + incr) % modu; } return unescape(enc_str); + }, + + /** + * 对字符串中的'和\做编码处理 + * @static + * @param {String} string 要做编码处理的字符串 + * @return {String} 编码后的字符串 + */ + escape: function (string) { + return string.replace(/('|\\)/g, "\\$1"); + }, + + /** + * 让字符串通过指定字符做补齐的函数 + * + * var s = BI.leftPad('123', 5, '0');//s的值为:'00123' + * + * @static + * @param {String} val 原始值 + * @param {Number} size 总共需要的位数 + * @param {String} ch 用于补齐的字符 + * @return {String} 补齐后的字符串 + */ + leftPad: function (val, size, ch) { + var result = String(val); + if (!ch) { + ch = " "; + } + while (result.length < size) { + result = ch + result; + } + return result.toString(); + }, + + /** + * 对字符串做替换的函数 + * + * var cls = 'my-class', text = 'Some text'; + * var res = BI.format('
Some text
'; + * + * @static + * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... + * @return {String} 做了替换后的字符串 + */ + format: function (format) { + var args = Array.prototype.slice.call(arguments, 1); + return format.replace(/\{(\d+)\}/g, function (m, i) { + return args[i]; + }); + } + }); + + // 日期相关方法 + _.extend(BI, { + /** + * 是否是闰年 + * @param year + * @returns {boolean} + */ + isLeapYear: function (year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + /** + * 检测是否在有效期 + * + * @param YY 年 + * @param MM 月 + * @param DD 日 + * @param minDate '1900-01-01' + * @param maxDate '2099-12-31' + * @returns {Array} 若无效返回无效状态 + */ + checkDateVoid: function (YY, MM, DD, minDate, maxDate) { + var back = []; + YY = YY | 0; + MM = MM | 0; + DD = DD | 0; + minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; + maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; + if (YY < minDate[0]) { + back = ["y"]; + } else if (YY > maxDate[0]) { + back = ["y", 1]; + } else if (YY >= minDate[0] && YY <= maxDate[0]) { + if (YY == minDate[0]) { + if (MM < minDate[1]) { + back = ["m"]; + } else if (MM == minDate[1]) { + if (DD < minDate[2]) { + back = ["d"]; + } + } + } + if (YY == maxDate[0]) { + if (MM > maxDate[1]) { + back = ["m", 1]; + } else if (MM == maxDate[1]) { + if (DD > maxDate[2]) { + back = ["d", 1]; + } + } + } + } + return back; + }, + + checkDateLegal: function (str) { + var ar = str.match(/\d+/g); + var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; + if (ar.length <= 1) { + return true; + } + if (ar.length <= 2) { + return MM >= 1 && MM <= 12; + } + var MD = Date._MD.slice(0); + MD[1] = BI.isLeapYear(YY) ? 29 : 28; + return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; + }, + + parseDateTime: function (str, fmt) { + var today = BI.getDate(); + var y = 0; + var m = 0; + var d = 1; + // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 + var a = str.split(/\W+/); + if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { + var yearlength = 4; + var otherlength = 2; + a[0] = str.substring(0, yearlength); + a[1] = str.substring(yearlength, yearlength + otherlength); + a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); + } + var b = fmt.match(/%./g); + var i = 0, j = 0; + var hr = 0; + var min = 0; + var sec = 0; + for (i = 0; i < a.length; ++i) { + switch (b[i]) { + case "%d": + case "%e": + d = parseInt(a[i], 10); + break; + + case "%X": + m = parseInt(a[i], 10) - 1; + break; + case "%x": + m = parseInt(a[i], 10) - 1; + break; + + case "%Y": + case "%y": + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + break; + + case "%b": + case "%B": + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + m = j; + break; + } + } + break; + + case "%H": + case "%I": + case "%k": + case "%l": + hr = parseInt(a[i], 10); + break; + + case "%P": + case "%p": + if (/pm/i.test(a[i]) && hr < 12) { + hr += 12; + } else if (/am/i.test(a[i]) && hr >= 12) { + hr -= 12; + } + break; + + case "%M": + min = parseInt(a[i], 10); + case "%S": + sec = parseInt(a[i], 10); + break; + } + } + // if (!a[i]) { + // continue; + // } + if (isNaN(y)) { + y = today.getFullYear(); + } + if (isNaN(m)) { + m = today.getMonth(); + } + if (isNaN(d)) { + d = today.getDate(); + } + if (isNaN(hr)) { + hr = today.getHours(); + } + if (isNaN(min)) { + min = today.getMinutes(); + } + if (isNaN(sec)) { + sec = today.getSeconds(); + } + if (y != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + y = 0; + m = -1; + d = 0; + for (i = 0; i < a.length; ++i) { + if (a[i].search(/[a-zA-Z]+/) != -1) { + var t = -1; + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + t = j; + break; + } + } + if (t != -1) { + if (m != -1) { + d = m + 1; + } + m = t; + } + } else if (parseInt(a[i], 10) <= 12 && m == -1) { + m = a[i] - 1; + } else if (parseInt(a[i], 10) > 31 && y == 0) { + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + } else if (d == 0) { + d = a[i]; + } + } + if (y == 0) { + y = today.getFullYear(); + } + if (m != -1 && d != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + return today; + }, + + getDate: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { + var localTime = dt.getTime(); + var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 + var utc = localTime + localOffset; // utc即GMT时间标准时区 + return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); + } + return dt; + + }, + + getTime: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone)) { + return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; + } + return dt.getTime(); + } }); @@ -13228,7 +13579,7 @@ BI.Cache = { // 判断是否设置过期时间 if (expiresHours && expiresHours > 0) { var date = new Date(); - date.setTime(date.getTime() + expiresHours * 3600 * 1000); + date.setTime(BI.getTime() + expiresHours * 3600 * 1000); cookieString = cookieString + "; expires=" + date.toGMTString(); } if (path) { @@ -13243,7 +13594,7 @@ BI.Cache = { }, deleteCookie: function (name, path) { var date = new Date(); - date.setTime(date.getTime() - 10000); + date.setTime(BI.getTime() - 10000); var cookieString = name + "=v; expires=" + date.toGMTString(); if (path) { cookieString = cookieString + "; path=" + path; @@ -17093,7 +17444,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = String.leftPad(newnum, orilen, "0"); + newnum = BI.leftPad(newnum, orilen, "0"); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -17436,6 +17787,8 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { text = _eFormat(text, fmt); } else { // 数字格式 + var s = []; + BI.clamp(s); text = _numberFormat(text, fmt); } // ¤ - 货币格式 @@ -17505,14 +17858,14 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { } else if (len < 2) { str = date.getMonth() + 1; } else { - str = String.leftPad(date.getMonth() + 1 + "", 2, "0"); + str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); } break; case "d": // 日 if (len > 1) { - str = String.leftPad(date.getDate() + "", 2, "0"); + str = BI.leftPad(BI.getDate() + "", 2, "0"); } else { - str = date.getDate(); + str = BI.getDate(); } break; case "h": // 时(12) @@ -17521,28 +17874,28 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { hour = 12; } if (len > 1) { - str = String.leftPad(hour + "", 2, "0"); + str = BI.leftPad(hour + "", 2, "0"); } else { str = hour; } break; case "H": // 时(24) if (len > 1) { - str = String.leftPad(date.getHours() + "", 2, "0"); + str = BI.leftPad(date.getHours() + "", 2, "0"); } else { str = date.getHours(); } break; case "m": if (len > 1) { - str = String.leftPad(date.getMinutes() + "", 2, "0"); + str = BI.leftPad(date.getMinutes() + "", 2, "0"); } else { str = date.getMinutes(); } break; case "s": if (len > 1) { - str = String.leftPad(date.getSeconds() + "", 2, "0"); + str = BI.leftPad(date.getSeconds() + "", 2, "0"); } else { str = date.getSeconds(); } @@ -20615,20 +20968,20 @@ Date.prototype.getMonthDays = function (month) { * @returns {Date} */ Date.prototype.getLastDateOfMonth = function () { - return Date.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); + return BI.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function () { - var now = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var then = Date.getDate(this.getFullYear(), 0, 0, 0, 0, 0); + var now = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var then = BI.getDate(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { - var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var d = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); // 周一是一周第一天 var week = d.getDay() === 0 ? 7 : d.getDay(); // var week = d.getDay(); @@ -20652,17 +21005,17 @@ Date.prototype.getQuarter = function () { // 离当前时间多少天的时间 Date.prototype.getOffsetDate = function (offset) { - return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); + return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; Date.prototype.getAfterMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n * 3); return dt; }; // 获得n个季度前的日期 Date.prototype.getBeforeMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n * 3); return dt; }; @@ -20686,29 +21039,29 @@ Date.prototype.getQuarterStartMonth = function () { }; // 获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { - return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); + return BI.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); }; // 得到本季度的结束日期 Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; - return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); + return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; Date.prototype.getAfterMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n | 0); return dt; }; Date.prototype.getBeforeMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n | 0); return dt; }; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); var day = dt.getDate(); - var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); if (day > monthDay) { day = monthDay; } @@ -20732,7 +21085,7 @@ Date.prototype.getWeekEndDate = function () { Date.prototype.equalsTo = function (date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && - (this.getDate() == date.getDate()) && + (this.getDate() == BI.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes()) && (this.getSeconds() == date.getSeconds())); @@ -20740,7 +21093,7 @@ Date.prototype.equalsTo = function (date) { /** Set only the year, month, date parts (keep existing time) */ Date.prototype.setDateOnly = function (date) { - var tmp = Date.getDate(date); + var tmp = BI.getDate(date); this.setDate(1); this.setFullYear(tmp.getFullYear()); this.setMonth(tmp.getMonth()); @@ -20819,304 +21172,6 @@ Date.prototype.print = function (str) { return str; }; - -/** - * 是否是闰年 - * @param year - * @returns {boolean} - */ -Date.isLeap = function (year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; -}; - -/** - * 检测是否在有效期 - * - * @param YY 年 - * @param MM 月 - * @param DD 日 - * @param minDate '1900-01-01' - * @param maxDate '2099-12-31' - * @returns {Array} 若无效返回无效状态 - */ -Date.checkVoid = function (YY, MM, DD, minDate, maxDate) { - var back = []; - YY = YY | 0; - MM = MM | 0; - DD = DD | 0; - minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; - maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; - if (YY < minDate[0]) { - back = ["y"]; - } else if (YY > maxDate[0]) { - back = ["y", 1]; - } else if (YY >= minDate[0] && YY <= maxDate[0]) { - if (YY == minDate[0]) { - if (MM < minDate[1]) { - back = ["m"]; - } else if (MM == minDate[1]) { - if (DD < minDate[2]) { - back = ["d"]; - } - } - } - if (YY == maxDate[0]) { - if (MM > maxDate[1]) { - back = ["m", 1]; - } else if (MM == maxDate[1]) { - if (DD > maxDate[2]) { - back = ["d", 1]; - } - } - } - } - return back; -}; - -Date.checkLegal = function (str) { - var ar = str.match(/\d+/g); - var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; - if (ar.length <= 1) { - return true; - } - if (ar.length <= 2) { - return MM >= 1 && MM <= 12; - } - var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(YY) ? 29 : 28; - return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; -}; - -Date.parseDateTime = function (str, fmt) { - var today = Date.getDate(); - var y = 0; - var m = 0; - var d = 1; - // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 - var a = str.split(/\W+/); - if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { - var yearlength = 4; - var otherlength = 2; - a[0] = str.substring(0, yearlength); - a[1] = str.substring(yearlength, yearlength + otherlength); - a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); - } - var b = fmt.match(/%./g); - var i = 0, j = 0; - var hr = 0; - var min = 0; - var sec = 0; - for (i = 0; i < a.length; ++i) { - switch (b[i]) { - case "%d": - case "%e": - d = parseInt(a[i], 10); - break; - - case "%X": - m = parseInt(a[i], 10) - 1; - break; - case "%x": - m = parseInt(a[i], 10) - 1; - break; - - case "%Y": - case "%y": - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - break; - - case "%b": - case "%B": - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - m = j; - break; - } - } - break; - - case "%H": - case "%I": - case "%k": - case "%l": - hr = parseInt(a[i], 10); - break; - - case "%P": - case "%p": - if (/pm/i.test(a[i]) && hr < 12) { - hr += 12; - } else if (/am/i.test(a[i]) && hr >= 12) { - hr -= 12; - } - break; - - case "%M": - min = parseInt(a[i], 10); - case "%S": - sec = parseInt(a[i], 10); - break; - } - } - // if (!a[i]) { - // continue; - // } - if (isNaN(y)) { - y = today.getFullYear(); - } - if (isNaN(m)) { - m = today.getMonth(); - } - if (isNaN(d)) { - d = today.getDate(); - } - if (isNaN(hr)) { - hr = today.getHours(); - } - if (isNaN(min)) { - min = today.getMinutes(); - } - if (isNaN(sec)) { - sec = today.getSeconds(); - } - if (y != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - y = 0; - m = -1; - d = 0; - for (i = 0; i < a.length; ++i) { - if (a[i].search(/[a-zA-Z]+/) != -1) { - var t = -1; - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - t = j; - break; - } - } - if (t != -1) { - if (m != -1) { - d = m + 1; - } - m = t; - } - } else if (parseInt(a[i], 10) <= 12 && m == -1) { - m = a[i] - 1; - } else if (parseInt(a[i], 10) > 31 && y == 0) { - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - } else if (d == 0) { - d = a[i]; - } - } - if (y == 0) { - y = today.getFullYear(); - } - if (m != -1 && d != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - return today; -}; - -Date.getDate = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { - var localTime = dt.getTime(); - var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 - var utc = localTime + localOffset; // utc即GMT时间标准时区 - return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); - } - return dt; - -}; - -Date.getTime = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone)) { - return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; - } - return dt.getTime(); - -}; /* * 给jQuery.Event对象添加的工具方法 */ @@ -21579,63 +21634,6 @@ _.extend(String.prototype, { } return location; } -}); - -/** - * 对字符串对象的扩展 - * @class String - */ -_.extend(String, { - - /** - * 对字符串中的'和\做编码处理 - * @static - * @param {String} string 要做编码处理的字符串 - * @return {String} 编码后的字符串 - */ - escape: function (string) { - return string.replace(/('|\\)/g, "\\$1"); - }, - - /** - * 让字符串通过指定字符做补齐的函数 - * - * var s = String.leftPad('123', 5, '0');//s的值为:'00123' - * - * @static - * @param {String} val 原始值 - * @param {Number} size 总共需要的位数 - * @param {String} ch 用于补齐的字符 - * @return {String} 补齐后的字符串 - */ - leftPad: function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; - } - while (result.length < size) { - result = ch + result; - } - return result.toString(); - }, - - /** - * 对字符串做替换的函数 - * - * var cls = 'my-class', text = 'Some text'; - * var res = String.format('
Some text
'; - * - * @static - * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... - * @return {String} 做了替换后的字符串 - */ - format: function (format) { - var args = Array.prototype.slice.call(arguments, 1); - return format.replace(/\{(\d+)\}/g, function (m, i) { - return args[i]; - }); - } });BI.EventListener = { listen: function listen (target, eventType, callback) { if (target.addEventListener) { @@ -63886,7 +63884,7 @@ BI.Calendar = BI.inherit(BI.Widget, { }, _dateCreator: function (Y, M, D) { - var self = this, o = this.options, log = {}, De = Date.getDate(); + var self = this, o = this.options, log = {}, De = BI.getDate(); var mins = o.min.match(/\d+/g); var maxs = o.max.match(/\d+/g); Y < (mins[0] | 0) && (Y = (mins[0] | 0)); @@ -63896,7 +63894,7 @@ BI.Calendar = BI.inherit(BI.Widget, { log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(log.ymd[0]) ? 29 : 28; + MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; De.setFullYear(log.ymd[0], log.ymd[1], 1); log.FDay = De.getDay(); @@ -63923,7 +63921,7 @@ BI.Calendar = BI.inherit(BI.Widget, { MM === 12 && (YY += 1); MM = MM === 12 ? 1 : MM + 1; } - if (Date.checkVoid(YY, MM, DD, mins, maxs)[0]) { + if (BI.checkDateVoid(YY, MM, DD, mins, maxs)[0]) { td.disabled = true; } td.text = DD; @@ -63996,20 +63994,20 @@ BI.Calendar = BI.inherit(BI.Widget, { isFrontDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(-1 * (day + 1)); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, isFinalDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(42 - day); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, setValue: function (ob) { @@ -64028,14 +64026,14 @@ BI.Calendar = BI.inherit(BI.Widget, { BI.extend(BI.Calendar, { getPageByDateJSON: function (json) { - var year = Date.getDate().getFullYear(); - var month = Date.getDate().getMonth(); + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); var page = (json.year - year) * 12; page += json.month - month; return page; }, getDateJSONByPage: function (v) { - var months = Date.getDate().getMonth(); + var months = BI.getDate().getMonth(); var page = v; // 对当前page做偏移,使到当前年初 @@ -64047,7 +64045,7 @@ BI.extend(BI.Calendar, { } var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); return { - year: Date.getDate().getFullYear() + year, + year: BI.getDate().getFullYear() + year, month: month }; } @@ -64081,7 +64079,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var items = []; BI.each(BI.range(BI.YearCalendar.INTERVAL), function (i) { var td = {}; - if (Date.checkVoid(start + i, 1, 1, o.min, o.max)[0]) { + if (BI.checkDateVoid(start + i, 1, 1, o.min, o.max)[0]) { td.disabled = true; } td.text = start + i; @@ -64093,7 +64091,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { _init: function () { BI.YearCalendar.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.currentYear = Date.getDate().getFullYear(); + this.currentYear = BI.getDate().getFullYear(); var years = this._yearCreator(o.year || this.currentYear); // 纵向排列年 @@ -64156,14 +64154,14 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var o = this.options; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; }, isFinalYear: function () { var o = this.options, c = this._const; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; }, setValue: function (val) { @@ -64180,7 +64178,7 @@ BI.extend(BI.YearCalendar, { // 获取显示的第一年 getStartYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); return year - ((year - cur + 3) % BI.YearCalendar.INTERVAL + 12) % BI.YearCalendar.INTERVAL; }, @@ -64189,7 +64187,7 @@ BI.extend(BI.YearCalendar, { }, getPageByYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); year = BI.YearCalendar.getStartYear(year); return (year - cur + 3) / BI.YearCalendar.INTERVAL; } @@ -77262,8 +77260,8 @@ BI.DatePicker = BI.inherit(BI.Widget, { _init: function () { BI.DatePicker.superclass._init.apply(this, arguments); var self = this, o = this.options; - this._year = Date.getDate().getFullYear(); - this._month = Date.getDate().getMonth(); + this._year = BI.getDate().getFullYear(); + this._month = BI.getDate().getMonth(); this.left = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", @@ -77360,14 +77358,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === Date.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === Date.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, @@ -77427,7 +77425,7 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { BI.DateCalendarPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); this._day = this.today.getDate(); @@ -77640,7 +77638,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge validationChecker: function (v) { var date = v.match(/\d+/g); self._autoAppend(v, date); - return self._dateCheck(v) && Date.checkLegal(v) && self._checkVoid({ + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ year: date[0], month: date[1], day: date[2] @@ -77718,21 +77716,21 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge this.setValue(o.value); }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; }, _autoAppend: function (v, dateObj) { var self = this; - var date = Date.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); var yearCheck = function (v) { - return Date.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; }; var monthCheck = function (v) { - return Date.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; }; - if (BI.isNotNull(dateObj) && Date.checkLegal(v)) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { switch (v.length) { case this._const.yearLength: if (yearCheck(v)) { @@ -77750,7 +77748,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge setValue: function (v) { var type, value, self = this; - var date = Date.getDate(); + var date = BI.getDate(); this.store_value = v; if (BI.isNotNull(v)) { type = v.type || BI.DateTrigger.MULTI_DATE_CALENDAR; value = v.value; @@ -77767,62 +77765,62 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge switch (type) { case BI.DateTrigger.MULTI_DATE_YEAR_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV]; - date = Date.getDate((date.getFullYear() - 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() - 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER]; - date = Date.getDate((date.getFullYear() + 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() + 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN]; - date = Date.getDate(date.getFullYear(), 0, 1); + date = BI.getDate(date.getFullYear(), 0, 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END]; - date = Date.getDate(date.getFullYear(), 11, 31); + date = BI.getDate(date.getFullYear(), 11, 31); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV]; - date = Date.getDate().getBeforeMulQuarter(value); + date = BI.getDate().getBeforeMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER]; - date = Date.getDate().getAfterMulQuarter(value); + date = BI.getDate().getAfterMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN]; - date = Date.getDate().getQuarterStartDate(); + date = BI.getDate().getQuarterStartDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END]; - date = Date.getDate().getQuarterEndDate(); + date = BI.getDate().getQuarterEndDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV]; - date = Date.getDate().getBeforeMultiMonth(value); + date = BI.getDate().getBeforeMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER]; - date = Date.getDate().getAfterMultiMonth(value); + date = BI.getDate().getAfterMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN]; - date = Date.getDate(date.getFullYear(), date.getMonth(), 1); + date = BI.getDate(date.getFullYear(), date.getMonth(), 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END]; - date = Date.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + date = BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_WEEK_PREV: @@ -77847,7 +77845,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge break; case BI.DateTrigger.MULTI_DATE_DAY_TODAY: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY]; - date = Date.getDate(); + date = BI.getDate(); _setInnerValue(date, text); break; default: @@ -77948,7 +77946,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { BI.DatePaneWidget.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); @@ -78013,7 +78011,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }, _getNewCurrentDate: function () { - var today = Date.getDate(); + var today = BI.getDate(); return { year: today.getFullYear(), month: today.getMonth() @@ -78075,11 +78073,11 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { _init: function () { BI.DateTimeCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = BI.isNotNull(opts.value) ? opts.value : { year: date.getFullYear(), month: date.getMonth(), - day: date.getDate(), + day: BI.getDate(), hour: date.getHours(), minute: date.getMinutes(), second: date.getSeconds() @@ -78318,11 +78316,11 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { setValue: function (v) { var value = v, date; if (BI.isNull(value)) { - date = Date.getDate(); + date = BI.getDate(); this.dateCombo.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.hour.setValue(date.getHours()); this.minute.setValue(date.getMinutes()); @@ -78509,10 +78507,10 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { var self = this; var value = v, dateStr; if(BI.isNull(value)) { - value = Date.getDate(); + value = BI.getDate(); dateStr = value.print("%Y-%X-%d %H:%M:%S"); } else { - var date = Date.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); + var date = BI.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); dateStr = date.print("%Y-%X-%d %H:%M:%S"); } @@ -81311,39 +81309,39 @@ BI.MultiDateCard = BI.inherit(BI.Widget, { var type = valueObject.type, value = valueObject.value; switch (type) { case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return Date.getDate().getOffsetDate(-1 * value); + return BI.getDate().getOffsetDate(-1 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return Date.getDate().getOffsetDate(value); + return BI.getDate().getOffsetDate(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return Date.getDate(); + return BI.getDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return Date.getDate().getBeforeMultiMonth(value); + return BI.getDate().getBeforeMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return Date.getDate().getAfterMultiMonth(value); + return BI.getDate().getAfterMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), 1); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), (Date.getDate().getLastDateOfMonth()).getDate()); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return Date.getDate().getBeforeMulQuarter(value); + return BI.getDate().getBeforeMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return Date.getDate().getAfterMulQuarter(value); + return BI.getDate().getAfterMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return Date.getDate().getQuarterStartDate(); + return BI.getDate().getQuarterStartDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return Date.getDate().getQuarterEndDate(); + return BI.getDate().getQuarterEndDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return Date.getDate().getOffsetDate(-7 * value); + return BI.getDate().getOffsetDate(-7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return Date.getDate().getOffsetDate(7 * value); + return BI.getDate().getOffsetDate(7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return Date.getDate((Date.getDate().getFullYear() - 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return Date.getDate((Date.getDate().getFullYear() + 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), 0, 1); + return BI.getDate(BI.getDate().getFullYear(), 0, 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return Date.getDate(Date.getDate().getFullYear(), 11, 31); + return BI.getDate(BI.getDate().getFullYear(), 11, 31); } } }); @@ -81372,7 +81370,7 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { BI.MultiDateCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; this.storeTriggerValue = ""; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = opts.value; this.trigger = BI.createWidget({ type: "bi.date_trigger", @@ -81441,11 +81439,11 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); }); this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = Date.getDate(); + var date = BI.getDate(); self.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self.combo.hideView(); self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); @@ -81885,7 +81883,7 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { self.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self._setInnerValue(self.ymd); break; @@ -82000,12 +81998,12 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { break; default: if (this._checkValueValid(value)) { - var date = Date.getDate(); + var date = BI.getDate(); this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); this.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); } else { @@ -94019,26 +94017,26 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, _check: function (smallDate, bigDate) { var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); - return this._dateCheck(smallDate) && Date.checkLegal(smallDate) && this._checkVoid({ + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ year: smallObj[0], month: smallObj[1], day: smallObj[2] - }) && this._dateCheck(bigDate) && Date.checkLegal(bigDate) && this._checkVoid({ + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ year: bigObj[0], month: bigObj[1], day: bigObj[2] }); }, _compare: function (smallDate, bigDate) { - smallDate = Date.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = Date.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { @@ -94206,7 +94204,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { BI.YearPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.selectedYear = this._year = Date.getDate().getFullYear(); + this.selectedYear = this._year = BI.getDate().getFullYear(); var backBtn = BI.createWidget({ type: "bi.icon_button", @@ -94263,8 +94261,8 @@ BI.YearPopup = BI.inherit(BI.Widget, { setValue: function (v) { var o = this.options; - if (Date.checkVoid(v, 1, 1, o.min, o.max)[0]) { - v = Date.getDate().getFullYear(); + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); this.selectedYear = ""; this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); this.navigation.setValue(""); @@ -94307,7 +94305,7 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { height: o.height, validationChecker: function (v) { self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !Date.checkVoid(v, 1, 1, o.min, o.max)[0]); + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); }, quitChecker: function (v) { return false; diff --git a/dist/case.js b/dist/case.js index fb45aacc0..541b5d675 100644 --- a/dist/case.js +++ b/dist/case.js @@ -1605,7 +1605,7 @@ BI.Calendar = BI.inherit(BI.Widget, { }, _dateCreator: function (Y, M, D) { - var self = this, o = this.options, log = {}, De = Date.getDate(); + var self = this, o = this.options, log = {}, De = BI.getDate(); var mins = o.min.match(/\d+/g); var maxs = o.max.match(/\d+/g); Y < (mins[0] | 0) && (Y = (mins[0] | 0)); @@ -1615,7 +1615,7 @@ BI.Calendar = BI.inherit(BI.Widget, { log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(log.ymd[0]) ? 29 : 28; + MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; De.setFullYear(log.ymd[0], log.ymd[1], 1); log.FDay = De.getDay(); @@ -1642,7 +1642,7 @@ BI.Calendar = BI.inherit(BI.Widget, { MM === 12 && (YY += 1); MM = MM === 12 ? 1 : MM + 1; } - if (Date.checkVoid(YY, MM, DD, mins, maxs)[0]) { + if (BI.checkDateVoid(YY, MM, DD, mins, maxs)[0]) { td.disabled = true; } td.text = DD; @@ -1715,20 +1715,20 @@ BI.Calendar = BI.inherit(BI.Widget, { isFrontDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(-1 * (day + 1)); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, isFinalDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(42 - day); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, setValue: function (ob) { @@ -1747,14 +1747,14 @@ BI.Calendar = BI.inherit(BI.Widget, { BI.extend(BI.Calendar, { getPageByDateJSON: function (json) { - var year = Date.getDate().getFullYear(); - var month = Date.getDate().getMonth(); + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); var page = (json.year - year) * 12; page += json.month - month; return page; }, getDateJSONByPage: function (v) { - var months = Date.getDate().getMonth(); + var months = BI.getDate().getMonth(); var page = v; // 对当前page做偏移,使到当前年初 @@ -1766,7 +1766,7 @@ BI.extend(BI.Calendar, { } var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); return { - year: Date.getDate().getFullYear() + year, + year: BI.getDate().getFullYear() + year, month: month }; } @@ -1800,7 +1800,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var items = []; BI.each(BI.range(BI.YearCalendar.INTERVAL), function (i) { var td = {}; - if (Date.checkVoid(start + i, 1, 1, o.min, o.max)[0]) { + if (BI.checkDateVoid(start + i, 1, 1, o.min, o.max)[0]) { td.disabled = true; } td.text = start + i; @@ -1812,7 +1812,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { _init: function () { BI.YearCalendar.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.currentYear = Date.getDate().getFullYear(); + this.currentYear = BI.getDate().getFullYear(); var years = this._yearCreator(o.year || this.currentYear); // 纵向排列年 @@ -1875,14 +1875,14 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var o = this.options; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; }, isFinalYear: function () { var o = this.options, c = this._const; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; }, setValue: function (val) { @@ -1899,7 +1899,7 @@ BI.extend(BI.YearCalendar, { // 获取显示的第一年 getStartYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); return year - ((year - cur + 3) % BI.YearCalendar.INTERVAL + 12) % BI.YearCalendar.INTERVAL; }, @@ -1908,7 +1908,7 @@ BI.extend(BI.YearCalendar, { }, getPageByYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); year = BI.YearCalendar.getStartYear(year); return (year - cur + 3) / BI.YearCalendar.INTERVAL; } diff --git a/dist/core.js b/dist/core.js index 5d951adfb..7e3b8cf8c 100644 --- a/dist/core.js +++ b/dist/core.js @@ -11695,7 +11695,7 @@ if (!window.BI) { // Date if (type === "[object Date]") { - return Date.getDate(obj.getTime()); + return BI.getDate(obj.getTime()); } var i, clone, key; @@ -11931,7 +11931,7 @@ if (!window.BI) { if (Date.now) { return Date.now(); } - return Date.getDate().getTime(); + return BI.getDate().getTime(); @@ -12195,6 +12195,357 @@ if (!window.BI) { prand = (mult * prand + incr) % modu; } return unescape(enc_str); + }, + + /** + * 对字符串中的'和\做编码处理 + * @static + * @param {String} string 要做编码处理的字符串 + * @return {String} 编码后的字符串 + */ + escape: function (string) { + return string.replace(/('|\\)/g, "\\$1"); + }, + + /** + * 让字符串通过指定字符做补齐的函数 + * + * var s = BI.leftPad('123', 5, '0');//s的值为:'00123' + * + * @static + * @param {String} val 原始值 + * @param {Number} size 总共需要的位数 + * @param {String} ch 用于补齐的字符 + * @return {String} 补齐后的字符串 + */ + leftPad: function (val, size, ch) { + var result = String(val); + if (!ch) { + ch = " "; + } + while (result.length < size) { + result = ch + result; + } + return result.toString(); + }, + + /** + * 对字符串做替换的函数 + * + * var cls = 'my-class', text = 'Some text'; + * var res = BI.format('
Some text
'; + * + * @static + * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... + * @return {String} 做了替换后的字符串 + */ + format: function (format) { + var args = Array.prototype.slice.call(arguments, 1); + return format.replace(/\{(\d+)\}/g, function (m, i) { + return args[i]; + }); + } + }); + + // 日期相关方法 + _.extend(BI, { + /** + * 是否是闰年 + * @param year + * @returns {boolean} + */ + isLeapYear: function (year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + /** + * 检测是否在有效期 + * + * @param YY 年 + * @param MM 月 + * @param DD 日 + * @param minDate '1900-01-01' + * @param maxDate '2099-12-31' + * @returns {Array} 若无效返回无效状态 + */ + checkDateVoid: function (YY, MM, DD, minDate, maxDate) { + var back = []; + YY = YY | 0; + MM = MM | 0; + DD = DD | 0; + minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; + maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; + if (YY < minDate[0]) { + back = ["y"]; + } else if (YY > maxDate[0]) { + back = ["y", 1]; + } else if (YY >= minDate[0] && YY <= maxDate[0]) { + if (YY == minDate[0]) { + if (MM < minDate[1]) { + back = ["m"]; + } else if (MM == minDate[1]) { + if (DD < minDate[2]) { + back = ["d"]; + } + } + } + if (YY == maxDate[0]) { + if (MM > maxDate[1]) { + back = ["m", 1]; + } else if (MM == maxDate[1]) { + if (DD > maxDate[2]) { + back = ["d", 1]; + } + } + } + } + return back; + }, + + checkDateLegal: function (str) { + var ar = str.match(/\d+/g); + var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; + if (ar.length <= 1) { + return true; + } + if (ar.length <= 2) { + return MM >= 1 && MM <= 12; + } + var MD = Date._MD.slice(0); + MD[1] = BI.isLeapYear(YY) ? 29 : 28; + return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; + }, + + parseDateTime: function (str, fmt) { + var today = BI.getDate(); + var y = 0; + var m = 0; + var d = 1; + // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 + var a = str.split(/\W+/); + if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { + var yearlength = 4; + var otherlength = 2; + a[0] = str.substring(0, yearlength); + a[1] = str.substring(yearlength, yearlength + otherlength); + a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); + } + var b = fmt.match(/%./g); + var i = 0, j = 0; + var hr = 0; + var min = 0; + var sec = 0; + for (i = 0; i < a.length; ++i) { + switch (b[i]) { + case "%d": + case "%e": + d = parseInt(a[i], 10); + break; + + case "%X": + m = parseInt(a[i], 10) - 1; + break; + case "%x": + m = parseInt(a[i], 10) - 1; + break; + + case "%Y": + case "%y": + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + break; + + case "%b": + case "%B": + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + m = j; + break; + } + } + break; + + case "%H": + case "%I": + case "%k": + case "%l": + hr = parseInt(a[i], 10); + break; + + case "%P": + case "%p": + if (/pm/i.test(a[i]) && hr < 12) { + hr += 12; + } else if (/am/i.test(a[i]) && hr >= 12) { + hr -= 12; + } + break; + + case "%M": + min = parseInt(a[i], 10); + case "%S": + sec = parseInt(a[i], 10); + break; + } + } + // if (!a[i]) { + // continue; + // } + if (isNaN(y)) { + y = today.getFullYear(); + } + if (isNaN(m)) { + m = today.getMonth(); + } + if (isNaN(d)) { + d = today.getDate(); + } + if (isNaN(hr)) { + hr = today.getHours(); + } + if (isNaN(min)) { + min = today.getMinutes(); + } + if (isNaN(sec)) { + sec = today.getSeconds(); + } + if (y != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + y = 0; + m = -1; + d = 0; + for (i = 0; i < a.length; ++i) { + if (a[i].search(/[a-zA-Z]+/) != -1) { + var t = -1; + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + t = j; + break; + } + } + if (t != -1) { + if (m != -1) { + d = m + 1; + } + m = t; + } + } else if (parseInt(a[i], 10) <= 12 && m == -1) { + m = a[i] - 1; + } else if (parseInt(a[i], 10) > 31 && y == 0) { + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + } else if (d == 0) { + d = a[i]; + } + } + if (y == 0) { + y = today.getFullYear(); + } + if (m != -1 && d != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + return today; + }, + + getDate: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { + var localTime = dt.getTime(); + var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 + var utc = localTime + localOffset; // utc即GMT时间标准时区 + return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); + } + return dt; + + }, + + getTime: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone)) { + return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; + } + return dt.getTime(); + } }); @@ -13228,7 +13579,7 @@ BI.Cache = { // 判断是否设置过期时间 if (expiresHours && expiresHours > 0) { var date = new Date(); - date.setTime(date.getTime() + expiresHours * 3600 * 1000); + date.setTime(BI.getTime() + expiresHours * 3600 * 1000); cookieString = cookieString + "; expires=" + date.toGMTString(); } if (path) { @@ -13243,7 +13594,7 @@ BI.Cache = { }, deleteCookie: function (name, path) { var date = new Date(); - date.setTime(date.getTime() - 10000); + date.setTime(BI.getTime() - 10000); var cookieString = name + "=v; expires=" + date.toGMTString(); if (path) { cookieString = cookieString + "; path=" + path; @@ -17093,7 +17444,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = String.leftPad(newnum, orilen, "0"); + newnum = BI.leftPad(newnum, orilen, "0"); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -17436,6 +17787,8 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { text = _eFormat(text, fmt); } else { // 数字格式 + var s = []; + BI.clamp(s); text = _numberFormat(text, fmt); } // ¤ - 货币格式 @@ -17505,14 +17858,14 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { } else if (len < 2) { str = date.getMonth() + 1; } else { - str = String.leftPad(date.getMonth() + 1 + "", 2, "0"); + str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); } break; case "d": // 日 if (len > 1) { - str = String.leftPad(date.getDate() + "", 2, "0"); + str = BI.leftPad(BI.getDate() + "", 2, "0"); } else { - str = date.getDate(); + str = BI.getDate(); } break; case "h": // 时(12) @@ -17521,28 +17874,28 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { hour = 12; } if (len > 1) { - str = String.leftPad(hour + "", 2, "0"); + str = BI.leftPad(hour + "", 2, "0"); } else { str = hour; } break; case "H": // 时(24) if (len > 1) { - str = String.leftPad(date.getHours() + "", 2, "0"); + str = BI.leftPad(date.getHours() + "", 2, "0"); } else { str = date.getHours(); } break; case "m": if (len > 1) { - str = String.leftPad(date.getMinutes() + "", 2, "0"); + str = BI.leftPad(date.getMinutes() + "", 2, "0"); } else { str = date.getMinutes(); } break; case "s": if (len > 1) { - str = String.leftPad(date.getSeconds() + "", 2, "0"); + str = BI.leftPad(date.getSeconds() + "", 2, "0"); } else { str = date.getSeconds(); } @@ -20615,20 +20968,20 @@ Date.prototype.getMonthDays = function (month) { * @returns {Date} */ Date.prototype.getLastDateOfMonth = function () { - return Date.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); + return BI.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function () { - var now = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var then = Date.getDate(this.getFullYear(), 0, 0, 0, 0, 0); + var now = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var then = BI.getDate(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { - var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var d = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); // 周一是一周第一天 var week = d.getDay() === 0 ? 7 : d.getDay(); // var week = d.getDay(); @@ -20652,17 +21005,17 @@ Date.prototype.getQuarter = function () { // 离当前时间多少天的时间 Date.prototype.getOffsetDate = function (offset) { - return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); + return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; Date.prototype.getAfterMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n * 3); return dt; }; // 获得n个季度前的日期 Date.prototype.getBeforeMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n * 3); return dt; }; @@ -20686,29 +21039,29 @@ Date.prototype.getQuarterStartMonth = function () { }; // 获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { - return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); + return BI.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); }; // 得到本季度的结束日期 Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; - return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); + return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; Date.prototype.getAfterMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n | 0); return dt; }; Date.prototype.getBeforeMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n | 0); return dt; }; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); var day = dt.getDate(); - var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); if (day > monthDay) { day = monthDay; } @@ -20732,7 +21085,7 @@ Date.prototype.getWeekEndDate = function () { Date.prototype.equalsTo = function (date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && - (this.getDate() == date.getDate()) && + (this.getDate() == BI.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes()) && (this.getSeconds() == date.getSeconds())); @@ -20740,7 +21093,7 @@ Date.prototype.equalsTo = function (date) { /** Set only the year, month, date parts (keep existing time) */ Date.prototype.setDateOnly = function (date) { - var tmp = Date.getDate(date); + var tmp = BI.getDate(date); this.setDate(1); this.setFullYear(tmp.getFullYear()); this.setMonth(tmp.getMonth()); @@ -20819,304 +21172,6 @@ Date.prototype.print = function (str) { return str; }; - -/** - * 是否是闰年 - * @param year - * @returns {boolean} - */ -Date.isLeap = function (year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; -}; - -/** - * 检测是否在有效期 - * - * @param YY 年 - * @param MM 月 - * @param DD 日 - * @param minDate '1900-01-01' - * @param maxDate '2099-12-31' - * @returns {Array} 若无效返回无效状态 - */ -Date.checkVoid = function (YY, MM, DD, minDate, maxDate) { - var back = []; - YY = YY | 0; - MM = MM | 0; - DD = DD | 0; - minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; - maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; - if (YY < minDate[0]) { - back = ["y"]; - } else if (YY > maxDate[0]) { - back = ["y", 1]; - } else if (YY >= minDate[0] && YY <= maxDate[0]) { - if (YY == minDate[0]) { - if (MM < minDate[1]) { - back = ["m"]; - } else if (MM == minDate[1]) { - if (DD < minDate[2]) { - back = ["d"]; - } - } - } - if (YY == maxDate[0]) { - if (MM > maxDate[1]) { - back = ["m", 1]; - } else if (MM == maxDate[1]) { - if (DD > maxDate[2]) { - back = ["d", 1]; - } - } - } - } - return back; -}; - -Date.checkLegal = function (str) { - var ar = str.match(/\d+/g); - var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; - if (ar.length <= 1) { - return true; - } - if (ar.length <= 2) { - return MM >= 1 && MM <= 12; - } - var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(YY) ? 29 : 28; - return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; -}; - -Date.parseDateTime = function (str, fmt) { - var today = Date.getDate(); - var y = 0; - var m = 0; - var d = 1; - // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 - var a = str.split(/\W+/); - if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { - var yearlength = 4; - var otherlength = 2; - a[0] = str.substring(0, yearlength); - a[1] = str.substring(yearlength, yearlength + otherlength); - a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); - } - var b = fmt.match(/%./g); - var i = 0, j = 0; - var hr = 0; - var min = 0; - var sec = 0; - for (i = 0; i < a.length; ++i) { - switch (b[i]) { - case "%d": - case "%e": - d = parseInt(a[i], 10); - break; - - case "%X": - m = parseInt(a[i], 10) - 1; - break; - case "%x": - m = parseInt(a[i], 10) - 1; - break; - - case "%Y": - case "%y": - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - break; - - case "%b": - case "%B": - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - m = j; - break; - } - } - break; - - case "%H": - case "%I": - case "%k": - case "%l": - hr = parseInt(a[i], 10); - break; - - case "%P": - case "%p": - if (/pm/i.test(a[i]) && hr < 12) { - hr += 12; - } else if (/am/i.test(a[i]) && hr >= 12) { - hr -= 12; - } - break; - - case "%M": - min = parseInt(a[i], 10); - case "%S": - sec = parseInt(a[i], 10); - break; - } - } - // if (!a[i]) { - // continue; - // } - if (isNaN(y)) { - y = today.getFullYear(); - } - if (isNaN(m)) { - m = today.getMonth(); - } - if (isNaN(d)) { - d = today.getDate(); - } - if (isNaN(hr)) { - hr = today.getHours(); - } - if (isNaN(min)) { - min = today.getMinutes(); - } - if (isNaN(sec)) { - sec = today.getSeconds(); - } - if (y != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - y = 0; - m = -1; - d = 0; - for (i = 0; i < a.length; ++i) { - if (a[i].search(/[a-zA-Z]+/) != -1) { - var t = -1; - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - t = j; - break; - } - } - if (t != -1) { - if (m != -1) { - d = m + 1; - } - m = t; - } - } else if (parseInt(a[i], 10) <= 12 && m == -1) { - m = a[i] - 1; - } else if (parseInt(a[i], 10) > 31 && y == 0) { - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - } else if (d == 0) { - d = a[i]; - } - } - if (y == 0) { - y = today.getFullYear(); - } - if (m != -1 && d != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - return today; -}; - -Date.getDate = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { - var localTime = dt.getTime(); - var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 - var utc = localTime + localOffset; // utc即GMT时间标准时区 - return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); - } - return dt; - -}; - -Date.getTime = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone)) { - return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; - } - return dt.getTime(); - -}; /* * 给jQuery.Event对象添加的工具方法 */ @@ -21579,63 +21634,6 @@ _.extend(String.prototype, { } return location; } -}); - -/** - * 对字符串对象的扩展 - * @class String - */ -_.extend(String, { - - /** - * 对字符串中的'和\做编码处理 - * @static - * @param {String} string 要做编码处理的字符串 - * @return {String} 编码后的字符串 - */ - escape: function (string) { - return string.replace(/('|\\)/g, "\\$1"); - }, - - /** - * 让字符串通过指定字符做补齐的函数 - * - * var s = String.leftPad('123', 5, '0');//s的值为:'00123' - * - * @static - * @param {String} val 原始值 - * @param {Number} size 总共需要的位数 - * @param {String} ch 用于补齐的字符 - * @return {String} 补齐后的字符串 - */ - leftPad: function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; - } - while (result.length < size) { - result = ch + result; - } - return result.toString(); - }, - - /** - * 对字符串做替换的函数 - * - * var cls = 'my-class', text = 'Some text'; - * var res = String.format('
Some text
'; - * - * @static - * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... - * @return {String} 做了替换后的字符串 - */ - format: function (format) { - var args = Array.prototype.slice.call(arguments, 1); - return format.replace(/\{(\d+)\}/g, function (m, i) { - return args[i]; - }); - } });BI.EventListener = { listen: function listen (target, eventType, callback) { if (target.addEventListener) { diff --git a/dist/demo.js b/dist/demo.js index 8a5304139..5f6d68563 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -2295,7 +2295,7 @@ BI.shortcut("demo.text_value_check_combo", Demo.TextValueCheckCombo);Demo.Func = }, year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }; }, @@ -2304,7 +2304,7 @@ BI.shortcut("demo.text_value_check_combo", Demo.TextValueCheckCombo);Demo.Func = this.calendar.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); } }); diff --git a/dist/fineui.js b/dist/fineui.js index 04ca5cf03..2f2dac0da 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -11896,7 +11896,7 @@ if (!window.BI) { // Date if (type === "[object Date]") { - return Date.getDate(obj.getTime()); + return BI.getDate(obj.getTime()); } var i, clone, key; @@ -12132,7 +12132,7 @@ if (!window.BI) { if (Date.now) { return Date.now(); } - return Date.getDate().getTime(); + return BI.getDate().getTime(); @@ -12396,6 +12396,357 @@ if (!window.BI) { prand = (mult * prand + incr) % modu; } return unescape(enc_str); + }, + + /** + * 对字符串中的'和\做编码处理 + * @static + * @param {String} string 要做编码处理的字符串 + * @return {String} 编码后的字符串 + */ + escape: function (string) { + return string.replace(/('|\\)/g, "\\$1"); + }, + + /** + * 让字符串通过指定字符做补齐的函数 + * + * var s = BI.leftPad('123', 5, '0');//s的值为:'00123' + * + * @static + * @param {String} val 原始值 + * @param {Number} size 总共需要的位数 + * @param {String} ch 用于补齐的字符 + * @return {String} 补齐后的字符串 + */ + leftPad: function (val, size, ch) { + var result = String(val); + if (!ch) { + ch = " "; + } + while (result.length < size) { + result = ch + result; + } + return result.toString(); + }, + + /** + * 对字符串做替换的函数 + * + * var cls = 'my-class', text = 'Some text'; + * var res = BI.format('
Some text
'; + * + * @static + * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... + * @return {String} 做了替换后的字符串 + */ + format: function (format) { + var args = Array.prototype.slice.call(arguments, 1); + return format.replace(/\{(\d+)\}/g, function (m, i) { + return args[i]; + }); + } + }); + + // 日期相关方法 + _.extend(BI, { + /** + * 是否是闰年 + * @param year + * @returns {boolean} + */ + isLeapYear: function (year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + /** + * 检测是否在有效期 + * + * @param YY 年 + * @param MM 月 + * @param DD 日 + * @param minDate '1900-01-01' + * @param maxDate '2099-12-31' + * @returns {Array} 若无效返回无效状态 + */ + checkDateVoid: function (YY, MM, DD, minDate, maxDate) { + var back = []; + YY = YY | 0; + MM = MM | 0; + DD = DD | 0; + minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; + maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; + if (YY < minDate[0]) { + back = ["y"]; + } else if (YY > maxDate[0]) { + back = ["y", 1]; + } else if (YY >= minDate[0] && YY <= maxDate[0]) { + if (YY == minDate[0]) { + if (MM < minDate[1]) { + back = ["m"]; + } else if (MM == minDate[1]) { + if (DD < minDate[2]) { + back = ["d"]; + } + } + } + if (YY == maxDate[0]) { + if (MM > maxDate[1]) { + back = ["m", 1]; + } else if (MM == maxDate[1]) { + if (DD > maxDate[2]) { + back = ["d", 1]; + } + } + } + } + return back; + }, + + checkDateLegal: function (str) { + var ar = str.match(/\d+/g); + var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; + if (ar.length <= 1) { + return true; + } + if (ar.length <= 2) { + return MM >= 1 && MM <= 12; + } + var MD = Date._MD.slice(0); + MD[1] = BI.isLeapYear(YY) ? 29 : 28; + return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; + }, + + parseDateTime: function (str, fmt) { + var today = BI.getDate(); + var y = 0; + var m = 0; + var d = 1; + // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 + var a = str.split(/\W+/); + if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { + var yearlength = 4; + var otherlength = 2; + a[0] = str.substring(0, yearlength); + a[1] = str.substring(yearlength, yearlength + otherlength); + a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); + } + var b = fmt.match(/%./g); + var i = 0, j = 0; + var hr = 0; + var min = 0; + var sec = 0; + for (i = 0; i < a.length; ++i) { + switch (b[i]) { + case "%d": + case "%e": + d = parseInt(a[i], 10); + break; + + case "%X": + m = parseInt(a[i], 10) - 1; + break; + case "%x": + m = parseInt(a[i], 10) - 1; + break; + + case "%Y": + case "%y": + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + break; + + case "%b": + case "%B": + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + m = j; + break; + } + } + break; + + case "%H": + case "%I": + case "%k": + case "%l": + hr = parseInt(a[i], 10); + break; + + case "%P": + case "%p": + if (/pm/i.test(a[i]) && hr < 12) { + hr += 12; + } else if (/am/i.test(a[i]) && hr >= 12) { + hr -= 12; + } + break; + + case "%M": + min = parseInt(a[i], 10); + case "%S": + sec = parseInt(a[i], 10); + break; + } + } + // if (!a[i]) { + // continue; + // } + if (isNaN(y)) { + y = today.getFullYear(); + } + if (isNaN(m)) { + m = today.getMonth(); + } + if (isNaN(d)) { + d = today.getDate(); + } + if (isNaN(hr)) { + hr = today.getHours(); + } + if (isNaN(min)) { + min = today.getMinutes(); + } + if (isNaN(sec)) { + sec = today.getSeconds(); + } + if (y != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + y = 0; + m = -1; + d = 0; + for (i = 0; i < a.length; ++i) { + if (a[i].search(/[a-zA-Z]+/) != -1) { + var t = -1; + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + t = j; + break; + } + } + if (t != -1) { + if (m != -1) { + d = m + 1; + } + m = t; + } + } else if (parseInt(a[i], 10) <= 12 && m == -1) { + m = a[i] - 1; + } else if (parseInt(a[i], 10) > 31 && y == 0) { + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + } else if (d == 0) { + d = a[i]; + } + } + if (y == 0) { + y = today.getFullYear(); + } + if (m != -1 && d != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + return today; + }, + + getDate: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { + var localTime = dt.getTime(); + var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 + var utc = localTime + localOffset; // utc即GMT时间标准时区 + return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); + } + return dt; + + }, + + getTime: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone)) { + return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; + } + return dt.getTime(); + } }); @@ -13429,7 +13780,7 @@ BI.Cache = { // 判断是否设置过期时间 if (expiresHours && expiresHours > 0) { var date = new Date(); - date.setTime(date.getTime() + expiresHours * 3600 * 1000); + date.setTime(BI.getTime() + expiresHours * 3600 * 1000); cookieString = cookieString + "; expires=" + date.toGMTString(); } if (path) { @@ -13444,7 +13795,7 @@ BI.Cache = { }, deleteCookie: function (name, path) { var date = new Date(); - date.setTime(date.getTime() - 10000); + date.setTime(BI.getTime() - 10000); var cookieString = name + "=v; expires=" + date.toGMTString(); if (path) { cookieString = cookieString + "; path=" + path; @@ -17294,7 +17645,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = String.leftPad(newnum, orilen, "0"); + newnum = BI.leftPad(newnum, orilen, "0"); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -17637,6 +17988,8 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { text = _eFormat(text, fmt); } else { // 数字格式 + var s = []; + BI.clamp(s); text = _numberFormat(text, fmt); } // ¤ - 货币格式 @@ -17706,14 +18059,14 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { } else if (len < 2) { str = date.getMonth() + 1; } else { - str = String.leftPad(date.getMonth() + 1 + "", 2, "0"); + str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); } break; case "d": // 日 if (len > 1) { - str = String.leftPad(date.getDate() + "", 2, "0"); + str = BI.leftPad(BI.getDate() + "", 2, "0"); } else { - str = date.getDate(); + str = BI.getDate(); } break; case "h": // 时(12) @@ -17722,28 +18075,28 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";(function () { hour = 12; } if (len > 1) { - str = String.leftPad(hour + "", 2, "0"); + str = BI.leftPad(hour + "", 2, "0"); } else { str = hour; } break; case "H": // 时(24) if (len > 1) { - str = String.leftPad(date.getHours() + "", 2, "0"); + str = BI.leftPad(date.getHours() + "", 2, "0"); } else { str = date.getHours(); } break; case "m": if (len > 1) { - str = String.leftPad(date.getMinutes() + "", 2, "0"); + str = BI.leftPad(date.getMinutes() + "", 2, "0"); } else { str = date.getMinutes(); } break; case "s": if (len > 1) { - str = String.leftPad(date.getSeconds() + "", 2, "0"); + str = BI.leftPad(date.getSeconds() + "", 2, "0"); } else { str = date.getSeconds(); } @@ -20816,20 +21169,20 @@ Date.prototype.getMonthDays = function (month) { * @returns {Date} */ Date.prototype.getLastDateOfMonth = function () { - return Date.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); + return BI.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function () { - var now = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var then = Date.getDate(this.getFullYear(), 0, 0, 0, 0, 0); + var now = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var then = BI.getDate(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { - var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var d = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); // 周一是一周第一天 var week = d.getDay() === 0 ? 7 : d.getDay(); // var week = d.getDay(); @@ -20853,17 +21206,17 @@ Date.prototype.getQuarter = function () { // 离当前时间多少天的时间 Date.prototype.getOffsetDate = function (offset) { - return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); + return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; Date.prototype.getAfterMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n * 3); return dt; }; // 获得n个季度前的日期 Date.prototype.getBeforeMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n * 3); return dt; }; @@ -20887,29 +21240,29 @@ Date.prototype.getQuarterStartMonth = function () { }; // 获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { - return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); + return BI.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); }; // 得到本季度的结束日期 Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; - return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); + return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; Date.prototype.getAfterMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n | 0); return dt; }; Date.prototype.getBeforeMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n | 0); return dt; }; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); var day = dt.getDate(); - var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); if (day > monthDay) { day = monthDay; } @@ -20933,7 +21286,7 @@ Date.prototype.getWeekEndDate = function () { Date.prototype.equalsTo = function (date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && - (this.getDate() == date.getDate()) && + (this.getDate() == BI.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes()) && (this.getSeconds() == date.getSeconds())); @@ -20941,7 +21294,7 @@ Date.prototype.equalsTo = function (date) { /** Set only the year, month, date parts (keep existing time) */ Date.prototype.setDateOnly = function (date) { - var tmp = Date.getDate(date); + var tmp = BI.getDate(date); this.setDate(1); this.setFullYear(tmp.getFullYear()); this.setMonth(tmp.getMonth()); @@ -21020,304 +21373,6 @@ Date.prototype.print = function (str) { return str; }; - -/** - * 是否是闰年 - * @param year - * @returns {boolean} - */ -Date.isLeap = function (year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; -}; - -/** - * 检测是否在有效期 - * - * @param YY 年 - * @param MM 月 - * @param DD 日 - * @param minDate '1900-01-01' - * @param maxDate '2099-12-31' - * @returns {Array} 若无效返回无效状态 - */ -Date.checkVoid = function (YY, MM, DD, minDate, maxDate) { - var back = []; - YY = YY | 0; - MM = MM | 0; - DD = DD | 0; - minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; - maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; - if (YY < minDate[0]) { - back = ["y"]; - } else if (YY > maxDate[0]) { - back = ["y", 1]; - } else if (YY >= minDate[0] && YY <= maxDate[0]) { - if (YY == minDate[0]) { - if (MM < minDate[1]) { - back = ["m"]; - } else if (MM == minDate[1]) { - if (DD < minDate[2]) { - back = ["d"]; - } - } - } - if (YY == maxDate[0]) { - if (MM > maxDate[1]) { - back = ["m", 1]; - } else if (MM == maxDate[1]) { - if (DD > maxDate[2]) { - back = ["d", 1]; - } - } - } - } - return back; -}; - -Date.checkLegal = function (str) { - var ar = str.match(/\d+/g); - var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; - if (ar.length <= 1) { - return true; - } - if (ar.length <= 2) { - return MM >= 1 && MM <= 12; - } - var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(YY) ? 29 : 28; - return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; -}; - -Date.parseDateTime = function (str, fmt) { - var today = Date.getDate(); - var y = 0; - var m = 0; - var d = 1; - // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 - var a = str.split(/\W+/); - if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { - var yearlength = 4; - var otherlength = 2; - a[0] = str.substring(0, yearlength); - a[1] = str.substring(yearlength, yearlength + otherlength); - a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); - } - var b = fmt.match(/%./g); - var i = 0, j = 0; - var hr = 0; - var min = 0; - var sec = 0; - for (i = 0; i < a.length; ++i) { - switch (b[i]) { - case "%d": - case "%e": - d = parseInt(a[i], 10); - break; - - case "%X": - m = parseInt(a[i], 10) - 1; - break; - case "%x": - m = parseInt(a[i], 10) - 1; - break; - - case "%Y": - case "%y": - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - break; - - case "%b": - case "%B": - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - m = j; - break; - } - } - break; - - case "%H": - case "%I": - case "%k": - case "%l": - hr = parseInt(a[i], 10); - break; - - case "%P": - case "%p": - if (/pm/i.test(a[i]) && hr < 12) { - hr += 12; - } else if (/am/i.test(a[i]) && hr >= 12) { - hr -= 12; - } - break; - - case "%M": - min = parseInt(a[i], 10); - case "%S": - sec = parseInt(a[i], 10); - break; - } - } - // if (!a[i]) { - // continue; - // } - if (isNaN(y)) { - y = today.getFullYear(); - } - if (isNaN(m)) { - m = today.getMonth(); - } - if (isNaN(d)) { - d = today.getDate(); - } - if (isNaN(hr)) { - hr = today.getHours(); - } - if (isNaN(min)) { - min = today.getMinutes(); - } - if (isNaN(sec)) { - sec = today.getSeconds(); - } - if (y != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - y = 0; - m = -1; - d = 0; - for (i = 0; i < a.length; ++i) { - if (a[i].search(/[a-zA-Z]+/) != -1) { - var t = -1; - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - t = j; - break; - } - } - if (t != -1) { - if (m != -1) { - d = m + 1; - } - m = t; - } - } else if (parseInt(a[i], 10) <= 12 && m == -1) { - m = a[i] - 1; - } else if (parseInt(a[i], 10) > 31 && y == 0) { - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - } else if (d == 0) { - d = a[i]; - } - } - if (y == 0) { - y = today.getFullYear(); - } - if (m != -1 && d != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - return today; -}; - -Date.getDate = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { - var localTime = dt.getTime(); - var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 - var utc = localTime + localOffset; // utc即GMT时间标准时区 - return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); - } - return dt; - -}; - -Date.getTime = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone)) { - return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; - } - return dt.getTime(); - -}; /* * 给jQuery.Event对象添加的工具方法 */ @@ -21780,63 +21835,6 @@ _.extend(String.prototype, { } return location; } -}); - -/** - * 对字符串对象的扩展 - * @class String - */ -_.extend(String, { - - /** - * 对字符串中的'和\做编码处理 - * @static - * @param {String} string 要做编码处理的字符串 - * @return {String} 编码后的字符串 - */ - escape: function (string) { - return string.replace(/('|\\)/g, "\\$1"); - }, - - /** - * 让字符串通过指定字符做补齐的函数 - * - * var s = String.leftPad('123', 5, '0');//s的值为:'00123' - * - * @static - * @param {String} val 原始值 - * @param {Number} size 总共需要的位数 - * @param {String} ch 用于补齐的字符 - * @return {String} 补齐后的字符串 - */ - leftPad: function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; - } - while (result.length < size) { - result = ch + result; - } - return result.toString(); - }, - - /** - * 对字符串做替换的函数 - * - * var cls = 'my-class', text = 'Some text'; - * var res = String.format('
Some text
'; - * - * @static - * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... - * @return {String} 做了替换后的字符串 - */ - format: function (format) { - var args = Array.prototype.slice.call(arguments, 1); - return format.replace(/\{(\d+)\}/g, function (m, i) { - return args[i]; - }); - } });BI.EventListener = { listen: function listen (target, eventType, callback) { if (target.addEventListener) { @@ -65715,7 +65713,7 @@ BI.Calendar = BI.inherit(BI.Widget, { }, _dateCreator: function (Y, M, D) { - var self = this, o = this.options, log = {}, De = Date.getDate(); + var self = this, o = this.options, log = {}, De = BI.getDate(); var mins = o.min.match(/\d+/g); var maxs = o.max.match(/\d+/g); Y < (mins[0] | 0) && (Y = (mins[0] | 0)); @@ -65725,7 +65723,7 @@ BI.Calendar = BI.inherit(BI.Widget, { log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(log.ymd[0]) ? 29 : 28; + MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; De.setFullYear(log.ymd[0], log.ymd[1], 1); log.FDay = De.getDay(); @@ -65752,7 +65750,7 @@ BI.Calendar = BI.inherit(BI.Widget, { MM === 12 && (YY += 1); MM = MM === 12 ? 1 : MM + 1; } - if (Date.checkVoid(YY, MM, DD, mins, maxs)[0]) { + if (BI.checkDateVoid(YY, MM, DD, mins, maxs)[0]) { td.disabled = true; } td.text = DD; @@ -65825,20 +65823,20 @@ BI.Calendar = BI.inherit(BI.Widget, { isFrontDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(-1 * (day + 1)); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, isFinalDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(42 - day); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, setValue: function (ob) { @@ -65857,14 +65855,14 @@ BI.Calendar = BI.inherit(BI.Widget, { BI.extend(BI.Calendar, { getPageByDateJSON: function (json) { - var year = Date.getDate().getFullYear(); - var month = Date.getDate().getMonth(); + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); var page = (json.year - year) * 12; page += json.month - month; return page; }, getDateJSONByPage: function (v) { - var months = Date.getDate().getMonth(); + var months = BI.getDate().getMonth(); var page = v; // 对当前page做偏移,使到当前年初 @@ -65876,7 +65874,7 @@ BI.extend(BI.Calendar, { } var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); return { - year: Date.getDate().getFullYear() + year, + year: BI.getDate().getFullYear() + year, month: month }; } @@ -65910,7 +65908,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var items = []; BI.each(BI.range(BI.YearCalendar.INTERVAL), function (i) { var td = {}; - if (Date.checkVoid(start + i, 1, 1, o.min, o.max)[0]) { + if (BI.checkDateVoid(start + i, 1, 1, o.min, o.max)[0]) { td.disabled = true; } td.text = start + i; @@ -65922,7 +65920,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { _init: function () { BI.YearCalendar.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.currentYear = Date.getDate().getFullYear(); + this.currentYear = BI.getDate().getFullYear(); var years = this._yearCreator(o.year || this.currentYear); // 纵向排列年 @@ -65985,14 +65983,14 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var o = this.options; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; }, isFinalYear: function () { var o = this.options, c = this._const; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; }, setValue: function (val) { @@ -66009,7 +66007,7 @@ BI.extend(BI.YearCalendar, { // 获取显示的第一年 getStartYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); return year - ((year - cur + 3) % BI.YearCalendar.INTERVAL + 12) % BI.YearCalendar.INTERVAL; }, @@ -66018,7 +66016,7 @@ BI.extend(BI.YearCalendar, { }, getPageByYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); year = BI.YearCalendar.getStartYear(year); return (year - cur + 3) / BI.YearCalendar.INTERVAL; } @@ -79091,8 +79089,8 @@ BI.DatePicker = BI.inherit(BI.Widget, { _init: function () { BI.DatePicker.superclass._init.apply(this, arguments); var self = this, o = this.options; - this._year = Date.getDate().getFullYear(); - this._month = Date.getDate().getMonth(); + this._year = BI.getDate().getFullYear(); + this._month = BI.getDate().getMonth(); this.left = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", @@ -79189,14 +79187,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === Date.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === Date.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, @@ -79256,7 +79254,7 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { BI.DateCalendarPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); this._day = this.today.getDate(); @@ -79469,7 +79467,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge validationChecker: function (v) { var date = v.match(/\d+/g); self._autoAppend(v, date); - return self._dateCheck(v) && Date.checkLegal(v) && self._checkVoid({ + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ year: date[0], month: date[1], day: date[2] @@ -79547,21 +79545,21 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge this.setValue(o.value); }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; }, _autoAppend: function (v, dateObj) { var self = this; - var date = Date.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); var yearCheck = function (v) { - return Date.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; }; var monthCheck = function (v) { - return Date.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; }; - if (BI.isNotNull(dateObj) && Date.checkLegal(v)) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { switch (v.length) { case this._const.yearLength: if (yearCheck(v)) { @@ -79579,7 +79577,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge setValue: function (v) { var type, value, self = this; - var date = Date.getDate(); + var date = BI.getDate(); this.store_value = v; if (BI.isNotNull(v)) { type = v.type || BI.DateTrigger.MULTI_DATE_CALENDAR; value = v.value; @@ -79596,62 +79594,62 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge switch (type) { case BI.DateTrigger.MULTI_DATE_YEAR_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV]; - date = Date.getDate((date.getFullYear() - 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() - 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER]; - date = Date.getDate((date.getFullYear() + 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() + 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN]; - date = Date.getDate(date.getFullYear(), 0, 1); + date = BI.getDate(date.getFullYear(), 0, 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END]; - date = Date.getDate(date.getFullYear(), 11, 31); + date = BI.getDate(date.getFullYear(), 11, 31); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV]; - date = Date.getDate().getBeforeMulQuarter(value); + date = BI.getDate().getBeforeMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER]; - date = Date.getDate().getAfterMulQuarter(value); + date = BI.getDate().getAfterMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN]; - date = Date.getDate().getQuarterStartDate(); + date = BI.getDate().getQuarterStartDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END]; - date = Date.getDate().getQuarterEndDate(); + date = BI.getDate().getQuarterEndDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV]; - date = Date.getDate().getBeforeMultiMonth(value); + date = BI.getDate().getBeforeMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER]; - date = Date.getDate().getAfterMultiMonth(value); + date = BI.getDate().getAfterMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN]; - date = Date.getDate(date.getFullYear(), date.getMonth(), 1); + date = BI.getDate(date.getFullYear(), date.getMonth(), 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END]; - date = Date.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + date = BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_WEEK_PREV: @@ -79676,7 +79674,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge break; case BI.DateTrigger.MULTI_DATE_DAY_TODAY: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY]; - date = Date.getDate(); + date = BI.getDate(); _setInnerValue(date, text); break; default: @@ -79777,7 +79775,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { BI.DatePaneWidget.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); @@ -79842,7 +79840,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }, _getNewCurrentDate: function () { - var today = Date.getDate(); + var today = BI.getDate(); return { year: today.getFullYear(), month: today.getMonth() @@ -79904,11 +79902,11 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { _init: function () { BI.DateTimeCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = BI.isNotNull(opts.value) ? opts.value : { year: date.getFullYear(), month: date.getMonth(), - day: date.getDate(), + day: BI.getDate(), hour: date.getHours(), minute: date.getMinutes(), second: date.getSeconds() @@ -80147,11 +80145,11 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { setValue: function (v) { var value = v, date; if (BI.isNull(value)) { - date = Date.getDate(); + date = BI.getDate(); this.dateCombo.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.hour.setValue(date.getHours()); this.minute.setValue(date.getMinutes()); @@ -80338,10 +80336,10 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { var self = this; var value = v, dateStr; if(BI.isNull(value)) { - value = Date.getDate(); + value = BI.getDate(); dateStr = value.print("%Y-%X-%d %H:%M:%S"); } else { - var date = Date.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); + var date = BI.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); dateStr = date.print("%Y-%X-%d %H:%M:%S"); } @@ -83140,39 +83138,39 @@ BI.MultiDateCard = BI.inherit(BI.Widget, { var type = valueObject.type, value = valueObject.value; switch (type) { case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return Date.getDate().getOffsetDate(-1 * value); + return BI.getDate().getOffsetDate(-1 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return Date.getDate().getOffsetDate(value); + return BI.getDate().getOffsetDate(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return Date.getDate(); + return BI.getDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return Date.getDate().getBeforeMultiMonth(value); + return BI.getDate().getBeforeMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return Date.getDate().getAfterMultiMonth(value); + return BI.getDate().getAfterMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), 1); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), (Date.getDate().getLastDateOfMonth()).getDate()); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return Date.getDate().getBeforeMulQuarter(value); + return BI.getDate().getBeforeMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return Date.getDate().getAfterMulQuarter(value); + return BI.getDate().getAfterMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return Date.getDate().getQuarterStartDate(); + return BI.getDate().getQuarterStartDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return Date.getDate().getQuarterEndDate(); + return BI.getDate().getQuarterEndDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return Date.getDate().getOffsetDate(-7 * value); + return BI.getDate().getOffsetDate(-7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return Date.getDate().getOffsetDate(7 * value); + return BI.getDate().getOffsetDate(7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return Date.getDate((Date.getDate().getFullYear() - 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return Date.getDate((Date.getDate().getFullYear() + 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), 0, 1); + return BI.getDate(BI.getDate().getFullYear(), 0, 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return Date.getDate(Date.getDate().getFullYear(), 11, 31); + return BI.getDate(BI.getDate().getFullYear(), 11, 31); } } }); @@ -83201,7 +83199,7 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { BI.MultiDateCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; this.storeTriggerValue = ""; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = opts.value; this.trigger = BI.createWidget({ type: "bi.date_trigger", @@ -83270,11 +83268,11 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); }); this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = Date.getDate(); + var date = BI.getDate(); self.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self.combo.hideView(); self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); @@ -83714,7 +83712,7 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { self.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self._setInnerValue(self.ymd); break; @@ -83829,12 +83827,12 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { break; default: if (this._checkValueValid(value)) { - var date = Date.getDate(); + var date = BI.getDate(); this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); this.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); } else { @@ -95848,26 +95846,26 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, _check: function (smallDate, bigDate) { var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); - return this._dateCheck(smallDate) && Date.checkLegal(smallDate) && this._checkVoid({ + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ year: smallObj[0], month: smallObj[1], day: smallObj[2] - }) && this._dateCheck(bigDate) && Date.checkLegal(bigDate) && this._checkVoid({ + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ year: bigObj[0], month: bigObj[1], day: bigObj[2] }); }, _compare: function (smallDate, bigDate) { - smallDate = Date.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = Date.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { @@ -96035,7 +96033,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { BI.YearPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.selectedYear = this._year = Date.getDate().getFullYear(); + this.selectedYear = this._year = BI.getDate().getFullYear(); var backBtn = BI.createWidget({ type: "bi.icon_button", @@ -96092,8 +96090,8 @@ BI.YearPopup = BI.inherit(BI.Widget, { setValue: function (v) { var o = this.options; - if (Date.checkVoid(v, 1, 1, o.min, o.max)[0]) { - v = Date.getDate().getFullYear(); + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); this.selectedYear = ""; this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); this.navigation.setValue(""); @@ -96136,7 +96134,7 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { height: o.height, validationChecker: function (v) { self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !Date.checkVoid(v, 1, 1, o.min, o.max)[0]); + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); }, quitChecker: function (v) { return false; diff --git a/dist/widget.js b/dist/widget.js index 2f8a1840f..8913157f9 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -561,8 +561,8 @@ BI.DatePicker = BI.inherit(BI.Widget, { _init: function () { BI.DatePicker.superclass._init.apply(this, arguments); var self = this, o = this.options; - this._year = Date.getDate().getFullYear(); - this._month = Date.getDate().getMonth(); + this._year = BI.getDate().getFullYear(); + this._month = BI.getDate().getMonth(); this.left = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", @@ -659,14 +659,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === Date.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === Date.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, @@ -726,7 +726,7 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { BI.DateCalendarPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); this._day = this.today.getDate(); @@ -939,7 +939,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge validationChecker: function (v) { var date = v.match(/\d+/g); self._autoAppend(v, date); - return self._dateCheck(v) && Date.checkLegal(v) && self._checkVoid({ + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ year: date[0], month: date[1], day: date[2] @@ -1017,21 +1017,21 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge this.setValue(o.value); }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; }, _autoAppend: function (v, dateObj) { var self = this; - var date = Date.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); var yearCheck = function (v) { - return Date.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; }; var monthCheck = function (v) { - return Date.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; }; - if (BI.isNotNull(dateObj) && Date.checkLegal(v)) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { switch (v.length) { case this._const.yearLength: if (yearCheck(v)) { @@ -1049,7 +1049,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge setValue: function (v) { var type, value, self = this; - var date = Date.getDate(); + var date = BI.getDate(); this.store_value = v; if (BI.isNotNull(v)) { type = v.type || BI.DateTrigger.MULTI_DATE_CALENDAR; value = v.value; @@ -1066,62 +1066,62 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge switch (type) { case BI.DateTrigger.MULTI_DATE_YEAR_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV]; - date = Date.getDate((date.getFullYear() - 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() - 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER]; - date = Date.getDate((date.getFullYear() + 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() + 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN]; - date = Date.getDate(date.getFullYear(), 0, 1); + date = BI.getDate(date.getFullYear(), 0, 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END]; - date = Date.getDate(date.getFullYear(), 11, 31); + date = BI.getDate(date.getFullYear(), 11, 31); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV]; - date = Date.getDate().getBeforeMulQuarter(value); + date = BI.getDate().getBeforeMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER]; - date = Date.getDate().getAfterMulQuarter(value); + date = BI.getDate().getAfterMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN]; - date = Date.getDate().getQuarterStartDate(); + date = BI.getDate().getQuarterStartDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END]; - date = Date.getDate().getQuarterEndDate(); + date = BI.getDate().getQuarterEndDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV]; - date = Date.getDate().getBeforeMultiMonth(value); + date = BI.getDate().getBeforeMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER]; - date = Date.getDate().getAfterMultiMonth(value); + date = BI.getDate().getAfterMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN]; - date = Date.getDate(date.getFullYear(), date.getMonth(), 1); + date = BI.getDate(date.getFullYear(), date.getMonth(), 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END]; - date = Date.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + date = BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_WEEK_PREV: @@ -1146,7 +1146,7 @@ BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigge break; case BI.DateTrigger.MULTI_DATE_DAY_TODAY: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY]; - date = Date.getDate(); + date = BI.getDate(); _setInnerValue(date, text); break; default: @@ -1247,7 +1247,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { BI.DatePaneWidget.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); @@ -1312,7 +1312,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }, _getNewCurrentDate: function () { - var today = Date.getDate(); + var today = BI.getDate(); return { year: today.getFullYear(), month: today.getMonth() @@ -1374,11 +1374,11 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { _init: function () { BI.DateTimeCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = BI.isNotNull(opts.value) ? opts.value : { year: date.getFullYear(), month: date.getMonth(), - day: date.getDate(), + day: BI.getDate(), hour: date.getHours(), minute: date.getMinutes(), second: date.getSeconds() @@ -1617,11 +1617,11 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { setValue: function (v) { var value = v, date; if (BI.isNull(value)) { - date = Date.getDate(); + date = BI.getDate(); this.dateCombo.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.hour.setValue(date.getHours()); this.minute.setValue(date.getMinutes()); @@ -1808,10 +1808,10 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { var self = this; var value = v, dateStr; if(BI.isNull(value)) { - value = Date.getDate(); + value = BI.getDate(); dateStr = value.print("%Y-%X-%d %H:%M:%S"); } else { - var date = Date.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); + var date = BI.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); dateStr = date.print("%Y-%X-%d %H:%M:%S"); } @@ -4610,39 +4610,39 @@ BI.MultiDateCard = BI.inherit(BI.Widget, { var type = valueObject.type, value = valueObject.value; switch (type) { case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return Date.getDate().getOffsetDate(-1 * value); + return BI.getDate().getOffsetDate(-1 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return Date.getDate().getOffsetDate(value); + return BI.getDate().getOffsetDate(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return Date.getDate(); + return BI.getDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return Date.getDate().getBeforeMultiMonth(value); + return BI.getDate().getBeforeMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return Date.getDate().getAfterMultiMonth(value); + return BI.getDate().getAfterMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), 1); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), (Date.getDate().getLastDateOfMonth()).getDate()); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return Date.getDate().getBeforeMulQuarter(value); + return BI.getDate().getBeforeMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return Date.getDate().getAfterMulQuarter(value); + return BI.getDate().getAfterMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return Date.getDate().getQuarterStartDate(); + return BI.getDate().getQuarterStartDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return Date.getDate().getQuarterEndDate(); + return BI.getDate().getQuarterEndDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return Date.getDate().getOffsetDate(-7 * value); + return BI.getDate().getOffsetDate(-7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return Date.getDate().getOffsetDate(7 * value); + return BI.getDate().getOffsetDate(7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return Date.getDate((Date.getDate().getFullYear() - 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return Date.getDate((Date.getDate().getFullYear() + 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), 0, 1); + return BI.getDate(BI.getDate().getFullYear(), 0, 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return Date.getDate(Date.getDate().getFullYear(), 11, 31); + return BI.getDate(BI.getDate().getFullYear(), 11, 31); } } }); @@ -4671,7 +4671,7 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { BI.MultiDateCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; this.storeTriggerValue = ""; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = opts.value; this.trigger = BI.createWidget({ type: "bi.date_trigger", @@ -4740,11 +4740,11 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); }); this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = Date.getDate(); + var date = BI.getDate(); self.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self.combo.hideView(); self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); @@ -5184,7 +5184,7 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { self.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self._setInnerValue(self.ymd); break; @@ -5299,12 +5299,12 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { break; default: if (this._checkValueValid(value)) { - var date = Date.getDate(); + var date = BI.getDate(); this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); this.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); } else { @@ -17318,26 +17318,26 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, _check: function (smallDate, bigDate) { var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); - return this._dateCheck(smallDate) && Date.checkLegal(smallDate) && this._checkVoid({ + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ year: smallObj[0], month: smallObj[1], day: smallObj[2] - }) && this._dateCheck(bigDate) && Date.checkLegal(bigDate) && this._checkVoid({ + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ year: bigObj[0], month: bigObj[1], day: bigObj[2] }); }, _compare: function (smallDate, bigDate) { - smallDate = Date.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = Date.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { @@ -17505,7 +17505,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { BI.YearPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.selectedYear = this._year = Date.getDate().getFullYear(); + this.selectedYear = this._year = BI.getDate().getFullYear(); var backBtn = BI.createWidget({ type: "bi.icon_button", @@ -17562,8 +17562,8 @@ BI.YearPopup = BI.inherit(BI.Widget, { setValue: function (v) { var o = this.options; - if (Date.checkVoid(v, 1, 1, o.min, o.max)[0]) { - v = Date.getDate().getFullYear(); + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); this.selectedYear = ""; this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); this.navigation.setValue(""); @@ -17606,7 +17606,7 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { height: o.height, validationChecker: function (v) { self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !Date.checkVoid(v, 1, 1, o.min, o.max)[0]); + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); }, quitChecker: function (v) { return false; diff --git a/src/case/calendar/calendar.js b/src/case/calendar/calendar.js index 7fe778a01..7e0fd0c87 100644 --- a/src/case/calendar/calendar.js +++ b/src/case/calendar/calendar.js @@ -20,7 +20,7 @@ BI.Calendar = BI.inherit(BI.Widget, { }, _dateCreator: function (Y, M, D) { - var self = this, o = this.options, log = {}, De = Date.getDate(); + var self = this, o = this.options, log = {}, De = BI.getDate(); var mins = o.min.match(/\d+/g); var maxs = o.max.match(/\d+/g); Y < (mins[0] | 0) && (Y = (mins[0] | 0)); @@ -30,7 +30,7 @@ BI.Calendar = BI.inherit(BI.Widget, { log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(log.ymd[0]) ? 29 : 28; + MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; De.setFullYear(log.ymd[0], log.ymd[1], 1); log.FDay = De.getDay(); @@ -57,7 +57,7 @@ BI.Calendar = BI.inherit(BI.Widget, { MM === 12 && (YY += 1); MM = MM === 12 ? 1 : MM + 1; } - if (Date.checkVoid(YY, MM, DD, mins, maxs)[0]) { + if (BI.checkDateVoid(YY, MM, DD, mins, maxs)[0]) { td.disabled = true; } td.text = DD; @@ -130,20 +130,20 @@ BI.Calendar = BI.inherit(BI.Widget, { isFrontDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(-1 * (day + 1)); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, isFinalDate: function () { var o = this.options, c = this._const; - var Y = o.year, M = o.month, De = Date.getDate(), day = De.getDay(); + var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); Y = Y | 0; De.setFullYear(Y, M, 1); var newDate = De.getOffsetDate(42 - day); - return !!Date.checkVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; + return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, setValue: function (ob) { @@ -162,14 +162,14 @@ BI.Calendar = BI.inherit(BI.Widget, { BI.extend(BI.Calendar, { getPageByDateJSON: function (json) { - var year = Date.getDate().getFullYear(); - var month = Date.getDate().getMonth(); + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); var page = (json.year - year) * 12; page += json.month - month; return page; }, getDateJSONByPage: function (v) { - var months = Date.getDate().getMonth(); + var months = BI.getDate().getMonth(); var page = v; // 对当前page做偏移,使到当前年初 @@ -181,7 +181,7 @@ BI.extend(BI.Calendar, { } var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); return { - year: Date.getDate().getFullYear() + year, + year: BI.getDate().getFullYear() + year, month: month }; } diff --git a/src/case/calendar/calendar.year.js b/src/case/calendar/calendar.year.js index 8a20eb177..910981ae5 100644 --- a/src/case/calendar/calendar.year.js +++ b/src/case/calendar/calendar.year.js @@ -26,7 +26,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var items = []; BI.each(BI.range(BI.YearCalendar.INTERVAL), function (i) { var td = {}; - if (Date.checkVoid(start + i, 1, 1, o.min, o.max)[0]) { + if (BI.checkDateVoid(start + i, 1, 1, o.min, o.max)[0]) { td.disabled = true; } td.text = start + i; @@ -38,7 +38,7 @@ BI.YearCalendar = BI.inherit(BI.Widget, { _init: function () { BI.YearCalendar.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.currentYear = Date.getDate().getFullYear(); + this.currentYear = BI.getDate().getFullYear(); var years = this._yearCreator(o.year || this.currentYear); // 纵向排列年 @@ -101,14 +101,14 @@ BI.YearCalendar = BI.inherit(BI.Widget, { var o = this.options; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0]; }, isFinalYear: function () { var o = this.options, c = this._const; var Y = o.year; Y = Y | 0; - return !!Date.checkVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; + return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; }, setValue: function (val) { @@ -125,7 +125,7 @@ BI.extend(BI.YearCalendar, { // 获取显示的第一年 getStartYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); return year - ((year - cur + 3) % BI.YearCalendar.INTERVAL + 12) % BI.YearCalendar.INTERVAL; }, @@ -134,7 +134,7 @@ BI.extend(BI.YearCalendar, { }, getPageByYear: function (year) { - var cur = Date.getDate().getFullYear(); + var cur = BI.getDate().getFullYear(); year = BI.YearCalendar.getStartYear(year); return (year - cur + 3) / BI.YearCalendar.INTERVAL; } diff --git a/src/core/alias.js b/src/core/alias.js index 3cd43c9f9..5de03ebc6 100644 --- a/src/core/alias.js +++ b/src/core/alias.js @@ -154,7 +154,7 @@ if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = String.leftPad(newnum, orilen, "0"); + newnum = BI.leftPad(newnum, orilen, "0"); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -497,6 +497,8 @@ text = _eFormat(text, fmt); } else { // 数字格式 + var s = []; + BI.clamp(s); text = _numberFormat(text, fmt); } // ¤ - 货币格式 @@ -566,14 +568,14 @@ } else if (len < 2) { str = date.getMonth() + 1; } else { - str = String.leftPad(date.getMonth() + 1 + "", 2, "0"); + str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); } break; case "d": // 日 if (len > 1) { - str = String.leftPad(date.getDate() + "", 2, "0"); + str = BI.leftPad(BI.getDate() + "", 2, "0"); } else { - str = date.getDate(); + str = BI.getDate(); } break; case "h": // 时(12) @@ -582,28 +584,28 @@ hour = 12; } if (len > 1) { - str = String.leftPad(hour + "", 2, "0"); + str = BI.leftPad(hour + "", 2, "0"); } else { str = hour; } break; case "H": // 时(24) if (len > 1) { - str = String.leftPad(date.getHours() + "", 2, "0"); + str = BI.leftPad(date.getHours() + "", 2, "0"); } else { str = date.getHours(); } break; case "m": if (len > 1) { - str = String.leftPad(date.getMinutes() + "", 2, "0"); + str = BI.leftPad(date.getMinutes() + "", 2, "0"); } else { str = date.getMinutes(); } break; case "s": if (len > 1) { - str = String.leftPad(date.getSeconds() + "", 2, "0"); + str = BI.leftPad(date.getSeconds() + "", 2, "0"); } else { str = date.getSeconds(); } diff --git a/src/core/base.js b/src/core/base.js index 09b2caea8..6b7d5e4f6 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -545,7 +545,7 @@ if (!window.BI) { // Date if (type === "[object Date]") { - return Date.getDate(obj.getTime()); + return BI.getDate(obj.getTime()); } var i, clone, key; @@ -781,7 +781,7 @@ if (!window.BI) { if (Date.now) { return Date.now(); } - return Date.getDate().getTime(); + return BI.getDate().getTime(); @@ -1045,6 +1045,357 @@ if (!window.BI) { prand = (mult * prand + incr) % modu; } return unescape(enc_str); + }, + + /** + * 对字符串中的'和\做编码处理 + * @static + * @param {String} string 要做编码处理的字符串 + * @return {String} 编码后的字符串 + */ + escape: function (string) { + return string.replace(/('|\\)/g, "\\$1"); + }, + + /** + * 让字符串通过指定字符做补齐的函数 + * + * var s = BI.leftPad('123', 5, '0');//s的值为:'00123' + * + * @static + * @param {String} val 原始值 + * @param {Number} size 总共需要的位数 + * @param {String} ch 用于补齐的字符 + * @return {String} 补齐后的字符串 + */ + leftPad: function (val, size, ch) { + var result = String(val); + if (!ch) { + ch = " "; + } + while (result.length < size) { + result = ch + result; + } + return result.toString(); + }, + + /** + * 对字符串做替换的函数 + * + * var cls = 'my-class', text = 'Some text'; + * var res = BI.format('
Some text
'; + * + * @static + * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... + * @return {String} 做了替换后的字符串 + */ + format: function (format) { + var args = Array.prototype.slice.call(arguments, 1); + return format.replace(/\{(\d+)\}/g, function (m, i) { + return args[i]; + }); + } + }); + + // 日期相关方法 + _.extend(BI, { + /** + * 是否是闰年 + * @param year + * @returns {boolean} + */ + isLeapYear: function (year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + /** + * 检测是否在有效期 + * + * @param YY 年 + * @param MM 月 + * @param DD 日 + * @param minDate '1900-01-01' + * @param maxDate '2099-12-31' + * @returns {Array} 若无效返回无效状态 + */ + checkDateVoid: function (YY, MM, DD, minDate, maxDate) { + var back = []; + YY = YY | 0; + MM = MM | 0; + DD = DD | 0; + minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; + maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; + if (YY < minDate[0]) { + back = ["y"]; + } else if (YY > maxDate[0]) { + back = ["y", 1]; + } else if (YY >= minDate[0] && YY <= maxDate[0]) { + if (YY == minDate[0]) { + if (MM < minDate[1]) { + back = ["m"]; + } else if (MM == minDate[1]) { + if (DD < minDate[2]) { + back = ["d"]; + } + } + } + if (YY == maxDate[0]) { + if (MM > maxDate[1]) { + back = ["m", 1]; + } else if (MM == maxDate[1]) { + if (DD > maxDate[2]) { + back = ["d", 1]; + } + } + } + } + return back; + }, + + checkDateLegal: function (str) { + var ar = str.match(/\d+/g); + var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; + if (ar.length <= 1) { + return true; + } + if (ar.length <= 2) { + return MM >= 1 && MM <= 12; + } + var MD = Date._MD.slice(0); + MD[1] = BI.isLeapYear(YY) ? 29 : 28; + return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; + }, + + parseDateTime: function (str, fmt) { + var today = BI.getDate(); + var y = 0; + var m = 0; + var d = 1; + // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 + var a = str.split(/\W+/); + if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { + var yearlength = 4; + var otherlength = 2; + a[0] = str.substring(0, yearlength); + a[1] = str.substring(yearlength, yearlength + otherlength); + a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); + } + var b = fmt.match(/%./g); + var i = 0, j = 0; + var hr = 0; + var min = 0; + var sec = 0; + for (i = 0; i < a.length; ++i) { + switch (b[i]) { + case "%d": + case "%e": + d = parseInt(a[i], 10); + break; + + case "%X": + m = parseInt(a[i], 10) - 1; + break; + case "%x": + m = parseInt(a[i], 10) - 1; + break; + + case "%Y": + case "%y": + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + break; + + case "%b": + case "%B": + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + m = j; + break; + } + } + break; + + case "%H": + case "%I": + case "%k": + case "%l": + hr = parseInt(a[i], 10); + break; + + case "%P": + case "%p": + if (/pm/i.test(a[i]) && hr < 12) { + hr += 12; + } else if (/am/i.test(a[i]) && hr >= 12) { + hr -= 12; + } + break; + + case "%M": + min = parseInt(a[i], 10); + case "%S": + sec = parseInt(a[i], 10); + break; + } + } + // if (!a[i]) { + // continue; + // } + if (isNaN(y)) { + y = today.getFullYear(); + } + if (isNaN(m)) { + m = today.getMonth(); + } + if (isNaN(d)) { + d = today.getDate(); + } + if (isNaN(hr)) { + hr = today.getHours(); + } + if (isNaN(min)) { + min = today.getMinutes(); + } + if (isNaN(sec)) { + sec = today.getSeconds(); + } + if (y != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + y = 0; + m = -1; + d = 0; + for (i = 0; i < a.length; ++i) { + if (a[i].search(/[a-zA-Z]+/) != -1) { + var t = -1; + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + t = j; + break; + } + } + if (t != -1) { + if (m != -1) { + d = m + 1; + } + m = t; + } + } else if (parseInt(a[i], 10) <= 12 && m == -1) { + m = a[i] - 1; + } else if (parseInt(a[i], 10) > 31 && y == 0) { + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + } else if (d == 0) { + d = a[i]; + } + } + if (y == 0) { + y = today.getFullYear(); + } + if (m != -1 && d != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + return today; + }, + + getDate: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { + var localTime = dt.getTime(); + var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 + var utc = localTime + localOffset; // utc即GMT时间标准时区 + return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); + } + return dt; + + }, + + getTime: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone)) { + return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; + } + return dt.getTime(); + } }); diff --git a/src/core/proto/date.js b/src/core/proto/date.js index 67d29437f..fc305cf14 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -32,20 +32,20 @@ Date.prototype.getMonthDays = function (month) { * @returns {Date} */ Date.prototype.getLastDateOfMonth = function () { - return Date.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); + return BI.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function () { - var now = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var then = Date.getDate(this.getFullYear(), 0, 0, 0, 0, 0); + var now = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var then = BI.getDate(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { - var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var d = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); // 周一是一周第一天 var week = d.getDay() === 0 ? 7 : d.getDay(); // var week = d.getDay(); @@ -69,17 +69,17 @@ Date.prototype.getQuarter = function () { // 离当前时间多少天的时间 Date.prototype.getOffsetDate = function (offset) { - return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); + return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; Date.prototype.getAfterMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n * 3); return dt; }; // 获得n个季度前的日期 Date.prototype.getBeforeMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n * 3); return dt; }; @@ -103,29 +103,29 @@ Date.prototype.getQuarterStartMonth = function () { }; // 获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { - return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); + return BI.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); }; // 得到本季度的结束日期 Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; - return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); + return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; Date.prototype.getAfterMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n | 0); return dt; }; Date.prototype.getBeforeMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n | 0); return dt; }; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); var day = dt.getDate(); - var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); if (day > monthDay) { day = monthDay; } @@ -149,7 +149,7 @@ Date.prototype.getWeekEndDate = function () { Date.prototype.equalsTo = function (date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && - (this.getDate() == date.getDate()) && + (this.getDate() == BI.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes()) && (this.getSeconds() == date.getSeconds())); @@ -157,7 +157,7 @@ Date.prototype.equalsTo = function (date) { /** Set only the year, month, date parts (keep existing time) */ Date.prototype.setDateOnly = function (date) { - var tmp = Date.getDate(date); + var tmp = BI.getDate(date); this.setDate(1); this.setFullYear(tmp.getFullYear()); this.setMonth(tmp.getMonth()); @@ -236,301 +236,3 @@ Date.prototype.print = function (str) { return str; }; - -/** - * 是否是闰年 - * @param year - * @returns {boolean} - */ -Date.isLeap = function (year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; -}; - -/** - * 检测是否在有效期 - * - * @param YY 年 - * @param MM 月 - * @param DD 日 - * @param minDate '1900-01-01' - * @param maxDate '2099-12-31' - * @returns {Array} 若无效返回无效状态 - */ -Date.checkVoid = function (YY, MM, DD, minDate, maxDate) { - var back = []; - YY = YY | 0; - MM = MM | 0; - DD = DD | 0; - minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; - maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; - if (YY < minDate[0]) { - back = ["y"]; - } else if (YY > maxDate[0]) { - back = ["y", 1]; - } else if (YY >= minDate[0] && YY <= maxDate[0]) { - if (YY == minDate[0]) { - if (MM < minDate[1]) { - back = ["m"]; - } else if (MM == minDate[1]) { - if (DD < minDate[2]) { - back = ["d"]; - } - } - } - if (YY == maxDate[0]) { - if (MM > maxDate[1]) { - back = ["m", 1]; - } else if (MM == maxDate[1]) { - if (DD > maxDate[2]) { - back = ["d", 1]; - } - } - } - } - return back; -}; - -Date.checkLegal = function (str) { - var ar = str.match(/\d+/g); - var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; - if (ar.length <= 1) { - return true; - } - if (ar.length <= 2) { - return MM >= 1 && MM <= 12; - } - var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(YY) ? 29 : 28; - return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; -}; - -Date.parseDateTime = function (str, fmt) { - var today = Date.getDate(); - var y = 0; - var m = 0; - var d = 1; - // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 - var a = str.split(/\W+/); - if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { - var yearlength = 4; - var otherlength = 2; - a[0] = str.substring(0, yearlength); - a[1] = str.substring(yearlength, yearlength + otherlength); - a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); - } - var b = fmt.match(/%./g); - var i = 0, j = 0; - var hr = 0; - var min = 0; - var sec = 0; - for (i = 0; i < a.length; ++i) { - switch (b[i]) { - case "%d": - case "%e": - d = parseInt(a[i], 10); - break; - - case "%X": - m = parseInt(a[i], 10) - 1; - break; - case "%x": - m = parseInt(a[i], 10) - 1; - break; - - case "%Y": - case "%y": - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - break; - - case "%b": - case "%B": - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - m = j; - break; - } - } - break; - - case "%H": - case "%I": - case "%k": - case "%l": - hr = parseInt(a[i], 10); - break; - - case "%P": - case "%p": - if (/pm/i.test(a[i]) && hr < 12) { - hr += 12; - } else if (/am/i.test(a[i]) && hr >= 12) { - hr -= 12; - } - break; - - case "%M": - min = parseInt(a[i], 10); - case "%S": - sec = parseInt(a[i], 10); - break; - } - } - // if (!a[i]) { - // continue; - // } - if (isNaN(y)) { - y = today.getFullYear(); - } - if (isNaN(m)) { - m = today.getMonth(); - } - if (isNaN(d)) { - d = today.getDate(); - } - if (isNaN(hr)) { - hr = today.getHours(); - } - if (isNaN(min)) { - min = today.getMinutes(); - } - if (isNaN(sec)) { - sec = today.getSeconds(); - } - if (y != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - y = 0; - m = -1; - d = 0; - for (i = 0; i < a.length; ++i) { - if (a[i].search(/[a-zA-Z]+/) != -1) { - var t = -1; - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - t = j; - break; - } - } - if (t != -1) { - if (m != -1) { - d = m + 1; - } - m = t; - } - } else if (parseInt(a[i], 10) <= 12 && m == -1) { - m = a[i] - 1; - } else if (parseInt(a[i], 10) > 31 && y == 0) { - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - } else if (d == 0) { - d = a[i]; - } - } - if (y == 0) { - y = today.getFullYear(); - } - if (m != -1 && d != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - return today; -}; - -Date.getDate = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { - var localTime = dt.getTime(); - var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 - var utc = localTime + localOffset; // utc即GMT时间标准时区 - return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); - } - return dt; - -}; - -Date.getTime = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone)) { - return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; - } - return dt.getTime(); - -}; diff --git a/src/core/proto/string.js b/src/core/proto/string.js index 07d4ad79a..0cb5619a0 100644 --- a/src/core/proto/string.js +++ b/src/core/proto/string.js @@ -113,61 +113,4 @@ _.extend(String.prototype, { } return location; } -}); - -/** - * 对字符串对象的扩展 - * @class String - */ -_.extend(String, { - - /** - * 对字符串中的'和\做编码处理 - * @static - * @param {String} string 要做编码处理的字符串 - * @return {String} 编码后的字符串 - */ - escape: function (string) { - return string.replace(/('|\\)/g, "\\$1"); - }, - - /** - * 让字符串通过指定字符做补齐的函数 - * - * var s = String.leftPad('123', 5, '0');//s的值为:'00123' - * - * @static - * @param {String} val 原始值 - * @param {Number} size 总共需要的位数 - * @param {String} ch 用于补齐的字符 - * @return {String} 补齐后的字符串 - */ - leftPad: function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; - } - while (result.length < size) { - result = ch + result; - } - return result.toString(); - }, - - /** - * 对字符串做替换的函数 - * - * var cls = 'my-class', text = 'Some text'; - * var res = String.format('
Some text
'; - * - * @static - * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... - * @return {String} 做了替换后的字符串 - */ - format: function (format) { - var args = Array.prototype.slice.call(arguments, 1); - return format.replace(/\{(\d+)\}/g, function (m, i) { - return args[i]; - }); - } }); \ No newline at end of file diff --git a/src/core/utils/cache.js b/src/core/utils/cache.js index 443e94a34..1398514d0 100644 --- a/src/core/utils/cache.js +++ b/src/core/utils/cache.js @@ -51,7 +51,7 @@ BI.Cache = { // 判断是否设置过期时间 if (expiresHours && expiresHours > 0) { var date = new Date(); - date.setTime(date.getTime() + expiresHours * 3600 * 1000); + date.setTime(BI.getTime() + expiresHours * 3600 * 1000); cookieString = cookieString + "; expires=" + date.toGMTString(); } if (path) { @@ -66,7 +66,7 @@ BI.Cache = { }, deleteCookie: function (name, path) { var date = new Date(); - date.setTime(date.getTime() - 10000); + date.setTime(BI.getTime() - 10000); var cookieString = name + "=v; expires=" + date.toGMTString(); if (path) { cookieString = cookieString + "; path=" + path; diff --git a/src/widget/date/calendar/picker.date.js b/src/widget/date/calendar/picker.date.js index 18d42d901..b7684f3c9 100644 --- a/src/widget/date/calendar/picker.date.js +++ b/src/widget/date/calendar/picker.date.js @@ -17,8 +17,8 @@ BI.DatePicker = BI.inherit(BI.Widget, { _init: function () { BI.DatePicker.superclass._init.apply(this, arguments); var self = this, o = this.options; - this._year = Date.getDate().getFullYear(); - this._month = Date.getDate().getMonth(); + this._year = BI.getDate().getFullYear(); + this._month = BI.getDate().getMonth(); this.left = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", @@ -115,14 +115,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === Date.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === Date.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, diff --git a/src/widget/date/calendar/popup.calendar.date.js b/src/widget/date/calendar/popup.calendar.date.js index 99140a2ae..edd1686df 100644 --- a/src/widget/date/calendar/popup.calendar.date.js +++ b/src/widget/date/calendar/popup.calendar.date.js @@ -34,7 +34,7 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { BI.DateCalendarPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); this._day = this.today.getDate(); diff --git a/src/widget/date/trigger.date.js b/src/widget/date/trigger.date.js index 91232a90b..a2b240722 100644 --- a/src/widget/date/trigger.date.js +++ b/src/widget/date/trigger.date.js @@ -23,7 +23,7 @@ BI.DateTrigger = BI.inherit(BI.Trigger, { validationChecker: function (v) { var date = v.match(/\d+/g); self._autoAppend(v, date); - return self._dateCheck(v) && Date.checkLegal(v) && self._checkVoid({ + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ year: date[0], month: date[1], day: date[2] @@ -101,21 +101,21 @@ BI.DateTrigger = BI.inherit(BI.Trigger, { this.setValue(o.value); }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; }, _autoAppend: function (v, dateObj) { var self = this; - var date = Date.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); var yearCheck = function (v) { - return Date.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; }; var monthCheck = function (v) { - return Date.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; }; - if (BI.isNotNull(dateObj) && Date.checkLegal(v)) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { switch (v.length) { case this._const.yearLength: if (yearCheck(v)) { @@ -133,7 +133,7 @@ BI.DateTrigger = BI.inherit(BI.Trigger, { setValue: function (v) { var type, value, self = this; - var date = Date.getDate(); + var date = BI.getDate(); this.store_value = v; if (BI.isNotNull(v)) { type = v.type || BI.DateTrigger.MULTI_DATE_CALENDAR; value = v.value; @@ -150,62 +150,62 @@ BI.DateTrigger = BI.inherit(BI.Trigger, { switch (type) { case BI.DateTrigger.MULTI_DATE_YEAR_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV]; - date = Date.getDate((date.getFullYear() - 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() - 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER]; - date = Date.getDate((date.getFullYear() + 1 * value), date.getMonth(), date.getDate()); + date = BI.getDate((date.getFullYear() + 1 * value), date.getMonth(), BI.getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN]; - date = Date.getDate(date.getFullYear(), 0, 1); + date = BI.getDate(date.getFullYear(), 0, 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_YEAR_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END]; - date = Date.getDate(date.getFullYear(), 11, 31); + date = BI.getDate(date.getFullYear(), 11, 31); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV]; - date = Date.getDate().getBeforeMulQuarter(value); + date = BI.getDate().getBeforeMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER]; - date = Date.getDate().getAfterMulQuarter(value); + date = BI.getDate().getAfterMulQuarter(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN]; - date = Date.getDate().getQuarterStartDate(); + date = BI.getDate().getQuarterStartDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_QUARTER_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END]; - date = Date.getDate().getQuarterEndDate(); + date = BI.getDate().getQuarterEndDate(); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_PREV: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV]; - date = Date.getDate().getBeforeMultiMonth(value); + date = BI.getDate().getBeforeMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_AFTER: var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER]; - date = Date.getDate().getAfterMultiMonth(value); + date = BI.getDate().getAfterMultiMonth(value); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_BEGIN: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN]; - date = Date.getDate(date.getFullYear(), date.getMonth(), 1); + date = BI.getDate(date.getFullYear(), date.getMonth(), 1); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_MONTH_END: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END]; - date = Date.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + date = BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); _setInnerValue(date, text); break; case BI.DateTrigger.MULTI_DATE_WEEK_PREV: @@ -230,7 +230,7 @@ BI.DateTrigger = BI.inherit(BI.Trigger, { break; case BI.DateTrigger.MULTI_DATE_DAY_TODAY: var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY]; - date = Date.getDate(); + date = BI.getDate(); _setInnerValue(date, text); break; default: diff --git a/src/widget/datepane/datepane.js b/src/widget/datepane/datepane.js index b73d96f9c..0ebc2c0c2 100644 --- a/src/widget/datepane/datepane.js +++ b/src/widget/datepane/datepane.js @@ -15,7 +15,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { BI.DatePaneWidget.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.today = Date.getDate(); + this.today = BI.getDate(); this._year = this.today.getFullYear(); this._month = this.today.getMonth(); @@ -80,7 +80,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }, _getNewCurrentDate: function () { - var today = Date.getDate(); + var today = BI.getDate(); return { year: today.getFullYear(), month: today.getMonth() diff --git a/src/widget/datetime/datetime.combo.js b/src/widget/datetime/datetime.combo.js index a34413789..37890d773 100644 --- a/src/widget/datetime/datetime.combo.js +++ b/src/widget/datetime/datetime.combo.js @@ -20,11 +20,11 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { _init: function () { BI.DateTimeCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = BI.isNotNull(opts.value) ? opts.value : { year: date.getFullYear(), month: date.getMonth(), - day: date.getDate(), + day: BI.getDate(), hour: date.getHours(), minute: date.getMinutes(), second: date.getSeconds() diff --git a/src/widget/datetime/datetime.popup.js b/src/widget/datetime/datetime.popup.js index 7137e5d94..d163c1dcf 100644 --- a/src/widget/datetime/datetime.popup.js +++ b/src/widget/datetime/datetime.popup.js @@ -130,11 +130,11 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { setValue: function (v) { var value = v, date; if (BI.isNull(value)) { - date = Date.getDate(); + date = BI.getDate(); this.dateCombo.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.hour.setValue(date.getHours()); this.minute.setValue(date.getMinutes()); diff --git a/src/widget/datetime/datetime.trigger.js b/src/widget/datetime/datetime.trigger.js index b23bc9a1f..bfa69906c 100644 --- a/src/widget/datetime/datetime.trigger.js +++ b/src/widget/datetime/datetime.trigger.js @@ -47,10 +47,10 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { var self = this; var value = v, dateStr; if(BI.isNull(value)) { - value = Date.getDate(); + value = BI.getDate(); dateStr = value.print("%Y-%X-%d %H:%M:%S"); } else { - var date = Date.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); + var date = BI.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); dateStr = date.print("%Y-%X-%d %H:%M:%S"); } diff --git a/src/widget/multidate/abstract.multidate.datepane.js b/src/widget/multidate/abstract.multidate.datepane.js index 0cfb77885..4d4d5ac55 100644 --- a/src/widget/multidate/abstract.multidate.datepane.js +++ b/src/widget/multidate/abstract.multidate.datepane.js @@ -112,39 +112,39 @@ BI.MultiDateCard = BI.inherit(BI.Widget, { var type = valueObject.type, value = valueObject.value; switch (type) { case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return Date.getDate().getOffsetDate(-1 * value); + return BI.getDate().getOffsetDate(-1 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return Date.getDate().getOffsetDate(value); + return BI.getDate().getOffsetDate(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return Date.getDate(); + return BI.getDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return Date.getDate().getBeforeMultiMonth(value); + return BI.getDate().getBeforeMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return Date.getDate().getAfterMultiMonth(value); + return BI.getDate().getAfterMultiMonth(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), 1); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return Date.getDate(Date.getDate().getFullYear(), Date.getDate().getMonth(), (Date.getDate().getLastDateOfMonth()).getDate()); + return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return Date.getDate().getBeforeMulQuarter(value); + return BI.getDate().getBeforeMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return Date.getDate().getAfterMulQuarter(value); + return BI.getDate().getAfterMulQuarter(value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return Date.getDate().getQuarterStartDate(); + return BI.getDate().getQuarterStartDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return Date.getDate().getQuarterEndDate(); + return BI.getDate().getQuarterEndDate(); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return Date.getDate().getOffsetDate(-7 * value); + return BI.getDate().getOffsetDate(-7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return Date.getDate().getOffsetDate(7 * value); + return BI.getDate().getOffsetDate(7 * value); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return Date.getDate((Date.getDate().getFullYear() - 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return Date.getDate((Date.getDate().getFullYear() + 1 * value), Date.getDate().getMonth(), Date.getDate().getDate()); + return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return Date.getDate(Date.getDate().getFullYear(), 0, 1); + return BI.getDate(BI.getDate().getFullYear(), 0, 1); case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return Date.getDate(Date.getDate().getFullYear(), 11, 31); + return BI.getDate(BI.getDate().getFullYear(), 11, 31); } } }); diff --git a/src/widget/multidate/multidate.combo.js b/src/widget/multidate/multidate.combo.js index 6e8625368..d458f5c7e 100644 --- a/src/widget/multidate/multidate.combo.js +++ b/src/widget/multidate/multidate.combo.js @@ -22,7 +22,7 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { BI.MultiDateCombo.superclass._init.apply(this, arguments); var self = this, opts = this.options; this.storeTriggerValue = ""; - var date = Date.getDate(); + var date = BI.getDate(); this.storeValue = opts.value; this.trigger = BI.createWidget({ type: "bi.date_trigger", @@ -91,11 +91,11 @@ BI.MultiDateCombo = BI.inherit(BI.Single, { self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); }); this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = Date.getDate(); + var date = BI.getDate(); self.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self.combo.hideView(); self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); diff --git a/src/widget/multidate/multidate.popup.js b/src/widget/multidate/multidate.popup.js index 307fc48bf..11d1f73cd 100644 --- a/src/widget/multidate/multidate.popup.js +++ b/src/widget/multidate/multidate.popup.js @@ -161,7 +161,7 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { self.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); self._setInnerValue(self.ymd); break; @@ -276,12 +276,12 @@ BI.MultiDatePopup = BI.inherit(BI.Widget, { break; default: if (this._checkValueValid(value)) { - var date = Date.getDate(); + var date = BI.getDate(); this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); this.ymd.setValue({ year: date.getFullYear(), month: date.getMonth(), - day: date.getDate() + day: BI.getDate() }); this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); } else { diff --git a/src/widget/timeinterval/timeinterval.js b/src/widget/timeinterval/timeinterval.js index d81260aed..d0763e50d 100644 --- a/src/widget/timeinterval/timeinterval.js +++ b/src/widget/timeinterval/timeinterval.js @@ -144,26 +144,26 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return Date.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || Date.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || Date.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || Date.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; }, _checkVoid: function (obj) { - return !Date.checkVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, _check: function (smallDate, bigDate) { var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); - return this._dateCheck(smallDate) && Date.checkLegal(smallDate) && this._checkVoid({ + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ year: smallObj[0], month: smallObj[1], day: smallObj[2] - }) && this._dateCheck(bigDate) && Date.checkLegal(bigDate) && this._checkVoid({ + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ year: bigObj[0], month: bigObj[1], day: bigObj[2] }); }, _compare: function (smallDate, bigDate) { - smallDate = Date.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = Date.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { diff --git a/src/widget/year/popup.year.js b/src/widget/year/popup.year.js index 4da3509a9..16e542f48 100644 --- a/src/widget/year/popup.year.js +++ b/src/widget/year/popup.year.js @@ -37,7 +37,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { BI.YearPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.selectedYear = this._year = Date.getDate().getFullYear(); + this.selectedYear = this._year = BI.getDate().getFullYear(); var backBtn = BI.createWidget({ type: "bi.icon_button", @@ -94,8 +94,8 @@ BI.YearPopup = BI.inherit(BI.Widget, { setValue: function (v) { var o = this.options; - if (Date.checkVoid(v, 1, 1, o.min, o.max)[0]) { - v = Date.getDate().getFullYear(); + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); this.selectedYear = ""; this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); this.navigation.setValue(""); diff --git a/src/widget/year/trigger.year.js b/src/widget/year/trigger.year.js index d95d45ff1..da6140337 100644 --- a/src/widget/year/trigger.year.js +++ b/src/widget/year/trigger.year.js @@ -29,7 +29,7 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { height: o.height, validationChecker: function (v) { self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !Date.checkVoid(v, 1, 1, o.min, o.max)[0]); + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); }, quitChecker: function (v) { return false; diff --git a/utils/utils.js b/utils/utils.js index 288aa7856..630d441e0 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -2099,63 +2099,6 @@ _.extend(String.prototype, { return location; } }); - -/** - * 对字符串对象的扩展 - * @class String - */ -_.extend(String, { - - /** - * 对字符串中的'和\做编码处理 - * @static - * @param {String} string 要做编码处理的字符串 - * @return {String} 编码后的字符串 - */ - escape: function (string) { - return string.replace(/('|\\)/g, "\\$1"); - }, - - /** - * 让字符串通过指定字符做补齐的函数 - * - * var s = String.leftPad('123', 5, '0');//s的值为:'00123' - * - * @static - * @param {String} val 原始值 - * @param {Number} size 总共需要的位数 - * @param {String} ch 用于补齐的字符 - * @return {String} 补齐后的字符串 - */ - leftPad: function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; - } - while (result.length < size) { - result = ch + result; - } - return result.toString(); - }, - - /** - * 对字符串做替换的函数 - * - * var cls = 'my-class', text = 'Some text'; - * var res = String.format('
Some text
'; - * - * @static - * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... - * @return {String} 做了替换后的字符串 - */ - format: function (format) { - var args = Array.prototype.slice.call(arguments, 1); - return format.replace(/\{(\d+)\}/g, function (m, i) { - return args[i]; - }); - } -}); /** Constants used for time computations */ Date.SECOND = 1000; Date.MINUTE = 60 * Date.SECOND; @@ -2189,20 +2132,20 @@ Date.prototype.getMonthDays = function (month) { * @returns {Date} */ Date.prototype.getLastDateOfMonth = function () { - return Date.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); + return BI.getDate(this.getFullYear(), this.getMonth(), this.getMonthDays()); }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function () { - var now = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var then = Date.getDate(this.getFullYear(), 0, 0, 0, 0, 0); + var now = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var then = BI.getDate(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { - var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); + var d = BI.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); // 周一是一周第一天 var week = d.getDay() === 0 ? 7 : d.getDay(); // var week = d.getDay(); @@ -2226,17 +2169,17 @@ Date.prototype.getQuarter = function () { // 离当前时间多少天的时间 Date.prototype.getOffsetDate = function (offset) { - return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); + return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; Date.prototype.getAfterMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n * 3); return dt; }; // 获得n个季度前的日期 Date.prototype.getBeforeMulQuarter = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n * 3); return dt; }; @@ -2260,29 +2203,29 @@ Date.prototype.getQuarterStartMonth = function () { }; // 获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { - return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); + return BI.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1); }; // 得到本季度的结束日期 Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; - return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); + return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; Date.prototype.getAfterMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() + n | 0); return dt; }; Date.prototype.getBeforeMultiMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); dt.setMonth(dt.getMonth() - n | 0); return dt; }; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { - var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); + var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); var day = dt.getDate(); - var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); if (day > monthDay) { day = monthDay; } @@ -2306,7 +2249,7 @@ Date.prototype.getWeekEndDate = function () { Date.prototype.equalsTo = function (date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && - (this.getDate() == date.getDate()) && + (this.getDate() == BI.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes()) && (this.getSeconds() == date.getSeconds())); @@ -2314,7 +2257,7 @@ Date.prototype.equalsTo = function (date) { /** Set only the year, month, date parts (keep existing time) */ Date.prototype.setDateOnly = function (date) { - var tmp = Date.getDate(date); + var tmp = BI.getDate(date); this.setDate(1); this.setFullYear(tmp.getFullYear()); this.setMonth(tmp.getMonth()); @@ -2393,304 +2336,6 @@ Date.prototype.print = function (str) { return str; }; - -/** - * 是否是闰年 - * @param year - * @returns {boolean} - */ -Date.isLeap = function (year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; -}; - -/** - * 检测是否在有效期 - * - * @param YY 年 - * @param MM 月 - * @param DD 日 - * @param minDate '1900-01-01' - * @param maxDate '2099-12-31' - * @returns {Array} 若无效返回无效状态 - */ -Date.checkVoid = function (YY, MM, DD, minDate, maxDate) { - var back = []; - YY = YY | 0; - MM = MM | 0; - DD = DD | 0; - minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; - maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; - if (YY < minDate[0]) { - back = ["y"]; - } else if (YY > maxDate[0]) { - back = ["y", 1]; - } else if (YY >= minDate[0] && YY <= maxDate[0]) { - if (YY == minDate[0]) { - if (MM < minDate[1]) { - back = ["m"]; - } else if (MM == minDate[1]) { - if (DD < minDate[2]) { - back = ["d"]; - } - } - } - if (YY == maxDate[0]) { - if (MM > maxDate[1]) { - back = ["m", 1]; - } else if (MM == maxDate[1]) { - if (DD > maxDate[2]) { - back = ["d", 1]; - } - } - } - } - return back; -}; - -Date.checkLegal = function (str) { - var ar = str.match(/\d+/g); - var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; - if (ar.length <= 1) { - return true; - } - if (ar.length <= 2) { - return MM >= 1 && MM <= 12; - } - var MD = Date._MD.slice(0); - MD[1] = Date.isLeap(YY) ? 29 : 28; - return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; -}; - -Date.parseDateTime = function (str, fmt) { - var today = Date.getDate(); - var y = 0; - var m = 0; - var d = 1; - // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 - var a = str.split(/\W+/); - if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { - var yearlength = 4; - var otherlength = 2; - a[0] = str.substring(0, yearlength); - a[1] = str.substring(yearlength, yearlength + otherlength); - a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); - } - var b = fmt.match(/%./g); - var i = 0, j = 0; - var hr = 0; - var min = 0; - var sec = 0; - for (i = 0; i < a.length; ++i) { - switch (b[i]) { - case "%d": - case "%e": - d = parseInt(a[i], 10); - break; - - case "%X": - m = parseInt(a[i], 10) - 1; - break; - case "%x": - m = parseInt(a[i], 10) - 1; - break; - - case "%Y": - case "%y": - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - break; - - case "%b": - case "%B": - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - m = j; - break; - } - } - break; - - case "%H": - case "%I": - case "%k": - case "%l": - hr = parseInt(a[i], 10); - break; - - case "%P": - case "%p": - if (/pm/i.test(a[i]) && hr < 12) { - hr += 12; - } else if (/am/i.test(a[i]) && hr >= 12) { - hr -= 12; - } - break; - - case "%M": - min = parseInt(a[i], 10); - case "%S": - sec = parseInt(a[i], 10); - break; - } - } - // if (!a[i]) { - // continue; - // } - if (isNaN(y)) { - y = today.getFullYear(); - } - if (isNaN(m)) { - m = today.getMonth(); - } - if (isNaN(d)) { - d = today.getDate(); - } - if (isNaN(hr)) { - hr = today.getHours(); - } - if (isNaN(min)) { - min = today.getMinutes(); - } - if (isNaN(sec)) { - sec = today.getSeconds(); - } - if (y != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - y = 0; - m = -1; - d = 0; - for (i = 0; i < a.length; ++i) { - if (a[i].search(/[a-zA-Z]+/) != -1) { - var t = -1; - for (j = 0; j < 12; ++j) { - if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { - t = j; - break; - } - } - if (t != -1) { - if (m != -1) { - d = m + 1; - } - m = t; - } - } else if (parseInt(a[i], 10) <= 12 && m == -1) { - m = a[i] - 1; - } else if (parseInt(a[i], 10) > 31 && y == 0) { - y = parseInt(a[i], 10); - (y < 100) && (y += (y > 29) ? 1900 : 2000); - } else if (d == 0) { - d = a[i]; - } - } - if (y == 0) { - y = today.getFullYear(); - } - if (m != -1 && d != 0) { - return Date.getDate(y, m, d, hr, min, sec); - } - return today; -}; - -Date.getDate = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { - var localTime = dt.getTime(); - var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 - var utc = localTime + localOffset; // utc即GMT时间标准时区 - return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); - } - return dt; - -}; - -Date.getTime = function () { - var length = arguments.length; - var args = arguments; - var dt; - switch (length) { - // new Date() - case 0: - dt = new Date(); - break; - // new Date(long) - case 1: - dt = new Date(args[0]); - break; - // new Date(year, month) - case 2: - dt = new Date(args[0], args[1]); - break; - // new Date(year, month, day) - case 3: - dt = new Date(args[0], args[1], args[2]); - break; - // new Date(year, month, day, hour) - case 4: - dt = new Date(args[0], args[1], args[2], args[3]); - break; - // new Date(year, month, day, hour, minute) - case 5: - dt = new Date(args[0], args[1], args[2], args[3], args[4]); - break; - // new Date(year, month, day, hour, minute, second) - case 6: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - // new Date(year, month, day, hour, minute, second, millisecond) - case 7: - dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - break; - default: - dt = new Date(); - break; - } - if(BI.isNotNull(Date.timeZone)) { - return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; - } - return dt.getTime(); - -}; Function.prototype.before = function (func) { var __self = this; return function () { @@ -3258,7 +2903,7 @@ if (!window.BI) { // Date if (type === "[object Date]") { - return Date.getDate(obj.getTime()); + return BI.getDate(obj.getTime()); } var i, clone, key; @@ -3494,7 +3139,7 @@ if (!window.BI) { if (Date.now) { return Date.now(); } - return Date.getDate().getTime(); + return BI.getDate().getTime(); @@ -3758,6 +3403,357 @@ if (!window.BI) { prand = (mult * prand + incr) % modu; } return unescape(enc_str); + }, + + /** + * 对字符串中的'和\做编码处理 + * @static + * @param {String} string 要做编码处理的字符串 + * @return {String} 编码后的字符串 + */ + escape: function (string) { + return string.replace(/('|\\)/g, "\\$1"); + }, + + /** + * 让字符串通过指定字符做补齐的函数 + * + * var s = BI.leftPad('123', 5, '0');//s的值为:'00123' + * + * @static + * @param {String} val 原始值 + * @param {Number} size 总共需要的位数 + * @param {String} ch 用于补齐的字符 + * @return {String} 补齐后的字符串 + */ + leftPad: function (val, size, ch) { + var result = String(val); + if (!ch) { + ch = " "; + } + while (result.length < size) { + result = ch + result; + } + return result.toString(); + }, + + /** + * 对字符串做替换的函数 + * + * var cls = 'my-class', text = 'Some text'; + * var res = BI.format('
Some text
'; + * + * @static + * @param {String} format 要做替换的字符串,替换字符串1,替换字符串2... + * @return {String} 做了替换后的字符串 + */ + format: function (format) { + var args = Array.prototype.slice.call(arguments, 1); + return format.replace(/\{(\d+)\}/g, function (m, i) { + return args[i]; + }); + } + }); + + // 日期相关方法 + _.extend(BI, { + /** + * 是否是闰年 + * @param year + * @returns {boolean} + */ + isLeapYear: function (year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + /** + * 检测是否在有效期 + * + * @param YY 年 + * @param MM 月 + * @param DD 日 + * @param minDate '1900-01-01' + * @param maxDate '2099-12-31' + * @returns {Array} 若无效返回无效状态 + */ + checkDateVoid: function (YY, MM, DD, minDate, maxDate) { + var back = []; + YY = YY | 0; + MM = MM | 0; + DD = DD | 0; + minDate = BI.isString(minDate) ? minDate.match(/\d+/g) : minDate; + maxDate = BI.isString(maxDate) ? maxDate.match(/\d+/g) : maxDate; + if (YY < minDate[0]) { + back = ["y"]; + } else if (YY > maxDate[0]) { + back = ["y", 1]; + } else if (YY >= minDate[0] && YY <= maxDate[0]) { + if (YY == minDate[0]) { + if (MM < minDate[1]) { + back = ["m"]; + } else if (MM == minDate[1]) { + if (DD < minDate[2]) { + back = ["d"]; + } + } + } + if (YY == maxDate[0]) { + if (MM > maxDate[1]) { + back = ["m", 1]; + } else if (MM == maxDate[1]) { + if (DD > maxDate[2]) { + back = ["d", 1]; + } + } + } + } + return back; + }, + + checkDateLegal: function (str) { + var ar = str.match(/\d+/g); + var YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; + if (ar.length <= 1) { + return true; + } + if (ar.length <= 2) { + return MM >= 1 && MM <= 12; + } + var MD = Date._MD.slice(0); + MD[1] = BI.isLeapYear(YY) ? 29 : 28; + return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; + }, + + parseDateTime: function (str, fmt) { + var today = BI.getDate(); + var y = 0; + var m = 0; + var d = 1; + // wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。 + var a = str.split(/\W+/); + if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { + var yearlength = 4; + var otherlength = 2; + a[0] = str.substring(0, yearlength); + a[1] = str.substring(yearlength, yearlength + otherlength); + a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); + } + var b = fmt.match(/%./g); + var i = 0, j = 0; + var hr = 0; + var min = 0; + var sec = 0; + for (i = 0; i < a.length; ++i) { + switch (b[i]) { + case "%d": + case "%e": + d = parseInt(a[i], 10); + break; + + case "%X": + m = parseInt(a[i], 10) - 1; + break; + case "%x": + m = parseInt(a[i], 10) - 1; + break; + + case "%Y": + case "%y": + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + break; + + case "%b": + case "%B": + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + m = j; + break; + } + } + break; + + case "%H": + case "%I": + case "%k": + case "%l": + hr = parseInt(a[i], 10); + break; + + case "%P": + case "%p": + if (/pm/i.test(a[i]) && hr < 12) { + hr += 12; + } else if (/am/i.test(a[i]) && hr >= 12) { + hr -= 12; + } + break; + + case "%M": + min = parseInt(a[i], 10); + case "%S": + sec = parseInt(a[i], 10); + break; + } + } + // if (!a[i]) { + // continue; + // } + if (isNaN(y)) { + y = today.getFullYear(); + } + if (isNaN(m)) { + m = today.getMonth(); + } + if (isNaN(d)) { + d = today.getDate(); + } + if (isNaN(hr)) { + hr = today.getHours(); + } + if (isNaN(min)) { + min = today.getMinutes(); + } + if (isNaN(sec)) { + sec = today.getSeconds(); + } + if (y != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + y = 0; + m = -1; + d = 0; + for (i = 0; i < a.length; ++i) { + if (a[i].search(/[a-zA-Z]+/) != -1) { + var t = -1; + for (j = 0; j < 12; ++j) { + if (Date._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { + t = j; + break; + } + } + if (t != -1) { + if (m != -1) { + d = m + 1; + } + m = t; + } + } else if (parseInt(a[i], 10) <= 12 && m == -1) { + m = a[i] - 1; + } else if (parseInt(a[i], 10) > 31 && y == 0) { + y = parseInt(a[i], 10); + (y < 100) && (y += (y > 29) ? 1900 : 2000); + } else if (d == 0) { + d = a[i]; + } + } + if (y == 0) { + y = today.getFullYear(); + } + if (m != -1 && d != 0) { + return BI.getDate(y, m, d, hr, min, sec); + } + return today; + }, + + getDate: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { + var localTime = dt.getTime(); + var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 + var utc = localTime + localOffset; // utc即GMT时间标准时区 + return new Date(utc + Date.timeZone);// + Pool.timeZone.offset); + } + return dt; + + }, + + getTime: function () { + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } + if (BI.isNotNull(Date.timeZone)) { + return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; + } + return dt.getTime(); + } }); @@ -4182,7 +4178,7 @@ _.extend(BI.OB.prototype, { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = String.leftPad(newnum, orilen, "0"); + newnum = BI.leftPad(newnum, orilen, "0"); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -4525,6 +4521,8 @@ _.extend(BI.OB.prototype, { text = _eFormat(text, fmt); } else { // 数字格式 + var s = []; + BI.clamp(s); text = _numberFormat(text, fmt); } // ¤ - 货币格式 @@ -4594,14 +4592,14 @@ _.extend(BI.OB.prototype, { } else if (len < 2) { str = date.getMonth() + 1; } else { - str = String.leftPad(date.getMonth() + 1 + "", 2, "0"); + str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); } break; case "d": // 日 if (len > 1) { - str = String.leftPad(date.getDate() + "", 2, "0"); + str = BI.leftPad(BI.getDate() + "", 2, "0"); } else { - str = date.getDate(); + str = BI.getDate(); } break; case "h": // 时(12) @@ -4610,28 +4608,28 @@ _.extend(BI.OB.prototype, { hour = 12; } if (len > 1) { - str = String.leftPad(hour + "", 2, "0"); + str = BI.leftPad(hour + "", 2, "0"); } else { str = hour; } break; case "H": // 时(24) if (len > 1) { - str = String.leftPad(date.getHours() + "", 2, "0"); + str = BI.leftPad(date.getHours() + "", 2, "0"); } else { str = date.getHours(); } break; case "m": if (len > 1) { - str = String.leftPad(date.getMinutes() + "", 2, "0"); + str = BI.leftPad(date.getMinutes() + "", 2, "0"); } else { str = date.getMinutes(); } break; case "s": if (len > 1) { - str = String.leftPad(date.getSeconds() + "", 2, "0"); + str = BI.leftPad(date.getSeconds() + "", 2, "0"); } else { str = date.getSeconds(); } @@ -5134,7 +5132,7 @@ BI.Cache = { // 判断是否设置过期时间 if (expiresHours && expiresHours > 0) { var date = new Date(); - date.setTime(date.getTime() + expiresHours * 3600 * 1000); + date.setTime(BI.getTime() + expiresHours * 3600 * 1000); cookieString = cookieString + "; expires=" + date.toGMTString(); } if (path) { @@ -5149,7 +5147,7 @@ BI.Cache = { }, deleteCookie: function (name, path) { var date = new Date(); - date.setTime(date.getTime() - 10000); + date.setTime(BI.getTime() - 10000); var cookieString = name + "=v; expires=" + date.toGMTString(); if (path) { cookieString = cookieString + "; path=" + path;