Get monday of the week from the user input

anupama8
Tera Expert

Hi All,

I have developed a time card record producer form where user enters the time worked and select a date in the field "week_starts".

As per our req , this date should be Monday of the week that user enters the date. I have written a script to change the date to Monday of the same week (as the date input by user). But the problem is when we change the TimeZone. I am using getDayOfWeekLocalTime() . But in IST if Monday=1,sunday=7 then in EST it changes to Monday=7, So my logic fails in this case.

Here is my code:

var wdate = new GlideDateTime(producer.week_starts);

var finalDate = new GlideDateTime();

finalDate = getMonday(wdate);

current.week_starts_on = finalDate;

function getMonday(wdate,firstDay){

  if(day==2){

  temp.addDaysLocalTime(-1);

  }

  else if(day==3){

  temp.addDaysLocalTime(-2);

  }

  else if(day==4){

  temp.addDaysLocalTime(-3);

  }

  else if(day==5){

  temp.addDaysLocalTime(-4);

  }

  else if(day==6){

  temp.addDaysLocalTime(-5);

  }

  else if(day==7){

  temp.addDaysLocalTime(-6);

  }

  else{

  return wdate.getLocalDate();

  }

  return temp.getLocalDate();

}

Can someone suggest any modification or if someone has better idea to approach this requirement? It will be really helpful.

6 REPLIES 6

No,



I am still looking for any method that should change the date automatically instead of forcing the user itself.


That is not so preferable as per our req but will try that method if nothing comes up.


Thank you for the response.


Hi Deepa,



The function you suggested is also getting affected when changing the TimeZone.