Skip to content

Commit

Permalink
sbstjn#17 - Improve implementation, so as not to break previous behav…
Browse files Browse the repository at this point in the history
…ior for timelines with ommitted end date
  • Loading branch information
jpgcc committed Sep 21, 2014
1 parent 7834cf3 commit c3da863
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/timesheet.js

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

13 changes: 8 additions & 5 deletions source/javascripts/timesheet.bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
/**
* Timesheet Bubble
*/
var Bubble = function(wMonth, min, start, end, endless) {
var Bubble = function(wMonth, min, start, end) {
this.min = min;
this.start = start;
this.end = end;
this.endless = endless;
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;
};

Expand Down Expand Up @@ -71,9 +74,9 @@
Bubble.prototype.getDateLabel = function() {
return [
(this.start.hasMonth ? this.formatMonth(this.start.getMonth() + 1) + '/' : '' ) + this.start.getFullYear(),
(this.endless ? '—' :
(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('');
};

Expand Down
6 changes: 3 additions & 3 deletions source/javascripts/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

for (var n = 0, m = this.data.length; n < m; n++) {
var cur = this.data[n];
var bubble = new TimesheetBubble(widthMonth, this.year.min, cur.start, cur.end ? cur.end : new Date(this.year.max+1, 0, 1), cur.end ? false : true);
var bubble = new TimesheetBubble(widthMonth, this.year.min, cur.start, cur.end);

var line = [
'<span style="margin-left: ' + bubble.getStartOffset() + 'px; width: ' + bubble.getWidth() + 'px;" class="bubble bubble-' + (cur.type || 'default') + '" data-duration="' + (cur.end ? Math.round((cur.end-cur.start)/1000/60/60/24/39) : '') + '"></span>',
Expand Down Expand Up @@ -66,7 +66,7 @@
*/
Timesheet.prototype.parseDate = function(date) {
if (date === 'present') {
return null;
return new Date(10000 + this.year.max, 0, 1);
}
if (date.indexOf('/') === -1) {
date = new Date(parseInt(date, 10), 0, 1);
Expand Down Expand Up @@ -94,7 +94,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();
Expand Down

0 comments on commit c3da863

Please sign in to comment.