diff --git a/Gruntfile.js b/Gruntfile.js
index 786fdbf..4ba059b 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -8,7 +8,7 @@ module.exports = function(grunt) {
},
my_target: {
files: {
- 'dist/timesheet.js': ['source/javascripts/timesheet.bubble.js', 'source/javascripts/timesheet.js']
+ 'dist/timesheet.js': ['source/javascripts/timesheet.js']
}
}
},
diff --git a/dist/timesheet.js b/dist/timesheet.js
index 17b13b2..b831d54 100644
--- a/dist/timesheet.js
+++ b/dist/timesheet.js
@@ -1 +1,5 @@
-!function(){"use strict";var Bubble=function(wMonth,min,start,end){this.min=min,this.start=start,this.end=end,this.widthMonth=wMonth};Bubble.prototype.formatMonth=function(num){return num=parseInt(num,10),num>=10?num:"0"+num},Bubble.prototype.getStartOffset=function(){return this.widthMonth/12*(12*(this.start.getFullYear()-this.min)+this.start.getMonth())},Bubble.prototype.getFullYears=function(){return(this.end&&this.end.getFullYear()||this.start.getFullYear())-this.start.getFullYear()},Bubble.prototype.getMonths=function(){var fullYears=this.getFullYears(),months=0;return this.end?this.end.hasMonth?(months+=this.end.getMonth()+1,months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1)):(months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1>0?fullYears-1:0)):months+=this.start.hasMonth?1:12,months},Bubble.prototype.getWidth=function(){return this.widthMonth/12*this.getMonths()},Bubble.prototype.getDateLabel=function(){return[(this.start.hasMonth?this.formatMonth(this.start.getMonth()+1)+"/":"")+this.start.getFullYear(),this.end?"-"+((this.end.hasMonth?this.formatMonth(this.end.getMonth()+1)+"/":"")+this.end.getFullYear()):""].join("")},window.TimesheetBubble=Bubble}(),function(){"use strict";var Timesheet=function(container,min,max,data){this.data=[],this.year={min:min,max:max},this.parse(data||[]),"undefined"!=typeof document&&(this.container="string"==typeof container?document.querySelector("#"+container):container,this.drawSections(),this.insertData())};Timesheet.prototype.insertData=function(){for(var html=[],widthMonth=this.container.querySelector(".scale section").offsetWidth,n=0,m=this.data.length;m>n;n++){var cur=this.data[n],bubble=new TimesheetBubble(widthMonth,this.year.min,cur.start,cur.end),line=['',''+bubble.getDateLabel()+" ",''+cur.label+""].join("");html.push("
"+line+"")}this.container.innerHTML+='"},Timesheet.prototype.drawSections=function(){for(var html=[],c=this.year.min;c<=this.year.max;c++)html.push("");this.container.className="timesheet color-scheme-default",this.container.innerHTML=''+html.join("")+"
"},Timesheet.prototype.parseDate=function(date){return-1===date.indexOf("/")?(date=new Date(parseInt(date,10),0,1),date.hasMonth=!1):(date=date.split("/"),date=new Date(parseInt(date[1],10),parseInt(date[0],10)-1,1),date.hasMonth=!0),date},Timesheet.prototype.parse=function(data){for(var n=0,m=data.length;m>n;n++){var beg=this.parseDate(data[n][0]),end=4===data[n].length?this.parseDate(data[n][1]):null,lbl=4===data[n].length?data[n][2]:data[n][1],cat=data[n][3]||"default";beg.getFullYear()this.year.max?this.year.max=end.getFullYear():beg.getFullYear()>this.year.max&&(this.year.max=beg.getFullYear()),this.data.push({start:beg,end:end,label:lbl,type:cat})}},window.Timesheet=Timesheet}();
\ No newline at end of file
+<<<<<<< HEAD
+!function(){"use strict";var Bubble=function(wMonth,min,start,end){this.min=min,this.start=start,this.end=end,this.end&&this.end.getFullYear()&&this.end.getFullYear()>9999&&(this.endless=!0,this.end=new Date(end.getFullYear()-9999,this.end.getMonth(),1)),this.widthMonth=wMonth};Bubble.prototype.formatMonth=function(num){return num=parseInt(num,10),num>=10?num:"0"+num},Bubble.prototype.getStartOffset=function(){return this.widthMonth/12*(12*(this.start.getFullYear()-this.min)+this.start.getMonth())},Bubble.prototype.getFullYears=function(){return(this.end&&this.end.getFullYear()||this.start.getFullYear())-this.start.getFullYear()},Bubble.prototype.getMonths=function(){var fullYears=this.getFullYears(),months=0;return this.end?this.end.hasMonth?(months+=this.end.getMonth()+1,months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1)):(months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1>0?fullYears-1:0)):months+=this.start.hasMonth?1:12,months},Bubble.prototype.getWidth=function(){return this.widthMonth/12*this.getMonths()},Bubble.prototype.getDateLabel=function(){return[(this.start.hasMonth?this.formatMonth(this.start.getMonth()+1)+"/":"")+this.start.getFullYear(),this.end?this.endless?"—":"–"+((this.end.hasMonth?this.formatMonth(this.end.getMonth()+1)+"/":"")+this.end.getFullYear()):""].join("")},window.TimesheetBubble=Bubble}(),function(){"use strict";var Timesheet=function(container,min,max,data){this.data=[],this.year={min:min,max:max},this.parse(data||[]),"undefined"!=typeof document&&(this.container="string"==typeof container?document.querySelector("#"+container):container,this.drawSections(),this.insertData())};Timesheet.prototype.insertData=function(){for(var html=[],widthMonth=this.container.querySelector(".scale section").offsetWidth,n=0,m=this.data.length;m>n;n++){var cur=this.data[n],bubble=new TimesheetBubble(widthMonth,this.year.min,cur.start,cur.end),line=['',''+bubble.getDateLabel()+" ",''+cur.label+""].join("");html.push(""+line+"")}this.container.innerHTML+='"},Timesheet.prototype.drawSections=function(){for(var html=[],c=this.year.min;c<=this.year.max;c++)html.push("");this.container.className="timesheet color-scheme-default",this.container.innerHTML=''+html.join("")+"
"},Timesheet.prototype.parseDate=function(date){return"present"===date?new Date(1e4+this.year.max,0,1):(-1===date.indexOf("/")?(date=new Date(parseInt(date,10),0,1),date.hasMonth=!1):(date=date.split("/"),date=new Date(parseInt(date[1],10),parseInt(date[0],10)-1,1),date.hasMonth=!0),date)},Timesheet.prototype.parse=function(data){for(var n=0,m=data.length;m>n;n++){var beg=this.parseDate(data[n][0]),end=4===data[n].length?this.parseDate(data[n][1]):null,lbl=4===data[n].length?data[n][2]:data[n][1],cat=data[n][3]||"default";beg.getFullYear()this.year.max?this.year.max=end.getFullYear():beg.getFullYear()>this.year.max&&(this.year.max=beg.getFullYear()),this.data.push({start:beg,end:end,label:lbl,type:cat})}},window.Timesheet=Timesheet}();
+=======
+!function(){"use strict";var Timesheet=function(container,min,max,data){this.data=[],this.year={min:min,max:max},this.parse(data||[]),"undefined"!=typeof document&&(this.container="string"==typeof container?document.querySelector("#"+container):container,this.drawSections(),this.insertData())};Timesheet.prototype.insertData=function(){for(var html=[],widthMonth=this.container.querySelector(".scale section").offsetWidth,n=0,m=this.data.length;m>n;n++){var cur=this.data[n],bubble=new Bubble(widthMonth,this.year.min,cur.start,cur.end),line=['',''+bubble.getDateLabel()+" ",''+cur.label+""].join("");html.push(""+line+"")}this.container.innerHTML+='"},Timesheet.prototype.drawSections=function(){for(var html=[],c=this.year.min;c<=this.year.max;c++)html.push("");this.container.className="timesheet color-scheme-default",this.container.innerHTML=''+html.join("")+"
"},Timesheet.prototype.parseDate=function(date){return-1===date.indexOf("/")?(date=new Date(parseInt(date,10),0,1),date.hasMonth=!1):(date=date.split("/"),date=new Date(parseInt(date[1],10),parseInt(date[0],10)-1,1),date.hasMonth=!0),date},Timesheet.prototype.parse=function(data){for(var n=0,m=data.length;m>n;n++){var beg=this.parseDate(data[n][0]),end=4===data[n].length?this.parseDate(data[n][1]):null,lbl=4===data[n].length?data[n][2]:data[n][1],cat=4===data[n].length?data[n][3]:3===data[n].length?data[n][2]:"default";beg.getFullYear()this.year.max?this.year.max=end.getFullYear():beg.getFullYear()>this.year.max&&(this.year.max=beg.getFullYear()),this.data.push({start:beg,end:end,label:lbl,type:cat})}};var Bubble=function(wMonth,min,start,end){this.min=min,this.start=start,this.end=end,this.widthMonth=wMonth};Bubble.prototype.formatMonth=function(num){return num=parseInt(num,10),num>=10?num:"0"+num},Bubble.prototype.getStartOffset=function(){return this.widthMonth/12*(12*(this.start.getFullYear()-this.min)+this.start.getMonth())},Bubble.prototype.getFullYears=function(){return(this.end&&this.end.getFullYear()||this.start.getFullYear())-this.start.getFullYear()},Bubble.prototype.getMonths=function(){var fullYears=this.getFullYears(),months=0;return this.end?this.end.hasMonth?(months+=this.end.getMonth()+1,months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1)):(months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1>0?fullYears-1:0)):months+=this.start.hasMonth?1:12,months},Bubble.prototype.getWidth=function(){return this.widthMonth/12*this.getMonths()},Bubble.prototype.getDateLabel=function(){return[(this.start.hasMonth?this.formatMonth(this.start.getMonth()+1)+"/":"")+this.start.getFullYear(),this.end?"-"+((this.end.hasMonth?this.formatMonth(this.end.getMonth()+1)+"/":"")+this.end.getFullYear()):""].join("")},window.Timesheet=Timesheet}();
+>>>>>>> fix_tests
diff --git a/source/javascripts/timesheet.js b/source/javascripts/timesheet.js
index d0914c9..2f11d4b 100644
--- a/source/javascripts/timesheet.js
+++ b/source/javascripts/timesheet.js
@@ -63,6 +63,9 @@
* Parse data string
*/
Timesheet.prototype.parseDate = function(date) {
+ if (date === 'present') {
+ return new Date(10000 + this.year.max, 0, 1);
+ }
if (date.indexOf('/') === -1) {
date = new Date(parseInt(date, 10), 0, 1);
date.hasMonth = false;
@@ -89,7 +92,7 @@
this.year.min = beg.getFullYear();
}
- if (end && end.getFullYear() > this.year.max) {
+ if (end && end.getFullYear() < 10000 && end.getFullYear() > this.year.max) {
this.year.max = end.getFullYear();
} else if (beg.getFullYear() > this.year.max) {
this.year.max = beg.getFullYear();
@@ -106,6 +109,10 @@
this.min = min;
this.start = start;
this.end = end;
+ if (this.end && this.end.getFullYear() && this.end.getFullYear() > 9999) {
+ this.endless = true;
+ this.end = new Date(end.getFullYear()-9999, this.end.getMonth(), 1);
+ }
this.widthMonth = wMonth;
};
@@ -168,9 +175,11 @@
Bubble.prototype.getDateLabel = function() {
return [
(this.start.hasMonth ? this.formatMonth(this.start.getMonth() + 1) + '/' : '' ) + this.start.getFullYear(),
- (this.end ? '-' + ((this.end.hasMonth ? this.formatMonth(this.end.getMonth() + 1) + '/' : '' ) + this.end.getFullYear()) : '')
+ (this.end
+ ? (this.endless ? '—' : '–' + ((this.end.hasMonth ? this.formatMonth(this.end.getMonth() + 1) + '/' : '' ) + this.end.getFullYear()))
+ : '')
].join('');
};
window.Timesheet = Timesheet;
-})();
\ No newline at end of file
+})();
diff --git a/test/timesheet.js b/test/timesheet.js
index 5d84105..231a205 100644
--- a/test/timesheet.js
+++ b/test/timesheet.js
@@ -3,27 +3,26 @@
*/
window = {};
require(__dirname + '/../source/javascripts/timesheet.js');
-require(__dirname + '/../source/javascripts/timesheet.bubble.js');
var assert = require('assert');
suite('Timesheet', function() {
test('Calculation', function(done) {
var TS = new window.Timesheet();
- assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2002'))).getMonths());
- assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2003'))).getMonths());
- assert.equal(24, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2004'))).getMonths());
+ assert.equal(12, (new window.Bubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2002'))).getMonths());
+ assert.equal(12, (new window.Bubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2003'))).getMonths());
+ assert.equal(24, (new window.Bubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2004'))).getMonths());
- assert.equal(9, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2002'))).getMonths());
- assert.equal(9, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2003'))).getMonths());
- assert.equal(21, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2004'))).getMonths());
+ assert.equal(9, (new window.Bubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2002'))).getMonths());
+ assert.equal(9, (new window.Bubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2003'))).getMonths());
+ assert.equal(21, (new window.Bubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2004'))).getMonths());
- assert.equal(13, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2003'))).getMonths());
+ assert.equal(13, (new window.Bubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2003'))).getMonths());
- assert.equal(25, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2004'))).getMonths());
+ assert.equal(25, (new window.Bubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2004'))).getMonths());
- assert.equal(1, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'))).getMonths());
- assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'))).getMonths());
+ assert.equal(1, (new window.Bubble(60, 2012, TS.parseDate('04/2002'))).getMonths());
+ assert.equal(12, (new window.Bubble(60, 2012, TS.parseDate('2002'))).getMonths());
done();
});