forked from stenyak/breakbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimestamp.py
34 lines (32 loc) · 1.17 KB
/
timestamp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright 2012 Bruno Gonzalez
# This software is released under the GNU AFFERO GENERAL PUBLIC LICENSE (see agpl-3.0.txt or www.gnu.org/licenses/agpl-3.0.html)
import time
import datetime
class Timestamp():
def __init__(self, ms_str = None, ms_int = None):
if ms_str is not None:
self.time = long(ms_str) / 1000. / 1000.
elif ms_int is not None:
self.time = ms_int / 1000. / 1000.
else:
self.time = time.time() #long
def to_human_str(self):
timestamp = self.time
dtime = datetime.datetime.fromtimestamp(timestamp)
return dtime.strftime("%Y-%m-%d %H:%M:%S.%f")
def __str__(self):
return str(self.ms_int())
def ms_int(self):
return int(round(self.time * 1000 * 1000))
def __eq__(self, other):
return self.time == other.time
def __ne__(self,other):
return self.time != other.time
def __lt__(self, other):
return self.time < other.time
def __gt__(self, other):
return self.time > other.time
def __le__(self, other):
return self.time <= other.time
def __ge__(self, other):
return self.time >= other.time