mirror of
https://github.com/OpenMTC/OpenMTC.git
synced 2025-06-16 21:48:06 +00:00
initial commit
This commit is contained in:
39
build/lib/openmtc/util.py
Normal file
39
build/lib/openmtc/util.py
Normal file
@ -0,0 +1,39 @@
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
import time
|
||||
|
||||
ZERO = timedelta(0)
|
||||
|
||||
|
||||
class Utc(tzinfo):
|
||||
"""UTC
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return ZERO
|
||||
|
||||
def tzname(self, dt):
|
||||
return "UTC"
|
||||
|
||||
def dst(self, dt):
|
||||
return ZERO
|
||||
|
||||
UTC = Utc()
|
||||
|
||||
|
||||
#del Utc
|
||||
|
||||
|
||||
def datetime_now():
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
def datetime_the_future(offset = 0):
|
||||
""" Returns a datetime instance <offset> seconds in the future.
|
||||
@note: if no offset is provided or offset == 0, this is equivalent to datetime_now
|
||||
@param offset: seconds from now
|
||||
@return: datetime in <offset> seconds
|
||||
"""
|
||||
f = time.time() + offset
|
||||
return datetime.fromtimestamp(f, UTC)
|
||||
|
Reference in New Issue
Block a user