<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Difference between two dates extracted by Audit API is not viewing. in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139320#M37267</link>
    <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on an Audit Report requested by my client. I am getting entries of users Login and Logout time but I also want how much time he spent when the user was logged in. So I simply subtracted my login time and logout and stored it in a variable in my javascript controller of my webscript.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is the subtracted date and time is not appearing on Alfresco. Instead there is symbol appearing on my report.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a look at my js code, you may get an idea of what im trying to do.&lt;/P&gt;&lt;PRE&gt;var auditJSON = {}
var connector= remote.connect("alfresco-api");
var user = page.url.args["user"];
//var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&amp;amp;maxItems=1000&amp;amp;where=(createdByUser=" + user +"%20and%20valuesKey='/alfresco-access/login/user')&amp;amp;include=values'");
var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&amp;amp;maxItems=1000000&amp;amp;where=(createdByUser="+ user +"%20and%20createdAt%20BETWEEN%20('2020-12-01T12%3A13%3A51.593%2B01%3A00'%20%2C%20'2021-04-25T10%3A05%3A16.536%2B01%3A00'))&amp;amp;include=values");
var final_results = [];
if (result.status.code == status.STATUS_OK) {
    var auditJSON = jsonUtils.toObject(result);
}
var entries = auditJSON["list"]["entries"];
model.user= user;
var map = {}
var activities = "";
var login_date;
var logout_date;
var map_key = "";
var results = [];
var result = {};
for(var i = 0; i &amp;lt; entries.length; i++){
        var values = entries[i].entry.values;
    if(values["/alfresco-access/login/user"] != null){
        activities = "";
        login_date = entries[i].entry.createdAt;
    } else if (values["/alfresco-access/logout/user"] != null){
        logout_date = entries[i].entry.createdAt;
        map_key = login_date + "-" + logout_date + "-" + user;
        map[map_key] = activities;
//CALCULATING LOGIN DURATION
         var time_elapsed = (new Date(logout_date).getTime() - new Date(login_date).getTime())/1000/60/60;
             time_elapsed = Math.round(time_elapsed * 100);
	     time_elapsed = time_elapsed / 100;
        result = {login_date: login_date, logout_date: logout_date, user: user, activities: activities, time_elapsed: time_elapsed}
        results.push(result);
        activities = "";
    } else {
        activities += values["/alfresco-access/transaction/action"] + "\n" + "\n" + values["/alfresco-access/transaction/path"] + "\n" + "\n";
        activities = activities.replace("/app:company_home","").replace("st:sites","Sites").replace("/cm:","/").replace("/sys:system/sys:people","User");
    }

}
model.results = results;

&lt;/PRE&gt;&lt;P&gt;Now as you can see the difference between login and logout is stored in "time_elapsed" variable.&lt;/P&gt;&lt;P&gt;But when I view my report a symbol is appearing instead. Take a look at the report.&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot from 2021-04-22 04-18-25.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://connect.hyland.com/t5/image/serverpage/image-id/1040iC34C8B80D87D08D9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;As you can see in the end of&amp;nbsp; every row there is this symbol appearing.&lt;/P&gt;&lt;P&gt;I calculated the difference of the same datetime format in an onlne js editor and the result is printing fine their. But the output is not printing on Alfresco.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how this problem can be solved?&lt;/P&gt;</description>
    <pubDate>Wed, 21 Apr 2021 23:21:38 GMT</pubDate>
    <dc:creator>Syedjunaid</dc:creator>
    <dc:date>2021-04-21T23:21:38Z</dc:date>
    <item>
      <title>Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139320#M37267</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on an Audit Report requested by my client. I am getting entries of users Login and Logout time but I also want how much time he spent when the user was logged in. So I simply subtracted my login time and logout and stored it in a variable in my javascript controller of my webscript.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is the subtracted date and time is not appearing on Alfresco. Instead there is symbol appearing on my report.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a look at my js code, you may get an idea of what im trying to do.&lt;/P&gt;&lt;PRE&gt;var auditJSON = {}
var connector= remote.connect("alfresco-api");
var user = page.url.args["user"];
//var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&amp;amp;maxItems=1000&amp;amp;where=(createdByUser=" + user +"%20and%20valuesKey='/alfresco-access/login/user')&amp;amp;include=values'");
var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&amp;amp;maxItems=1000000&amp;amp;where=(createdByUser="+ user +"%20and%20createdAt%20BETWEEN%20('2020-12-01T12%3A13%3A51.593%2B01%3A00'%20%2C%20'2021-04-25T10%3A05%3A16.536%2B01%3A00'))&amp;amp;include=values");
var final_results = [];
if (result.status.code == status.STATUS_OK) {
    var auditJSON = jsonUtils.toObject(result);
}
var entries = auditJSON["list"]["entries"];
model.user= user;
var map = {}
var activities = "";
var login_date;
var logout_date;
var map_key = "";
var results = [];
var result = {};
for(var i = 0; i &amp;lt; entries.length; i++){
        var values = entries[i].entry.values;
    if(values["/alfresco-access/login/user"] != null){
        activities = "";
        login_date = entries[i].entry.createdAt;
    } else if (values["/alfresco-access/logout/user"] != null){
        logout_date = entries[i].entry.createdAt;
        map_key = login_date + "-" + logout_date + "-" + user;
        map[map_key] = activities;
//CALCULATING LOGIN DURATION
         var time_elapsed = (new Date(logout_date).getTime() - new Date(login_date).getTime())/1000/60/60;
             time_elapsed = Math.round(time_elapsed * 100);
	     time_elapsed = time_elapsed / 100;
        result = {login_date: login_date, logout_date: logout_date, user: user, activities: activities, time_elapsed: time_elapsed}
        results.push(result);
        activities = "";
    } else {
        activities += values["/alfresco-access/transaction/action"] + "\n" + "\n" + values["/alfresco-access/transaction/path"] + "\n" + "\n";
        activities = activities.replace("/app:company_home","").replace("st:sites","Sites").replace("/cm:","/").replace("/sys:system/sys:people","User");
    }

}
model.results = results;

&lt;/PRE&gt;&lt;P&gt;Now as you can see the difference between login and logout is stored in "time_elapsed" variable.&lt;/P&gt;&lt;P&gt;But when I view my report a symbol is appearing instead. Take a look at the report.&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot from 2021-04-22 04-18-25.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://connect.hyland.com/t5/image/serverpage/image-id/1040iC34C8B80D87D08D9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;As you can see in the end of&amp;nbsp; every row there is this symbol appearing.&lt;/P&gt;&lt;P&gt;I calculated the difference of the same datetime format in an onlne js editor and the result is printing fine their. But the output is not printing on Alfresco.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how this problem can be solved?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 23:21:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139320#M37267</guid>
      <dc:creator>Syedjunaid</dc:creator>
      <dc:date>2021-04-21T23:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139321#M37268</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/76245"&gt;@Syedjunaid&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you:&lt;/P&gt;
&lt;P&gt;1) show us the actual value that you expect to be displayed&lt;/P&gt;
&lt;P&gt;2) print the value to the log output - how does it appear there?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 10:50:04 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139321#M37268</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2021-04-27T10:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139322#M37269</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/76783"&gt;@EddieMay&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted my output to display number of hours user spent when he was logged in.&lt;/P&gt;&lt;P&gt;My output is printing fine in Javascript Console, I installed in alfresco.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://connect.hyland.com/t5/image/serverpage/image-id/1042i8AAD45F48E8039BC/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The login and logout date is set as same as it is appearing in my report and as you can see in Javascript console it printed the output fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is same output is not printing on my report page.&lt;/P&gt;&lt;P&gt;Secondly I tried to log the time_elapsed value in my catalina and alfresco logs by enabling debug mode in share/WEB-INF/classes/log4j.properties like this..&lt;/P&gt;&lt;PRE&gt;log4j.logger.org.springframework.extensions.webscripts.ScriptLogger=debug&lt;/PRE&gt;&lt;P&gt;And then I added line, &lt;STRONG&gt;logger.system.out(time_elapsed);&amp;nbsp;&lt;/STRONG&gt;in my js code but nothing logged in catalina.out or alfresco.log. Also tried &lt;STRONG&gt;logger.log(time_elapsed)&lt;/STRONG&gt; but it didn't logged the value&lt;/P&gt;&lt;P&gt;Can you please tell me how can I log "time_elapsed" in my alfresco logs?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 08:19:42 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139322#M37269</guid>
      <dc:creator>Syedjunaid</dc:creator>
      <dc:date>2021-05-19T08:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139323#M37270</link>
      <description>&lt;P&gt;1) logger.system.out has nothing to do with the log4j logger configuration - it simply prints to the standard output stream, which is not handled by log4j, and may - depending on Tomcat configuration - be either included in catalina.out or dropped completely&lt;/P&gt;
&lt;P&gt;2) for logging via log4j you should use logger.warn('your message') (alternatively, the operations debug(), log(), info(), error() should be available) - you should also set the logger for org.alfresco.repo.jscript.ScriptLogger to the same level in the log4j configuration, since Alfresco unfortunately has two similarily named classes used in different layers of the application (though for Repository scripts, the class I mentioned should be the one used for 99% of cases)&lt;/P&gt;
&lt;P&gt;3) I expect your issue with the weird character to be caused by your custom FTL / rendering code, which turns the calculated value into an undisplayable or even invalid unicode character due to implicit value type conversion&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 09:16:20 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139323#M37270</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-05-19T09:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139324#M37271</link>
      <description>&lt;P&gt;I have resolved my issue with the difference between login_date and logout_date not showing.&lt;/P&gt;&lt;P&gt;The issue was fixed by formatting the date through splitting every element of the date like&lt;/P&gt;&lt;PRE&gt;new Date( (year),(month),(date),(minutes),(seconds),(miliseconds))&lt;/PRE&gt;&lt;P&gt;Since I was getting login and logout date from Audit Rest API, what i did is&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; var res = login_date.match(/\d{1,4}/g)
        var login_time = new Date(res[0], res[1], res[2], res[3], res[4], res[5], res[6]).getTime();
        res = logout_date.match(/\d{1,4}/g)
        var logout_time = new Date(res[0], res[1], res[2], res[3], res[4], res[5], res[6]).getTime();
        var time_elapsed = (logout_time - login_time)/1000/60/60;&lt;/PRE&gt;&lt;P&gt;Anyway the issue is resolved, however thanks for actively replying to my queries and making me more clear about the problem I was facing.&lt;/P&gt;&lt;P&gt;thanks alott&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt;&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/76783"&gt;@EddieMay&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 07:28:52 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139324#M37271</guid>
      <dc:creator>Syedjunaid</dc:creator>
      <dc:date>2021-05-27T07:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates extracted by Audit API is not viewing.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139325#M37272</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/76245"&gt;@Syedjunaid&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well done for resolving your problem &amp;amp; thanks for updating your thread on how you did it - I'm sure that will be very helpful to other users.&lt;/P&gt;
&lt;P&gt;Onwards and upwards!&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 08:35:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/difference-between-two-dates-extracted-by-audit-api-is-not/m-p/139325#M37272</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2021-05-27T08:35:24Z</dc:date>
    </item>
  </channel>
</rss>

