Chris Leonello avatar Chris Leonello committed 59a8b1d

Fixed bug with proper setting of date axis bounds. Added defaultCentry configuration option so user can decide if 1900 or 2000 should be used as default century.

Comments (0)

Files changed (2)

 		this.options = {};
 		this.locale = jsDate.regional.getLocale();
 		this.formatString = '';
+		this.defaultCentury = jsDate.config.defaultCentury;
 
         switch ( arguments.length ) {
             case 0:
 				// assume it is an options argument.
 				if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
 					var opts = this.options = arguments[0];
-					this.syntax= opts.syntax;
+					this.syntax = opts.syntax || this.syntax;
+					this.defaultCentury = opts.defaultCentury || this.defaultCentury;
 					this.proxy = jsDate.createDate(opts.date);
 				}
 				else {
 	 */
 	jsDate.config = {
 		defaultLocale: 'en',
-		syntax: 'perl'
+		syntax: 'perl',
+		defaultCentury: 1900
 	};
 		
 	/**
 				// assume it is an options argument.
 				if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
 					var opts = this.options = arguments[0];
-					this.syntax= opts.syntax;
+					this.syntax = opts.syntax || this.syntax;
+					this.defaultCentury = opts.defaultCentury || this.defaultCentury;
 					this.proxy = jsDate.createDate(opts.date);
 				}
 				else {
         // first check for 'dd-mmm-yyyy' or 'dd/mmm/yyyy' like '15-Dec-2010'
         parsable = parsable.replace(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{4})/i, "$1 $2 $3");
         
-        // Now check for 'dd-mmm-yy' or 'dd/mmm/yy' and normalize years to 1900.
+        // Now check for 'dd-mmm-yy' or 'dd/mmm/yy' and normalize years to default century.
         var match = parsable.match(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{2})\D*/i);
         if (match && match.length > 3) {
             var m3 = parseFloat(match[3]);
-            var ny = 1900 + m3;
+            var ny = jsDate.config.defaultCentury + m3;
             ny = String(ny);
             
             // now replace 2 digit year with 4 digit year
         
         // Check for '1/19/70 8:14PM'
         // where starts with mm/dd/yy or yy/mm/dd and have something after
-        // Check if 1st postiion is greater than 12, assume it is year.
+        // Check if 1st postiion is greater than 31, assume it is year.
         // Assme all 2 digit years are 1900's.
         // Finally, change them into US style mm/dd/yyyy representations.
         match = parsable.match(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})[^0-9]/);
             var m1 = parseFloat(match[1]);
             var m2 = parseFloat(match[2]);
             var m3 = parseFloat(match[3]);
-            var cent = 1900;
+            var cent = jsDate.config.defaultCentury;
             var ny, nd, nm, str;
             
             if (m1 > 31) { // first number is a year
             var match = str.match(/^([0-3]?\d)\s*[-\/.\s]{1}\s*([a-zA-Z]{3,9})\s*[-\/.\s]{1}\s*([0-3]?\d)$/);
             if (match) {
                 var d = new Date();
-                var cent = 1900;
+                var cent = jsDate.config.defaultCentury;
                 var m1 = parseFloat(match[1]);
                 var m3 = parseFloat(match[3]);
                 var ny, nd, nm;

src/plugins/jqplot.dateAxisRenderer.js

                     d[j][0] = new $.jsDate(d[j][0]).getTime();
                     pd[j][0] = new $.jsDate(d[j][0]).getTime();
                     sd[j][0] = new $.jsDate(d[j][0]).getTime();
-                    if (db.min == null || d[j][1] < db.min) {
+                    if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
                         db.min = d[j][0];
                     }
-                    if (db.max == null || d[j][1] > db.max) {
+                    if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
                         db.max = d[j][0];
                     }
 					if (j>0) {
                     d[j][1] = new $.jsDate(d[j][1]).getTime();
                     pd[j][1] = new $.jsDate(d[j][1]).getTime();
                     sd[j][1] = new $.jsDate(d[j][1]).getTime();
-                    if (db.min == null || d[j][1] < db.min) {
+                    if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) {
                         db.min = d[j][1];
                     }
-                    if (db.max == null || d[j][1] > db.max) {
+                    if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) {
                         db.max = d[j][1];
                     }
 					if (j>0) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.