SIL Script Custom Field and interval value in second

Hi,

I would like to know if there is an easy way of getting a time interval value translated in second (maybe a interval SIL function/routine for example).

Right now I am getting the interpretative value (1d 3h 15min) in my custom field but I cannot do any calculation with it when data fields are exported to excel for instance.

Here is the code example I am using:

string [] subtasks = subtasks(key);
interval subtaskTimeSpentTesting;
for(string task in subtasks){
subtaskTimeSpentTesting = subtaskTimeSpentTesting + getTimeSpent(task, "hses-testing-group");
}
return getTimeSpent(key, "hses-testing-group") + subtaskTimeSpentTesting;

Thank you in advance for your help.

1 answer

I'am using this code to convert interval to number type:

function dateToSeconds(date dateToConvert) {
number seconds;
number year = formatDate(dateToConvert, "yyyy");
number day = formatDate(dateToConvert, "D");
number hours = formatDate(dateToConvert, "H");
number minutes = formatDate(dateToConvert, "m");
number sec = formatDate(dateToConvert, "s");
seconds = year*365*24*60*60 + day*24*60*60 + hours*60*60 + minutes*60 + sec;
return seconds;
}

function countWeekends(date dat1, date dat2) {
number countD = 0;
dat1 += "1d";

while (dat1 < dat2) {
  if (dayOfWeek(dat1) == "Sun" || dayOfWeek(dat1) == "Sat") countD +=1;
  dat1 += "1d";
}
return countD;
}

string field_name = "status";
string[] field_history = fieldHistory(key, field_name);
number n = arraySize(field_history);
date date1;
date date2;
number finalResult = 0;

for (number i = 1; i< n; i += 2) {
  if (i!=(n-1) && field_history[i] == 3) {
  date1 = parseDate("yyyy-MM-dd HH:mm:ss",field_history[i-1]);
  date2 = parseDate("yyyy-MM-dd HH:mm:ss",field_history[i+1]);
  finalResult += - countWeekends(date1,date2)*8*60*60;
  finalResult += dateToSeconds(date1 + toRawWorkingInterval(date2-date1))-dateToSeconds(date1);
  } 
}

return finalResult/60/60;

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

163 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you