Problem with exeJavascriptDirect

Hi Clifton,
I have a problem. I use the current date and time in the name of the folder created on the server to contain the student's work (mp3 and text files). Something like [name of exercise + current date + current time]. The student is not allowed to do an exercise more than once in an hour so when an exercise is opened the folders are checked to make sure there is no folder for this exercise created less than an hour ago. (I know there are other ways to do this but I have chosen to do it this way for compatibility with my previous version of this project.) It works OK but there is one problem. Javascript applies the local time variation when you use the new Date() function or pgDateFormat(). For example here in France this is GMT + 2 hours. That's fine. It's what I want for the folder name. I must then compare the date on the folder with the current date and time and to do this I convert both to milliseconds. Here is the problem: when I use date.parse([date]) the result is not corrected to local time. I thought I had found the solution because there is a Javascript function [date].getTimezoneOffset(). But Powerpac doesn't like it!
This works on an HTML document but not in my Toolbook program:
Powepac says: date2.getTimezoneOffset is not a function I've tried changing the variable name but it doesn't make any difference. Could you help please?
I have a problem. I use the current date and time in the name of the folder created on the server to contain the student's work (mp3 and text files). Something like [name of exercise + current date + current time]. The student is not allowed to do an exercise more than once in an hour so when an exercise is opened the folders are checked to make sure there is no folder for this exercise created less than an hour ago. (I know there are other ways to do this but I have chosen to do it this way for compatibility with my previous version of this project.) It works OK but there is one problem. Javascript applies the local time variation when you use the new Date() function or pgDateFormat(). For example here in France this is GMT + 2 hours. That's fine. It's what I want for the folder name. I must then compare the date on the folder with the current date and time and to do this I convert both to milliseconds. Here is the problem: when I use date.parse([date]) the result is not corrected to local time. I thought I had found the solution because there is a Javascript function [date].getTimezoneOffset(). But Powerpac doesn't like it!
This works on an HTML document but not in my Toolbook program:
- Code: Select all
function getDate(){
// date1 is the date on the folder
// date2 is the current time
var date1 = "2015-05-12T11:54:00";
var msec1 = Date.parse(date1);
var date2 = new Date();
var localTime = date2.getTimezoneOffset();
var msec2 = Date.parse(date2);
var msec21 = msec2;
var result;
var difference;
// getTimezoneOffset() gives the time difference in minutes
// eg 120
localTime = localTime * 60000
msec2 = msec2 - localTime
if (msec2 < msec1)
{
result = 'folder date > current time';
}
else
{
result = 'current time > folder date';
}
difference = msec2 - msec1;
difference = msToTime(difference);
alert('date and time on folder = ' + date1
+ '\r\n' + 'folder date = ' + msec1 + '\r\n' + 'currentTime = ' + msec2
+ '\r\n' + result + '\r\n' + 'current time without correction: ' + msec21
+ '\r\n' + 'current time corrected: ' + msec2
+ '\r\n' + 'difference = ' + difference);
}
function msToTime(s) {
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
var mins = s % 60;
var hrs = (s - mins) / 60;
if (hrs < 10) {hrs = "0" + hrs}
if (mins < 10) {mins = "0" + mins}
if (secs < 10) {secs = "0" + secs}
return hrs + ':' + mins + ':' + secs
}
Powepac says: date2.getTimezoneOffset is not a function I've tried changing the variable name but it doesn't make any difference. Could you help please?