I will set a specific start date in a “function new_date(datetime,event_of_the_day)” with a return from the “function set_start_time(event_of_the_day)”:
function set_start_time(event_of_the_day) {
var arg = new Array();
switch (event_of_the_day) {
case 0:
arg[0] = 1;
arg[1] = 0;
return arg;
break;
case 1:
arg[0] = 1;
arg[1] = 30;
return arg;
break;
case 2:
arg[0] = 2;
arg[1] = 0;
return arg;
break;
... and so on.
If I set the return like:
function new_date(datetime,event_of_the_day) {
var argS = m_set_start_time(event_of_the_day);
start_datetime = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate(), argS[0], argS[1], 0);
//
I get the warning:
The constructor Date(Number,Number,[Number],[Number],[Number],[Number],[Number]) is not applicable for the arguments (Number,Number,Number,None,None,Number)
Don’t I get a number in the array as return?
If I than use utils.numberFormat(argS[0],0) and/or utils.stringToNumber(argS[0]) the warning for the Date constructor disappears but I get new for the utils.!
The method stringToNumber() from the type JSUtils is deprecated
The method numberFormat() from the type JSUtils is deprecated
I don’t understand this because the functions are listed in the developer and in the Servoy Wiki?
Every help is welcome.
tgs:
If I set the return like:
CODE: SELECT ALL
function new_date(datetime,event_of_the_day) {
var argS = m_set_start_time(event_of_the_day);
start_datetime = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate(), argS[0], argS[1], 0);
//
I get the warning:
CODE: SELECT ALL
The constructor Date(Number,Number,[Number],[Number],[Number],[Number],[Number]) is not applicable for the arguments (Number,Number,Number,None,None,Number)
Don’t I get a number in the array as return?
this should work:
function new_date(datetime,event_of_the_day) {
/** @type {Array<Number>} */
var argS = m_set_start_time(event_of_the_day);
start_datetime = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate(), argS[0], argS[1], 0);
//
just one note:
the JSDoc I added has nothing to do with casting data or related ‘magic’.
The warning (buildmarker) you’ve experienced was all about Servoy Developer not knowing which type the values of the ‘argS’ array were…
The JSDoc changed that.
mboegem:
The warning (buildmarker) you’ve experienced was all about Servoy Developer not knowing which type the values of the ‘argS’ array were…
The JSDoc changed that.
Hi Marc,
does this mean, that I have to set the type of a value if the warning says “none”, because Servoy Developer doesn’t know it? And if I ignore the warnings, does the function is working as well?
Yes and yes. But I think you can better type the return value of the function, so wherever you use the function the return value and the variable you assign it to is typed.
/**
* @return {Array<Number>}
*/
function set_start_time(event_of_the_day) {
/** @type {Array<Number>} */
var arg = new Array();
switch (event_of_the_day) {
case 0:
arg[0] = 1;
arg[1] = 0;
return arg;
break;
case 1:
arg[0] = 1;
arg[1] = 30;
return arg;
break;
case 2:
arg[0] = 2;
arg[1] = 0;
return arg;
break;
... and so on.