Dear all,
I'd like to automatically update roadmap-planner macros via the REST API. However, it seems that the choice of representation is a bit roundabout:
{
// ...
lanes: [
{
title: 'Some Lane',
color: { bar: 'red', count: 1, lane: 'blue', text: 'black' },
bars: [
{
title: 'Some Bar',
description: '',
startDate: '2017-01-01T00:00:00.000Z',
duration: 3.456, // <========= PROBLEM
rowIndex: 0,
id: '57ab0b36-7ba5-4f89-957b-d83bd5ff7e3f'
},
// ...
]
},
// ...
],
// ...
}
The problem for me with this format is that the duration needs to be specified either as a fraction of weeks or months, depending on the roadmap display option.
However, if selecting months, given a start and end date, it seems to be quite non-trivial to compute the months fraction, since not all months are equal length. If I understand the plugin source code it looks like this calculation is based on the milliseconds in a month.
So, here the questions:
Besides my questions which I still hold up, here is a function which seems to accurately compute the months duration as expected by Confluence with the help of moment.js:
function countMonths(start, end)
{
var s = moment(start);
var e = moment(end);
var sbom = moment(start).startOf('month');
var seom = moment(start).endOf('month');
var ebom = moment(end).startOf('month');
var eeom = moment(end).endOf('month');
var count = Math.round(ebom.diff(seom, 'months', true)) + 1;
count += seom.diff(s) / seom.diff(sbom);
count += e.diff(eeom) / eeom.diff(ebom);
return count;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.