give value to a Period Custom Field

I have a project with a Period type Custom Field "Reaction Time" and I want it to caltulate the time between the issue creation, and the time it takes to be "In Progress" State. For some reason when I give the parsed value to the Custom Field, it gets broken. Any help would be appriciated. I have the folowing code:

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const dateTime = require('@jetbrains/youtrack-scripting-api/date-time');
exports.rule = entities.Issue.onChange({
title: 'Calculate_reaction_time',
guard: (ctx) => {
return ctx.issue.is("State", "In Progress") && ctx.issue.fields['Reaction Time'] == null;
},
action: (ctx) => {
console.log("now: ", Date.now());
console.log("created: ", ctx.issue.created);
let reacttime = (Date.now() - ctx.issue.created);
console.log("reacttime",reacttime);
console.log(dateTime.toPeriod(reacttime));
console.log(ctx.issue.fields['Reaction Time']);
ctx.issue.fields['Reaction Time'] = dateTime.toPeriod(reacttime);
console.log(ctx.issue.fields['Reaction Time']);
},
requirements: {
// TODO: add requirements
}
});

 

And here are the outputs:

now: ,1627312800465
created: ,1627045416680
267383786
PT74H16M23.786S
null
P1W4DT2H16M

Its strange, that it seems to parse it right "PT74H16M23.786S", but when I set the value, its gonna be something mutch more "P1W4DT2H16M" I thought maybe, it is because the issue was submitted last week, and its monday, so it ads another week, but then the four days would be wrong as well, because the issue was only created in 3 days. So I dont really have any other idea.

It just hit me that maybe the custom field calculates 5days as one week, and 8hours as one day, so maybe thats why its way off the accual time, but then how coud I parse the miliseconds to accual weeks days and hours, not "YouTrack" weeks, days and hours. Or can I set the format of the custom field to be "normal"? (it accualyl ads up 267383786 ~= 74 hours and if 8hours is 1day than thats roughly ~= 1week 4days)

1 comment
Comment actions Permalink
Official comment

Hi! 

I'm Sergey from the YouTrack team. 

We've already discussed this case in the direct support request. But just in case I'll leave a note here: the period is calculated based on what you have in Settings → Time Tracking. One could start with the Time Tracking tutorial to learn more.

Please sign in to leave a comment.