Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

def nowUnix returns the wrong time #188

Open
nojeffrey opened this issue Jun 5, 2015 · 2 comments
Open

def nowUnix returns the wrong time #188

nojeffrey opened this issue Jun 5, 2015 · 2 comments

Comments

@nojeffrey
Copy link

In core/dblog.py, line 61:
def nowUnix(self):
"""return the current UTC time as an UNIX timestamp"""
return int(time.mktime(time.gmtime()[:-1] + (-1,)))

If I just run this inside python:

import time
int(time.mktime(time.gmtime()[:-1] + (-1,)))
1433447440

If i just run this from command line:
$ date +"%s"
$ 1433483440

It's 36000 seconds off, is this normal?

@svc-user
Copy link

svc-user commented Jun 5, 2015

Sounds very much as a timezone gone wrong. My guess is that the python code returns the timestamp in GMT and your system is set to GMT+1 or GMT-1.

Could this be the case?

On June 5, 2015 8:22:55 AM GMT+02:00, nojeffrey notifications@github.com wrote:

In core/dblog.py, line 61:
def nowUnix(self):
"""return the current UTC time as an UNIX timestamp"""
return int(time.mktime(time.gmtime()[:-1] + (-1,)))

If I just run this inside python:

import time
int(time.mktime(time.gmtime()[:-1] + (-1,)))
1433447440

If i just run this from command line:
$ date +"%s"
$ 1433483440

It's 36000 seconds off, is this normal?


Reply to this email directly or view it on GitHub:
#188

@nojeffrey
Copy link
Author

I'm in +10 timezone here which is 36000 seconds off UTC time.
But the timestamp in the DB is not UTC or my +10 either
My system timezone is set to +10, so my current time is 17:27

if I run: >>> time.time(), in python it returns the right epoch time(UTC): 1433489239
If i run: date +"%s" it return the same epoch time as above(1433489239).
If I run: date --utc, it returns: Fri Jun 5 07:27:35 UTC 2015

If i do a failed SSH login, and check the DB, I see this line:
+----+----------------------------------+---------+----------+------------+---------------------+
| id | session | success | username | password | timestamp |
+----+----------------------------------+---------+----------+------------+---------------------+
| 1 | c951bdba0b5211e5b632005056ba4905 | 0 | root | xzlgnfkakj | 2015-06-05 08:27:30 |
+----+----------------------------------+---------+----------+------------+---------------------+

This timestamp is 1 hour off of UTC time, and 11 hours off my +10 timezone.
Is something in: "return int(time.mktime(time.gmtime()[:-1] + (-1,)))" modifying the time by 1 hour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants