Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对象初始化完成后,通过对象修改format后不生效 #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/laydate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,35 @@
: (options.range ? lay.extend({}, that.startDate, that.startTime) : options.dateTime))
,format = that.format.concat();

//#region 因为that.config可能被外部改变了,所以这里需要根据options.format重新生成正则表达式和返回结果的格式 by 凌云 2018-08-02
that.EXP_IF = '';
that.EXP_SPLIT = '';
var dateType = 'yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s';
format = options.format.match(new RegExp(dateType + '|.', 'g')) || [];
that.format = format;
lay.each(that.format, function(i, item) {
var EXP = new RegExp(dateType).test(item) ?
'\\d{' + function() {
if (new RegExp(dateType).test(that.format[i === 0 ? i + 1 : i - 1] || '')) {
if (/^yyyy|y$/.test(item)) return 4;
return item.length;
}
if (/^yyyy$/.test(item)) return '1,4';
if (/^y$/.test(item)) return '1,308';
return '1,2';
}() + '}' :
'\\' + item;
that.EXP_IF = that.EXP_IF + EXP;
that.EXP_SPLIT = that.EXP_SPLIT + '(' + EXP + ')';
});
that.EXP_IF = new RegExp('^' + (
options.range ?
that.EXP_IF + '\\s\\' + options.range + '\\s' + that.EXP_IF :
that.EXP_IF
) + '$');
that.EXP_SPLIT = new RegExp('^' + that.EXP_SPLIT + '$', '');
//#endregion

//转义为规定格式
lay.each(format, function(i, item){
if(/yyyy|y/.test(item)){ //年
Expand Down Expand Up @@ -1863,4 +1892,4 @@
}()
);

}();
}();