From 089b2ce797cfe062efcc6c3390b80098d68f7572 Mon Sep 17 00:00:00 2001 From: Carlos Vega <carlos.vega@uni.lu> Date: Wed, 10 Oct 2018 14:17:40 +0200 Subject: [PATCH] added utils module for occasional functions --- smash/web/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 smash/web/utils.py diff --git a/smash/web/utils.py b/smash/web/utils.py new file mode 100644 index 00000000..85341925 --- /dev/null +++ b/smash/web/utils.py @@ -0,0 +1,23 @@ +# coding=utf-8 +from django.utils import timezone +import datetime, time + +def timeit(method): + def timed(*args, **kw): + ts = time.time() + result = method(*args, **kw) + te = time.time() + if 'log_time' in kw: + name = kw.get('log_name', method.__name__.upper()) + kw['log_time'][name] = int((te - ts) * 1000) + else: + print '%r %2.2f ms' % \ + (method.__name__, (te - ts) * 1000) + return result + return timed + +def get_today_midnight_date(): + today = timezone.now() + today_midnight = datetime.datetime(today.year, today.month, today.day, tzinfo=today.tzinfo) + return today_midnight + -- GitLab