Skip to content

Commit

Permalink
fix formatDate 未获取到语言配置
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaoca committed Jun 22, 2022
1 parent 18458ff commit dc3bc87
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
11 changes: 6 additions & 5 deletions dist/js/cxcalendar.es.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* cxCalendar
* @version 3.0.2
* @version 3.0.3
* @author ciaoca
* @email [email protected]
* @site https://github.com/ciaoca/cxCalendar
Expand Down Expand Up @@ -182,9 +182,10 @@ theTool.parseDate = function(value, mustDef) {
};

// 格式化日期值
theTool.formatDate = function(style, time) {
theTool.formatDate = function(style, time, lang) {
const self = this;
const theDate = self.parseDate(time);
const language = self.extend({}, cxCalendar.languages.default, lang);

if (typeof style !== 'string' || !self.isDate(theDate)) {
return time;
Expand All @@ -207,7 +208,7 @@ theTool.formatDate = function(style, time) {
attr.h = self.fillLeadZero(attr.g, 2);
attr.i = self.fillLeadZero(theDate.getMinutes(), 2);
attr.s = self.fillLeadZero(theDate.getSeconds(), 2);
attr.a = attr.G > 12 ? cacheApi.language.pm : cacheApi.language.am;
attr.a = attr.G > 12 ? language.pm : language.am;

const keys = ['timestamp', 'Y', 'y', 'm', 'n', 'd', 'j', 'W', 'H', 'h', 'G', 'g', 'i', 's', 'a'];
const reg = new RegExp('(' + keys.join('|') + ')', 'g');
Expand Down Expand Up @@ -1504,7 +1505,7 @@ picker.prototype.getDate = function(style) {
newValue = [];
break;
}
newValue.push(theTool.formatDate(style, theDate.getTime()));
newValue.push(theTool.formatDate(style, theDate.getTime(), self.language));
}
newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');

Expand Down Expand Up @@ -1541,7 +1542,7 @@ picker.prototype.setDate = function(value) {
} else if (theTime > self.maxDate.time) {
theTime = self.maxDate.time;
}
newValue.push(theTool.formatDate(self.settings.format, theTime));
newValue.push(theTool.formatDate(self.settings.format, theTime, self.language));
}
newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');

Expand Down
11 changes: 6 additions & 5 deletions dist/js/cxcalendar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* cxCalendar
* @version 3.0.2
* @version 3.0.3
* @author ciaoca
* @email [email protected]
* @site https://github.com/ciaoca/cxCalendar
Expand Down Expand Up @@ -188,9 +188,10 @@ theTool.parseDate = function(value, mustDef) {
};

// 格式化日期值
theTool.formatDate = function(style, time) {
theTool.formatDate = function(style, time, lang) {
const self = this;
const theDate = self.parseDate(time);
const language = self.extend({}, cxCalendar.languages.default, lang);

if (typeof style !== 'string' || !self.isDate(theDate)) {
return time;
Expand All @@ -213,7 +214,7 @@ theTool.formatDate = function(style, time) {
attr.h = self.fillLeadZero(attr.g, 2);
attr.i = self.fillLeadZero(theDate.getMinutes(), 2);
attr.s = self.fillLeadZero(theDate.getSeconds(), 2);
attr.a = attr.G > 12 ? cacheApi.language.pm : cacheApi.language.am;
attr.a = attr.G > 12 ? language.pm : language.am;

const keys = ['timestamp', 'Y', 'y', 'm', 'n', 'd', 'j', 'W', 'H', 'h', 'G', 'g', 'i', 's', 'a'];
const reg = new RegExp('(' + keys.join('|') + ')', 'g');
Expand Down Expand Up @@ -1510,7 +1511,7 @@ picker.prototype.getDate = function(style) {
newValue = [];
break;
}
newValue.push(theTool.formatDate(style, theDate.getTime()));
newValue.push(theTool.formatDate(style, theDate.getTime(), self.language));
}
newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');

Expand Down Expand Up @@ -1547,7 +1548,7 @@ picker.prototype.setDate = function(value) {
} else if (theTime > self.maxDate.time) {
theTime = self.maxDate.time;
}
newValue.push(theTool.formatDate(self.settings.format, theTime));
newValue.push(theTool.formatDate(self.settings.format, theTime, self.language));
}
newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');

Expand Down
4 changes: 2 additions & 2 deletions dist/js/cxcalendar.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cxcalendar3",
"version": "3.0.2",
"version": "3.0.3",
"description": "JavaScript date picker, support range, time, year, month.",
"author": "ciaoca <[email protected]> (https://github.com/ciaoca/cxCalendar)",
"license": "MIT",
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ theTool.parseDate = function(value, mustDef) {
};

// 格式化日期值
theTool.formatDate = function(style, time) {
theTool.formatDate = function(style, time, lang) {
const self = this;
const theDate = self.parseDate(time);
const language = self.extend({}, cxCalendar.languages.default, lang);

if (typeof style !== 'string' || !self.isDate(theDate)) {
return time;
Expand All @@ -223,7 +224,7 @@ theTool.formatDate = function(style, time) {
attr.h = self.fillLeadZero(attr.g, 2);
attr.i = self.fillLeadZero(theDate.getMinutes(), 2);
attr.s = self.fillLeadZero(theDate.getSeconds(), 2);
attr.a = attr.G > 12 ? cacheApi.language.pm : cacheApi.language.am;
attr.a = attr.G > 12 ? language.pm : language.am;

const keys = ['timestamp', 'Y', 'y', 'm', 'n', 'd', 'j', 'W', 'H', 'h', 'G', 'g', 'i', 's', 'a'];
const reg = new RegExp('(' + keys.join('|') + ')', 'g');
Expand Down Expand Up @@ -1691,7 +1692,7 @@ picker.prototype.getDate = function(style) {
break;
};

newValue.push(theTool.formatDate(style, theDate.getTime()));
newValue.push(theTool.formatDate(style, theDate.getTime(), self.language));
};

newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');
Expand Down Expand Up @@ -1733,7 +1734,7 @@ picker.prototype.setDate = function(value) {
theTime = self.maxDate.time;
};

newValue.push(theTool.formatDate(self.settings.format, theTime));
newValue.push(theTool.formatDate(self.settings.format, theTime, self.language));
};

newValue = self.settings.mode === 'range' ? newValue.join(self.settings.rangeSymbol) : newValue.join('');
Expand Down

0 comments on commit dc3bc87

Please sign in to comment.