AD2PI zone events log in UTC time instead of local timezone

General Discussion

AD2PI zone events log in UTC time instead of local timezone

Postby m_listed » Sun Jan 22, 2017 1:08 pm

I set my Raspberry Pi's time zone to my local zone, and this seems to be working for the "App" and "Live" logs, but for the "Events" log, the AD2PI app continues to log every event according to UTC time instead of local time. How can I make it so these events are logged per local time as well?
m_listed
newt
newt
 
Posts: 5
Joined: Thu Jan 12, 2017 11:13 pm

Re: AD2PI zone events log in UTC time instead of local timez

Postby kevin » Sun Jan 22, 2017 2:01 pm

Login via ssh and set your date/time, we ship it as UTC by default - https://www.cyberciti.biz/faq/howto-set ... nd-prompt/

The python event stores the current date/time in the database and on rendering the datatable it is passed through a javascript function to normalize to your localtime - so I would check that date/time parameters are set correctly. I suggest the timedatectl method

Event log timestamps are converted using the following function:
Code: Select all
        function RenderDateLocal(oObj)
        {
            //parse date from python to format Date object understands
            var match = oObj.aData[oObj.iDataColumn].match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/);
            var localDate = new Date(match[1], match[2] - 1, match[3], match[4], match[5], match[6]);
            //take care of timezone offset in minutes to hours by negating and then adding to the hours
            var tzo = (localDate.getTimezoneOffset()/60) *-1;
            localDate.setHours(localDate.getHours() + tzo );
            //reformat date for consistency
            var dateStr = localDate.getFullYear() + "-" + (localDate.getMonth() + 1) + "-" + localDate.getDate() + " " + localDate.toLocaleTimeString();
            return dateStr;
        }
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: AD2PI zone events log in UTC time instead of local timez

Postby m_listed » Sun Jan 22, 2017 6:17 pm

I don't think JavaScript has a central place where the timezone is set, but timedatectl nevertheless shows the correct local time and UTC time because I did "sudo dpkg-reconfigure tzdata" and set it to my local timezone. The Alarmdecoder web app still shows all zone fault and restore etc. events as UTC though. It was working correctly (i.e. logging in local time) before the latest update though.
m_listed
newt
newt
 
Posts: 5
Joined: Thu Jan 12, 2017 11:13 pm

Re: AD2PI zone events log in UTC time instead of local timez

Postby kevin » Sun Jan 22, 2017 10:56 pm

All right, please file an issue on the github project and it'll be added to the list of things to investigate/fix on another release.

The JavaScript above uses your local clientside computer's time data to calculate based off of time/date from event in datatable
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: AD2PI zone events log in UTC time instead of local timez

Postby billfor » Wed Mar 01, 2017 5:09 pm

Looks like fnRender is ignored if used, so the RenderDataLocal never gets called. fnrender has been deprecated from jQuery so you have to use mRender going forward.

The "Live" section never had the problem because the code doesn't actually pull the value from a database -- it just stamps it with your currently time. So there is no transformation there.

Do you want me to file a bug?

fyi if you want to fix it temporarily, find the events.html file and change this line:
{"fnRender": RenderDateLocal },
to
{"mRender": RenderDateLocal },


now because mRender works differently, you also have to change the rendering function.

change
function RenderDateLocal(oObj)
to
function RenderDateLocal(data,type,full)

and change the first line that has the regex matching to:

var match = data.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/);
billfor
Junior Nut
Junior Nut
 
Posts: 29
Joined: Wed Mar 01, 2017 4:32 pm

Re: AD2PI zone events log in UTC time instead of local timez

Postby kevin » Thu Mar 02, 2017 10:21 am

billfor wrote:Looks like fnRender is ignored if used, so the RenderDataLocal never gets called. fnrender has been deprecated from jQuery so you have to use mRender going forward.

The "Live" section never had the problem because the code doesn't actually pull the value from a database -- it just stamps it with your currently time. So there is no transformation there.

Do you want me to file a bug?

fyi if you want to fix it temporarily, find the events.html file and change this line:
{"fnRender": RenderDateLocal },
to
{"mRender": RenderDateLocal },


now because mRender works differently, you also have to change the rendering function.

change
function RenderDateLocal(oObj)
to
function RenderDateLocal(data,type,full)

and change the first line that has the regex matching to:

var match = data.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/);


Looks like we stumbled upon this fix around the same time. I did it a little differently. Yes to the mRender step, but did not change prototype of RenderDateLocal at all

Code: Select all
        function RenderDateLocal(oObj)
        {
            //parse date from python to format Date object understands
            var match = oObj.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/);

            var localDate = new Date(match[1], match[2] - 1, match[3], match[4], match[5], match[6]);

            //take care of timezone offset in minutes to hours by negating and then adding to the hours
            var tzo = (localDate.getTimezoneOffset()/60) *-1;
            localDate.setHours(localDate.getHours() + tzo );

            //reformat date for consistency
            var dateStr = localDate.getFullYear() + "-" + (localDate.getMonth() + 1) + "-" + localDate.getDate() + " " + localDate.toLocaleTimeString();
            return dateStr;
        }



At any rate, this was due to an upgrade of the dataTables plugin that we use - and is fixed locally here - hopefully pushed to github sometime soon.

Thanks for your help!
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: AD2PI zone events log in UTC time instead of local timez

Postby billfor » Thu Mar 02, 2017 10:55 am

Yeah the other arguments are thrown away but technically the definition of mRender calls for a 3 argument function so I just added them as per their spec. It was interesting that the Jquery developers decided to deprecate and nullify an old function rather than just leaving the behavior there for people who had used it. Anyway it works now -- was just annyoing the hell out me so had to fix it :-)
billfor
Junior Nut
Junior Nut
 
Posts: 29
Joined: Wed Mar 01, 2017 4:32 pm


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron