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

ggg
Giga Guru

convert epoch time to GlideDateTime:

var epochTime = '1578912558000';
var gdt = new GlideDateTime();
gdt.setNumericValue(parseInt(epochTime));
gs.info('dt is ' + gdt.getDisplayValue());

How do I use that in my transform map?

change your script include:

var epochTime = your input value
var gdt = new GlideDateTime();
return gdt.setNumericValue(parseInt(epochTime));

 

 

it points to 

 1970-01-20 05:11:16