SIL Script Custom Field and interval value in second


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
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

476 views 8 27
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