Pergunta

I'm trying to modify a simple little AE script which shows the day of the week in source text. I need it to show tomorrow and the next day - which I can do by using +1 and +2 - but without a condition it breaks. I'm guessing it's along the lines of; if d>6 then d=0? Can't quite get the code right, some help would be much appreciated!

d = new Date(Date(0));
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

weekday[d.getDay()]
Foi útil?

Solução

[EDIT: Terribly sorry, @ndix, but previous code (deleted) is totally flawed. The negatives will NOT work. Use the code below]

timeDirectionIndex = 0;//initial for today or future
daysToAdd = -15;//you can make this zero or any positive or negative integer
d = new Date(Date(0));
var weekday=new Array(7);
if (daysToAdd < 0) {timeDirectionIndex = 1;}

//if time is reversed, uses second column

weekday[0]=["Sunday","Saturday"][timeDirectionIndex];
weekday[1]=["Monday","Friday"][timeDirectionIndex];
weekday[2]=["Tuesday","Thursday"][timeDirectionIndex];
weekday[3]=["Wednesday","Wednesday"][timeDirectionIndex];
weekday[4]=["Thursday","Tuesday"][timeDirectionIndex];
weekday[5]=["Friday","Monday"][timeDirectionIndex];
weekday[6]=["Saturday","Sunday"][timeDirectionIndex];

//Math.abs makes it always positive; we rely on order of array now
if (daysToAdd < 0) {
   wd=weekday[ ( Math.abs(daysToAdd) +  3 + ( 3 - d.getDay())  )%7 ];
} else {
   wd=weekday[ (Math.abs(daysToAdd) +  (  d.getDay()   ) )%7 ];
}

alert(wd);

[PREVIOUS CODE DID NOT WORK]

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top