Javascript changes in Fix Pack 30
In Netcool/Impact Fix Pack 7.1.0.30, the
Rhino Javascript engine was updated to a new release. This may affect how some of your Javascript
functions work.
Note: This is applicable to Impact Fix Pack 30 or later.
Changes to the toLocaleTimeString
function
The time stamp value returned by the toLocaleTimeString
function may by
formatted differently.
Example 1
var date = new Date();
var timeString = date.toLocaleTimeString();
Log(timeString); // prints 4:38:03 PM EST
This will return a 12 hour time stamp. In previous fix packs, the time stamp was in 24 hour format.
Workaround
As a workaround, you can switch to the LocalTime
function or modify the toLocaleTimeString
prototype.
Using LocalTime
Call the LocalTime
policy
function with a 24 hour pattern parameter.
Example 2
Seconds = GetDate();
Time = LocalTime(Seconds, "HH:mm:ss");
Log(Time); // prints 16:38:03
Override the toLocaleTimeString prototype
Override the prototype for the toLocaleTimeString
function to return a 24 hour
time stamp.
Add the following code to the top of your policy:
Date.prototype.toLocaleTimeString = function() {
var hours = this.getHours();
var minutes = this.getMinutes();
var seconds = this.getSeconds();
var localetime = ((hours < 10) ? "0"+hours : hours ) + ":" + ((minutes < 10) ? "0"+minutes : minutes) + ":" + ((seconds < 10) ? "0"+seconds : seconds );
return localetime;
}
Example 3:
var d = new Date();
var timeString = d.toLocaleTimeString();
Log(timeString); // prints 16:38:03