Covert Epoch Time?

Chris5
Kilo Expert

I have an integration that receives a string value for the last online date of an endpoint.

In my Transform Script I would like to convert this string from Epoch time to a usable value.  I have read a few posts and tried a script include and an onBefore script but I am unsuccessful with both.

 

The value coming in to my staging table is u_last_online and the field I wanna map to is u_addigy_last_online (date/time field)

 

Currently I am using the script onBefore in my transform map.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// convert and set account expiration date from AD
var dateConv = new DateConversion();
target.u_addigy_last_online = dateConv.int8ToGlideDateTime(source.u_last_online);

})(source, map, log, target);

This is the Script Include "DateConversion"

var DateConversion = Class.create();   
DateConversion.prototype = {   
   initialize : function() {   
   },   
   int8ToGlideDateTime : function(int8Date) {   
       var msDate = new Packages.org.apache.poi.hpsf.Util.filetimeToDate(int8Date);   
       var gDate = new GlideDateTime();   
       gDate.setValue(msDate);   
       return gDate;   
   }   
	
};

 

Thanks for any suggestions!

1 ACCEPTED SOLUTION

Chris5
Kilo Expert

I ended up using the following onBefore script in my transform map.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var lastOnlineTime;
var lastOnlineEpoch = source.u_last_online; //Whatever your epoch time is here
var gdtLastOnline = new GlideDateTime();
gdtLastOnline.setNumericValue(lastOnlineEpoch * 1000);
lastOnlineTime = gdtLastOnline.getValue();
target.u_addigy_last_online = lastOnlineTime;
	
})(source, map, log, target);

 

View solution in original post

9 REPLIES 9

tiagomacul
Giga Sage

do you have any advice on how to use this in my transform map or script include?

Mike Patel
Tera Sage

you can do below in transform map script (little modification to ggg script)

var epochTime = source.u_last_online;
var gdt = new GlideDateTime();
target.u_addigy_last_online =gdt.setNumericValue(parseInt(epochTime));

Chris5
Kilo Expert

I ended up using the following onBefore script in my transform map.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var lastOnlineTime;
var lastOnlineEpoch = source.u_last_online; //Whatever your epoch time is here
var gdtLastOnline = new GlideDateTime();
gdtLastOnline.setNumericValue(lastOnlineEpoch * 1000);
lastOnlineTime = gdtLastOnline.getValue();
target.u_addigy_last_online = lastOnlineTime;
	
})(source, map, log, target);

 

Really Helpful :


var epochTime = '1689076116';
var gdt = new GlideDateTime();
gdt.setNumericValue(epochTime * 1000);
gs.print('dt is ' + gdt.getValue());