Page 1 of 1

Date declaration bug

PostPosted: Fri Oct 05, 2018 9:22 am
by briese-it
I created a form variable and want to set a specific month on the onShow event for that variable but the variable has still the original month. Changing a new date variable created on the onShow event is working fine.
Is it a bug?

Code: Select all
/**
* @type {Date}
*
* @properties={typeid:35,uuid:"A25E3416-1A34-4CC5-9C21-BBC05B9C434C",variableType:93}
*/
var dateMinus6Month = new Date();

/**
* @param {Boolean} firstShow
* @param {JSEvent} event
* @override
*
* @properties={typeid:24,uuid:"C8A32A7E-EA94-488B-A2BA-1D17D0BDE7D3"}
*/
function onShowForm(firstShow, event) {
   _super.onShowForm(firstShow, event);

   /** @type {Date} */
   var testDate = new Date();
   testDate.setMonth(testDate.getMonth()-6);

   dateMinus6Month.setMonth(dateMinus6Month.getMonth()-6);

   application.output("dateMinus6Month: " + dateMinus6Month)
   application.output("testDate: " + testDate)
}


Result:
dateMinus6Month: Fri Oct 05 2018 09:16:02 GMT+0200 (MESZ)
testDate: Thu Apr 05 2018 09:16:02 GMT+0200 (MESZ)

Re: Date declaration bug

PostPosted: Sat Oct 06, 2018 8:07 pm
by kwpsd
Try initializing the date in the onShowForm() method.


Code: Select all
/**
* @type {Date}
*
* @properties={typeid:35,uuid:"A25E3416-1A34-4CC5-9C21-BBC05B9C434C",variableType:93}
*/
var dateMinus6Month = null;

/**
* @param {Boolean} firstShow
* @param {JSEvent} event
* @override
*
* @properties={typeid:24,uuid:"C8A32A7E-EA94-488B-A2BA-1D17D0BDE7D3"}
*/
function onShowForm(firstShow, event)
{
   _super.onShowForm(firstShow, event);

   /** @type {Date} */

   var today = new Date();


   var testDate = today;

   dateMinus6Month = today;


   testDate.setMonth( testDate.getMonth() - 6 );

   dateMinus6Month.setMonth( dateMinus6Month.getMonth() - 6 );


   application.output( "dateMinus6Month: " + dateMinus6Month )

   application.output( "testDate: " + testDate )
}