Skip to content

Commit

Permalink
Fix wrong format error
Browse files Browse the repository at this point in the history
Fix error when a wrong format is provided.
  • Loading branch information
sky93 committed Dec 14, 2016
1 parent c36350a commit b17efb6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
48 changes: 27 additions & 21 deletions dist/jquery.ezdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,33 @@
var year = gDate.getFullYear();
var hour = gDate.getHours();
var minute = gDate.getMinutes();
var converted = toJalaali(year, month + 1, day, false);

var mm = converted.jm < 10 ? "0" + converted.jm : converted.jm;
var dd = converted.jd < 10 ? "0" + converted.jd : converted.jd;

var final_text = settings['dateFormat'];
final_text = final_text
.replace(eval("/YYYY/g"), converted.jy)
.replace(eval("/MMM/g"), monthToName(converted.jm))
.replace(eval("/MM/g"), mm)
.replace(eval("/M/g"), converted.jm)
.replace(eval("/DD/g"), dd)
.replace(eval("/D/g"), converted.jd);

if (settings['persianNumber']) {
var persian = Array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
for (i = 0; i < 10; i++) {
final_text = final_text.replace(eval("/" + i + "/g"), persian[i]);
try {
var converted = toJalaali(year, month + 1, day, false);

var mm = converted.jm < 10 ? "0" + converted.jm : converted.jm;
var dd = converted.jd < 10 ? "0" + converted.jd : converted.jd;

var final_text = settings['dateFormat'];
final_text = final_text
.replace(eval("/YYYY/g"), converted.jy)
.replace(eval("/MMM/g"), monthToName(converted.jm))
.replace(eval("/MM/g"), mm)
.replace(eval("/M/g"), converted.jm)
.replace(eval("/DD/g"), dd)
.replace(eval("/D/g"), converted.jd);

if (settings['persianNumber']) {
var persian = Array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
for (i = 0; i < 10; i++) {
final_text = final_text.replace(eval("/" + i + "/g"), persian[i]);
}
}
object.text(final_text);
}
object.text(final_text);
catch(err) {
console.log(err.message + '(' + object.attr(settings.attrName) + ')');
}

}

if ($.isFunction(settings.complete)) {
Expand Down Expand Up @@ -80,7 +86,7 @@
, i;

if (jy < jp || jy >= breaks[bl - 1])
throw new Error('error');
throw new Error('Wrong date provided.');

for (i = 1; i < bl; i += 1) {
jm = breaks[i];
Expand Down Expand Up @@ -224,4 +230,4 @@
function mod(a, b) {
return a - ~~(a / b) * b
}
})(jQuery);
})(jQuery);
2 changes: 1 addition & 1 deletion dist/jquery.ezdate.min.js

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": "ezdate",
"version": "1.1.1",
"version": "1.1.3",
"description": "The easiest and the best way to convert dates to Persian date format.",
"main": "jquey.ezdate.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion test/jquery.ezdate.min.js

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

0 comments on commit b17efb6

Please sign in to comment.