Weird SSJS Time/Date stuff...
While working on the Day view of the XPages Calendar I've kind-of re-arranged the way I'm calculating the different parts of the calendar. Instead of using separate variables for the Month and Year I've setup a date variable which holds a JavaScript date object and then use the getMonth() and getFullYear() functions of the date object. This makes it easier to navigate between the different days and months, you just change that one variable and everything else gets computed from that one date. However, I've come across some weirdness (for lack of a better term) with the getMonth() function that I can't for the life of me figure out.
OK, so I've setup an array with the names of all the months. This is a zero based array because with JavaScript the month numbers are zero based. So, here's what I've got:
sessionScope.put("months", new Array("January","Feburary","March","April","May","June","July","August","September","October","November","December"));
sessionScope.put("dispDate",new Date());
sessionScope.put("dispCalMonth", sessionScope.get("dispDate").getMonth());
Now, the dispCalMonth sessionScope variable contains the correct month, which for Feburary is 1 (remember zero based months). Farther down the form I've got a computed field that uses:
var curMonth = sessionScope.months(sessionScope.get("dispDate").getMonth());
return curMonth;
Now, this is returning 0 (January) instead of 1 (Feburary). I can't figure out why and it's driving me nuts
I've even returned just the number instead of the month name, and it does return 0.
Another issue I'm running into is using the setMonth(), setDate() and setFullYear() functions. These don't seem to work at all, at least not on sessionScope variables. I am able to set a new Date variable and use these functions and set the dispDate sessionScope variable to the new date variable. Which while workable, it is rather frustrating ![]()
These simple little things are the biggest hold up on Part 4 of the XPages Calendar which will include the day view and hopefully an "Alpha" release to OpenNTF. So, gentle reader, if you've got any ideas on what's going on here, please chime in while I still have a few hairs left.
UPDATE:
OK, in front of the computed field that displays the month is a link. In the onClick event of the link I decrement the dispDate sessionScope variable month. I removed this link and now the month display in the computed field is correct. So, it seems the onClick code is affecting the computed field somehow, so maybe someone can explain that one to me?
UPDATE #2:
OK, after searching the 8.5 Forum I found this post which said he got rid of all the event code and added it back via the source code editor. Well, I tried this with no joy. So, out of desparation I removed all the event code from the link and went and looked at the source. There was still an xp:this.onclick statement in the source and I still experienced the same results I defined above. This tag should not have been where it was, it should have been within the xp:EventHandler and then xp:this.action tags of the source. So I believe this is the whole problem. Now that I know what to look for it should be easy to spot. Also, I think the xp:this.onclick tag gets added if you edit the onclick event from the All properties tab instead of the events section.


















