Merge pull request #198 from dbrans/master

Gantt chart - add minutes and seconds durations
This commit is contained in:
Knut Sveidqvist 2015-08-29 18:50:34 +02:00
commit 4ee0f9b6be
2 changed files with 47 additions and 21 deletions

View File

@ -102,11 +102,17 @@ var getEndDate = function(prevTime, dateFormat, str){
var d = moment(prevTime); var d = moment(prevTime);
// Check for length // Check for length
var re = /^([\d]+)([wdh])/; var re = /^([\d]+)([wdhms])/;
var durationStatement = re.exec(str.trim()); var durationStatement = re.exec(str.trim());
if(durationStatement!== null){ if(durationStatement!== null){
switch(durationStatement[2]){ switch(durationStatement[2]){
case 's':
d.add(durationStatement[1], 'seconds');
break;
case 'm':
d.add(durationStatement[1], 'minutes');
break;
case 'h': case 'h':
d.add(durationStatement[1], 'hours'); d.add(durationStatement[1], 'hours');
break; break;

View File

@ -27,7 +27,7 @@ describe('when using the ganttDb',function() {
expect(tasks[0].id ).toEqual('id1'); expect(tasks[0].id ).toEqual('id1');
expect(tasks[0].description).toEqual('test1'); expect(tasks[0].description).toEqual('test1');
}); });
it('should handle duration instead of fixed date to determine end date', function () { it('should handle duration (days) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD'); gDb.setDateFormat('YYYY-MM-DD');
gDb.addSection('testa1'); gDb.addSection('testa1');
gDb.addTask('test1','id1,2013-01-01,2d'); gDb.addTask('test1','id1,2013-01-01,2d');
@ -37,7 +37,7 @@ describe('when using the ganttDb',function() {
expect(tasks[0].id ).toEqual('id1'); expect(tasks[0].id ).toEqual('id1');
expect(tasks[0].description).toEqual('test1'); expect(tasks[0].description).toEqual('test1');
}); });
it('should handle duration instead of fixed date to determine end date', function () { it('should handle duration (hours) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD'); gDb.setDateFormat('YYYY-MM-DD');
gDb.addSection('testa1'); gDb.addSection('testa1');
gDb.addTask('test1','id1,2013-01-01,2h'); gDb.addTask('test1','id1,2013-01-01,2h');
@ -47,7 +47,27 @@ describe('when using the ganttDb',function() {
expect(tasks[0].id ).toEqual('id1'); expect(tasks[0].id ).toEqual('id1');
expect(tasks[0].description).toEqual('test1'); expect(tasks[0].description).toEqual('test1');
}); });
it('should handle ', function () { it('should handle duration (minutes) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD');
gDb.addSection('testa1');
gDb.addTask('test1','id1,2013-01-01,2m');
var tasks = gDb.getTasks();
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate());
expect(tasks[0].endTime ).toEqual(moment('2013-01-01 00:02', 'YYYY-MM-DD hh:mm').toDate());
expect(tasks[0].id ).toEqual('id1');
expect(tasks[0].description).toEqual('test1');
});
it('should handle duration (seconds) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD');
gDb.addSection('testa1');
gDb.addTask('test1','id1,2013-01-01,2s');
var tasks = gDb.getTasks();
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate());
expect(tasks[0].endTime ).toEqual(moment('2013-01-01 00:00:02', 'YYYY-MM-DD hh:mm:ss').toDate());
expect(tasks[0].id ).toEqual('id1');
expect(tasks[0].description).toEqual('test1');
});
it('should handle duration (weeks) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD'); gDb.setDateFormat('YYYY-MM-DD');
gDb.addSection('testa1'); gDb.addSection('testa1');
gDb.addTask('test1','id1,2013-01-01,2w'); gDb.addTask('test1','id1,2013-01-01,2w');