Merge pull request #91 from jholland-usgs/master

Fixed parseDate(input, format) when format contained a dayOfYear value.
This commit is contained in:
Valeriy 2014-04-08 09:21:29 +06:00
commit b4e02aff4a
3 changed files with 17 additions and 5 deletions

View File

@ -121,7 +121,7 @@ Date.createParser = function (format) {
var regexNum = Date.parseRegexes.length; var regexNum = Date.parseRegexes.length;
var currentGroup = 1; var currentGroup = 1;
Date.parseFunctions[format] = funcName; Date.parseFunctions[format] = funcName;
var code = "Date." + funcName + " = function(input) {\n" + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n" + "var d = new Date();\n" + "y = d.getFullYear();\n" + "m = d.getMonth();\n" + "d = d.getDate();\n" + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" + "if (results && results.length > 0) {"; var code = "Date." + funcName + " = function(input) {\n" + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, z = -1;\n" + "var d = new Date();\n" + "y = d.getFullYear();\n" + "m = d.getMonth();\n" + "d = d.getDate();\n" + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" + "if (results && results.length > 0) {";
var regex = ""; var regex = "";
var special = false; var special = false;
var ch = ''; var ch = '';
@ -141,6 +141,7 @@ Date.createParser = function (format) {
} }
} }
} }
code += "if (y > 0 && z > 0){\n" + "var doyDate = new Date(y,0);\ndoyDate.setDate(z);\nm = doyDate.getMonth();\nd = doyDate.getDate();\n}";
code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" + "{return new Date(y, m, d, h, i, s);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n" + "{return new Date(y, m, d, h, i);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n" + "{return new Date(y, m, d, h);}\n" + "else if (y > 0 && m >= 0 && d > 0)\n" + "{return new Date(y, m, d);}\n" + "else if (y > 0 && m >= 0)\n" + "{return new Date(y, m);}\n" + "else if (y > 0)\n" + "{return new Date(y);}\n" + "}return null;}"; code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" + "{return new Date(y, m, d, h, i, s);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n" + "{return new Date(y, m, d, h, i);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n" + "{return new Date(y, m, d, h);}\n" + "else if (y > 0 && m >= 0 && d > 0)\n" + "{return new Date(y, m, d);}\n" + "else if (y > 0 && m >= 0)\n" + "{return new Date(y, m);}\n" + "else if (y > 0)\n" + "{return new Date(y);}\n" + "}return null;}";
Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$"); Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
eval(code) eval(code)
@ -180,9 +181,9 @@ Date.formatCodeToRegex = function (character, currentGroup) {
}; };
case "z": case "z":
return { return {
g: 0, g: 1,
c: null, c: "z = parseInt(results[" + currentGroup + "], 10);\n",
s: "(?:\\d{1,3})" s: "(\\d{1,3})"
}; };
case "W": case "W":
return { return {

View File

@ -38,6 +38,8 @@
<input type="text" id="datetimepicker_start_time"/> <input type="text" id="datetimepicker_start_time"/>
<h3>Date Time Picker from unixtime</h3> <h3>Date Time Picker from unixtime</h3>
<input type="text" id="datetimepicker_unixtime"/> <input type="text" id="datetimepicker_unixtime"/>
<h3>Date Time Picker with day of year and week of year</h3>
<input type="text" id="datetimepicker11"/>
</body> </body>
<script type="text/javascript" src="./jquery.js"></script> <script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript" src="./jquery.datetimepicker.js"></script> <script type="text/javascript" src="./jquery.datetimepicker.js"></script>
@ -136,5 +138,14 @@ $('#datetimepicker_start_time').datetimepicker({
$('#datetimepicker_unixtime').datetimepicker({ $('#datetimepicker_unixtime').datetimepicker({
format:'unixtime' format:'unixtime'
}); });
$('#datetimepicker11').datetimepicker({
hours12: false,
format: 'Y-z H:i W',
step: 1,
opened: false,
validateOnBlur: false,
closeOnDateSelect: false,
closeOnTimeSelect: false
});
</script> </script>
</html> </html>

File diff suppressed because one or more lines are too long