mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
Merge pull request #198 from dbrans/master
Gantt chart - add minutes and seconds durations
This commit is contained in:
commit
4ee0f9b6be
@ -77,7 +77,7 @@ var getStartDate = function(prevTime, dateFormat, str){
|
|||||||
}
|
}
|
||||||
return task.endTime;
|
return task.endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for actual date set
|
// Check for actual date set
|
||||||
if(moment(str,dateFormat.trim(),true).isValid()){
|
if(moment(str,dateFormat.trim(),true).isValid()){
|
||||||
return moment(str,dateFormat.trim(),true).toDate();
|
return moment(str,dateFormat.trim(),true).toDate();
|
||||||
@ -86,27 +86,33 @@ var getStartDate = function(prevTime, dateFormat, str){
|
|||||||
log.debug('With date format:'+dateFormat.trim());
|
log.debug('With date format:'+dateFormat.trim());
|
||||||
//log.debug('----');
|
//log.debug('----');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default date - now
|
// Default date - now
|
||||||
return new Date();
|
return new Date();
|
||||||
};
|
};
|
||||||
|
|
||||||
var getEndDate = function(prevTime, dateFormat, str){
|
var getEndDate = function(prevTime, dateFormat, str){
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
|
|
||||||
// Check for actual date
|
// Check for actual date
|
||||||
if(moment(str,dateFormat.trim(),true).isValid()){
|
if(moment(str,dateFormat.trim(),true).isValid()){
|
||||||
|
|
||||||
return moment(str,dateFormat.trim()).toDate();
|
return moment(str,dateFormat.trim()).toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -144,21 +150,21 @@ var parseId = function(idStr){
|
|||||||
|
|
||||||
var compileData = function(prevTask, dataStr){
|
var compileData = function(prevTask, dataStr){
|
||||||
var ds;
|
var ds;
|
||||||
|
|
||||||
if(dataStr.substr(0,1) === ':'){
|
if(dataStr.substr(0,1) === ':'){
|
||||||
ds = dataStr.substr(1,dataStr.length);
|
ds = dataStr.substr(1,dataStr.length);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ds=dataStr;
|
ds=dataStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = ds.split(',');
|
var data = ds.split(',');
|
||||||
|
|
||||||
|
|
||||||
var task = {};
|
var task = {};
|
||||||
var df = exports.getDateFormat();
|
var df = exports.getDateFormat();
|
||||||
|
|
||||||
|
|
||||||
// Get tags like active, done cand crit
|
// Get tags like active, done cand crit
|
||||||
var matchFound = true;
|
var matchFound = true;
|
||||||
while(matchFound){
|
while(matchFound){
|
||||||
@ -167,7 +173,7 @@ var compileData = function(prevTask, dataStr){
|
|||||||
task.active = true;
|
task.active = true;
|
||||||
data.shift(1);
|
data.shift(1);
|
||||||
matchFound = true;
|
matchFound = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(data[0].match(/^\s*done\s*$/)){
|
if(data[0].match(/^\s*done\s*$/)){
|
||||||
task.done = true;
|
task.done = true;
|
||||||
@ -184,8 +190,8 @@ var compileData = function(prevTask, dataStr){
|
|||||||
for(i=0;i<data.length;i++){
|
for(i=0;i<data.length;i++){
|
||||||
data[i] = data[i].trim();
|
data[i] = data[i].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch(data.length){
|
switch(data.length){
|
||||||
case 1:
|
case 1:
|
||||||
task.id = parseId();
|
task.id = parseId();
|
||||||
@ -203,7 +209,7 @@ var compileData = function(prevTask, dataStr){
|
|||||||
task.endTime = getEndDate(task.startTime, df, data[2]);
|
task.endTime = getEndDate(task.startTime, df, data[2]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
@ -232,4 +238,4 @@ exports.addTask = function(descr,data){
|
|||||||
|
|
||||||
exports.parseError = function(err,hash){
|
exports.parseError = function(err,hash){
|
||||||
mermaidAPI.parseError(err,hash);
|
mermaidAPI.parseError(err,hash);
|
||||||
};
|
};
|
||||||
|
@ -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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user