Setting Future Time to specific date and time

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2010 11:57 AM
I am trying to set the planned start of an RFC to Monday from 12pm to tuesday 02am. But the Monday has to be at lease 14 days out so The code below sets it to 2 Mondays from now or 3 Mondays from now depending on day requested. How do I get from this code to setting the exact change window with date and time, etc.... Thank you in advance for the help!!
function setDecomDate() {
var today = new Date();
var thisDay = today.getDay(); //returns 0 for Sunday, 1 for Monday, etc. thru 6 for Saturday.
var thisMon = new Packages.com.glide.glideobject.GlideDateTime();
thisMon.setDisplayValue(gs.beginningOfThisWeek());
var nextMon = thisMon.getNumericValue();
nextMon1 += (1000*60*60*24*14);
nextMon2 += (1000*60*60*24*21);
//if today is Sun thru Wed (thisDay = 0, 1, 2, or 3), set decom to 2 mondays from now.
if (thisDay < 4){
current.planned_start.setDateNumericValue(nextMon1.getNumericValue());
}
//if today is Thurs thru Sat (thisDay = 4, 5, 6), set decom to 3 Mondays from now.
else if (thisDay >= 4){
current.planned_start.setDateNumericValue(nextMon2);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2010 07:36 AM
anyon have any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2010 09:48 AM
Howdy Marcus..
This isn't an issue here, but always make sure you define your variables as local. The variables "nextMon1" and "nextMon2" as written are global variables. This is generally a VERY bad idea. Any time you declare a variable "variable = 1;" instead of "var variable = 1;" it's now in the global scope.
Couplea questions:
1. what is the "exact change window?" (where is is coming from?)
2. are you just trying to add 12 hours to the start of Monday? If so, can you just add 12*60*60*1000 to "nextMon1, etc..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2010 10:31 AM
Here's something that should work. You may have to change the field names based on your RFC table.
var today = new Date();
var thisDay = today.getDay(); //returns 0 for Sunday, 1 for Monday, etc. thru 6 for Saturday.
var monday = GlideDateTime();
monday.setDisplayValue(gs.beginningOfThisWeek()); //get this Monday
midnightStartDiff = 12*60*60; //12 hours of seconds
duration = 14*60*60; //14 hours Mon 12pm- Tue 2am
monday.addSeconds(midnightStartDiff); //set time to Monday 12pm
//if today is Sun thru Wed (thisDay = 0, 1, 2, or 3), set decom to 2 mondays from now.
if (thisDay < 4){
monday.addWeeks(2); //add 2 weeks to this monday
}
//if today is Thurs thru Sat (thisDay = 4, 5, 6), set decom to 3 Mondays from now.
else if (thisDay >= 4){
monday.addWeeks(3); //add 3 weeks to this monday
}
//get value of Monday 12pm
current.start_date.setValue(monday.getDisplayValue());
//add duration to move to Tue 2am
monday.addSeconds(duration);
current.end_date.setValue(monday.getDisplayValue());