- }
- var b = [];
- fmt.replace(/(%.)/g, function(str, par) {
- return b[b.length] = par;
- });
- var i = 0, j = 0;
- var hr = 0;
- var min = 0;
- for (i = 0; i < a.length; ++i) {
- if (b[i] == "%a" || b[i] == "%A") {
- continue;
- }
- if (b[i] == "%d" || b[i] == "%e") {
- d = parseInt(a[i], 10);
- }
- if (b[i] == "%m") {
- m = parseInt(a[i], 10) - 1;
- }
- if (b[i] == "%Y" || b[i] == "%y") {
- y = parseInt(a[i], 10);
- (y < 100) && (y += (y > 29) ? 1900 : 2000);
- }
- if (b[i] == "%b" || b[i] == "%B") {
- for (j = 0; j < 12; ++j) {
- if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
- }
- } else if (/%[HIkl]/.test(b[i])) {
- hr = parseInt(a[i], 10);
- } else if (/%[pP]/.test(b[i])) {
- if (/pm/i.test(a[i]) && hr < 12)
- hr += 12;
- } else if (b[i] == "%M") {
- min = parseInt(a[i], 10);
- }
- }
- if (y != 0 && m != -1 && d != 0) {
- this.setDate(new Date(y, m, d, hr, min, 0));
- return;
- }
- 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 (Calendar._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) {
- var today = new Date();
- y = today.getFullYear();
- }
- if (m != -1 && d != 0) {
- this.setDate(new Date(y, m, d, hr, min, 0));
- }