FORUMS: list search recent posts

Year countdown timer expression problem

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Graham Harris
Year countdown timer expression problem
on Sep 16, 2017 at 10:58:21 am

I'm trying to create a timer that countdown from 1 year and displays in years, months, days, minutes and seconds. I found a suitable expression on an adobe forum but when run it populates the day, minute and second fields with NA. The expression is below. Any help in getting this to work would be gratefully received. As you can guess I know just enough about expressions to make myself look stupid.

totalTimeInSeconds = 31400000;
secondsPerMinute = 60;
secondsPerHour = 60 * 60;
secondsPerDay = 60 * 60 * 24;
secondsPerMonth = 60 * 60 * 24 * 30;
secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);
secondsRemaining = secondsRemaining % years;

months = Math.floor(secondsRemaining / secondsPerMonth);
secondsRemaining = secondsRemaining % months;

days = Math.floor(secondsRemaining / secondsPerDay);
secondsRemaining = secondsRemaining % days;

hours = Math.floor(secondsRemaining / secondsPerHour);
secondsRemaining = secondsRemaining % hours;

minutes = Math.floor(secondsRemaining / secondsPerMinute);
secondsRemaining = secondsRemaining % minutes;

seconds = secondsRemaining;

txt = "";
txt += yearleadingZeros(years);
txt += leadingZeros(months);
txt += leadingZeros(days);
txt += leadingZeros(hours);
txt += leadingZeros(minutes);
txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){
x = "0" + Math.floor(i);
return x;

}

function leadingZeros(i){
x = "0" + Math.floor(i);
x = ":" + x.substr(x.length-2, 2);
return x;

}


Return to posts index

Andrei Popa
Re: Year countdown timer expression problem
on Sep 18, 2017 at 6:26:50 am

The aN is from the NaN error, which means Not a Number. That is because by the time you get to the days you already are trying to do 0%0, which does not have a result. The problem is that you use the number of years, months, etc in your % operation. This should work.totalTimeInSeconds = 31400000;
secondsPerMinute = 60;
secondsPerHour = 60 * 60;
secondsPerDay = 60 * 60 * 24;
secondsPerMonth = 60 * 60 * 24 * 30;
secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);
secondsRemaining = secondsRemaining % secondsPerYear;

months = Math.floor(secondsRemaining / secondsPerMonth);
secondsRemaining = secondsRemaining % secondsPerMonth ;

days = Math.floor(secondsRemaining / secondsPerDay);
secondsRemaining = secondsRemaining % secondsPerDay ;

hours = Math.floor(secondsRemaining / secondsPerHour);
secondsRemaining = secondsRemaining % secondsPerHour;

minutes = Math.floor(secondsRemaining / secondsPerMinute);
secondsRemaining = secondsRemaining % secondsPerMinute ;

seconds = secondsRemaining;

txt = "";
txt += yearleadingZeros(years);
txt += leadingZeros(months);
txt += leadingZeros(days);
txt += leadingZeros(hours);
txt += leadingZeros(minutes);
txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){
x = "0" + Math.floor(i);
return x;

}

function leadingZeros(i){
x = "0" + Math.floor(i);
x = ":" + x.substr(x.length-2, 2);
return x;

}


Andrei


Return to posts index

Graham Harris
Re: Year countdown timer expression problem
on Sep 19, 2017 at 6:22:44 pm

Thanks Andrei, I really appreciate you taking the time to look at this. It now displays numbers instead of NA! Unfortunately it doesn't count down when I run it. Would you have any idea why that is?


Return to posts index


Graham Harris
Re: Year countdown timer expression problem
on Sep 19, 2017 at 6:52:28 pm

Sorry! It's been a long day, I realised I had hard coded the time to a single variable so the expression is unable to count up or down. I altered the expression as below and it appears to do what I want, at least I can render it out and then reverse it in premiere to do what I want. Thanks again for your help Andrei.

countspeed = 100;
clockStart = 31102010;

function times(n){
if (n &lt; 10) return "0" + n else return "" + n
}

clockTime = clockStart +countspeed*(time - inPoint);

if (clockTime &lt; 0){
minus = "-";
clockTime = -clockTime;
}else{
minus = "";
}

totalTimeInSeconds=clockTime
;

secondsPerMinute = 60;
secondsPerHour = 60 * 60;
secondsPerDay = 60 * 60 * 24;
secondsPerMonth = 60 * 60 * 24 * 30;
secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);
secondsRemaining = secondsRemaining % secondsPerYear;

months = Math.floor(secondsRemaining / secondsPerMonth);
secondsRemaining = secondsRemaining % secondsPerMonth ;

days = Math.floor(secondsRemaining / secondsPerDay);
secondsRemaining = secondsRemaining % secondsPerDay ;

hours = Math.floor(secondsRemaining / secondsPerHour);
secondsRemaining = secondsRemaining % secondsPerHour;

minutes = Math.floor(secondsRemaining / secondsPerMinute);
secondsRemaining = secondsRemaining % secondsPerMinute ;

seconds = secondsRemaining;

txt = "";
txt += yearleadingZeros(years);
txt += leadingZeros(months);
txt += leadingZeros(days);
txt += leadingZeros(hours);
txt += leadingZeros(minutes);
txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){
x = "0" + Math.floor(i);
return x;

}

function leadingZeros(i){
x = "0" + Math.floor(i);
x = ":" + x.substr(x.length-2, 2);
return x;

}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]