mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +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;
|
||||
}
|
||||
|
||||
|
||||
// Check for actual date set
|
||||
if(moment(str,dateFormat.trim(),true).isValid()){
|
||||
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('----');
|
||||
}
|
||||
|
||||
|
||||
// Default date - now
|
||||
return new Date();
|
||||
};
|
||||
|
||||
var getEndDate = function(prevTime, dateFormat, str){
|
||||
str = str.trim();
|
||||
|
||||
// Check for actual date
|
||||
|
||||
// Check for actual date
|
||||
if(moment(str,dateFormat.trim(),true).isValid()){
|
||||
|
||||
|
||||
return moment(str,dateFormat.trim()).toDate();
|
||||
}
|
||||
|
||||
var d = moment(prevTime);
|
||||
// Check for length
|
||||
var re = /^([\d]+)([wdh])/;
|
||||
var re = /^([\d]+)([wdhms])/;
|
||||
var durationStatement = re.exec(str.trim());
|
||||
|
||||
|
||||
if(durationStatement!== null){
|
||||
switch(durationStatement[2]){
|
||||
case 's':
|
||||
d.add(durationStatement[1], 'seconds');
|
||||
break;
|
||||
case 'm':
|
||||
d.add(durationStatement[1], 'minutes');
|
||||
break;
|
||||
case 'h':
|
||||
d.add(durationStatement[1], 'hours');
|
||||
break;
|
||||
@ -144,21 +150,21 @@ var parseId = function(idStr){
|
||||
|
||||
var compileData = function(prevTask, dataStr){
|
||||
var ds;
|
||||
|
||||
|
||||
if(dataStr.substr(0,1) === ':'){
|
||||
ds = dataStr.substr(1,dataStr.length);
|
||||
}
|
||||
else{
|
||||
ds=dataStr;
|
||||
}
|
||||
|
||||
|
||||
var data = ds.split(',');
|
||||
|
||||
|
||||
|
||||
|
||||
var task = {};
|
||||
var df = exports.getDateFormat();
|
||||
|
||||
|
||||
|
||||
|
||||
// Get tags like active, done cand crit
|
||||
var matchFound = true;
|
||||
while(matchFound){
|
||||
@ -167,7 +173,7 @@ var compileData = function(prevTask, dataStr){
|
||||
task.active = true;
|
||||
data.shift(1);
|
||||
matchFound = true;
|
||||
|
||||
|
||||
}
|
||||
if(data[0].match(/^\s*done\s*$/)){
|
||||
task.done = true;
|
||||
@ -184,8 +190,8 @@ var compileData = function(prevTask, dataStr){
|
||||
for(i=0;i<data.length;i++){
|
||||
data[i] = data[i].trim();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
switch(data.length){
|
||||
case 1:
|
||||
task.id = parseId();
|
||||
@ -203,7 +209,7 @@ var compileData = function(prevTask, dataStr){
|
||||
task.endTime = getEndDate(task.startTime, df, data[2]);
|
||||
break;
|
||||
default:
|
||||
|
||||
|
||||
}
|
||||
|
||||
return task;
|
||||
@ -232,4 +238,4 @@ exports.addTask = function(descr,data){
|
||||
|
||||
exports.parseError = function(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].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.addSection('testa1');
|
||||
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].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.addSection('testa1');
|
||||
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].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.addSection('testa1');
|
||||
gDb.addTask('test1','id1,2013-01-01,2w');
|
||||
|
Loading…
x
Reference in New Issue
Block a user