diff --git a/botconfig.py.example b/botconfig.py.example index 2477c6e..bad3997 100644 --- a/botconfig.py.example +++ b/botconfig.py.example @@ -29,3 +29,6 @@ ALT_CHANNELS = "" ALLOWED_ALT_CHANNELS_COMMANDS = [] USE_UTC = True # if True, will use the UTC time, else the local time +# {tzname} and {tzoffset} can both be used; respectively the timezone name (like UTC) and offset in the form +0000 +# %Y is the year with century, %y is the year without, %m is the month, %d the day, %H hour, %M minute and %S seconds +TIMESTAMP_FORMAT = "[%Y-%m-%d %H:%M:%S{tzoffset}]" diff --git a/tools/__init__.py b/tools/__init__.py index e351851..ee6a35b 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -5,14 +5,19 @@ import time def get_timestamp(): """Returns a timestamp with timezone + offset from UTC.""" if botconfig.USE_UTC: - return datetime.datetime.utcnow().strftime("[%Y-%m-%d] (%H:%M:%S) UTC +0000 ") + tmf = datetime.datetime.utcnow().strftime(botconfig.TIMESTAMP_FORMAT) + if tmf[-1] != " ": + tmf += " " + return tmf.format(tzname="UTC", tzoffset="+0000") + tmf = time.strftime(botconfig.TIMESTAMP_FORMAT) + if tmf[-1] != " ": + tmf += " " + tz = time.strftime("%Z") utctime = datetime.datetime.utcnow().strftime("%H") nowtime = datetime.datetime.now().strftime("%H") - offset = "+" if int(utctime) > int(nowtime) else "-" - tz = str(time.timezone // 36) - if len(tz) == 3: - tz = "0" + tz - return time.strftime("[%Y-%m-%d] (%H:%M:%S) %Z {0}{1} ").upper().format(offset, tz) + offset = "-" if int(utctime) > int(nowtime) else "+" + offset += str(time.timezone // 36).zfill(4) + return tmf.format(tzname=tz, tzoffset=offset).upper() def logger(file, write=True, display=True): def log(*output, write=write, display=display):