Mercurial > getan > getan
view getan/utils.py @ 405:150180e972d3
Adds ability to adjust the length of (saved) entries.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Fri, 10 Feb 2017 15:01:07 +0100 |
parents | f21c1fe3b20b |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- # # (c) 2008, 2009, 2010 by # Sascha L. Teichmann <sascha.teichmann@intevation.de> # Ingo Weinzierl <ingo.weinzierl@intevation.de> # # This is Free Software licensed under the terms of GPLv3 or later. # For details see LICENSE coming with the source of 'getan'. # import logging global DATETIME_FORMAT DATETIME_FORMAT = "%Y-%m-%d" TIME_FORMAT = "%H:%M:%S" logger = logging.getLogger() def human_time(seconds): if seconds is None or seconds == 0: return "--:--:--" s = seconds % 60 seconds /= 60 m = seconds % 60 seconds /= 60 out = "%02d:%02d:%02d" % (seconds, m, s) return out def safe_int(s, default=0): try: return int(s) except ValueError: return default def short_time(seconds): if seconds is None: logger.warn( "short_time(): No seconds given to format to 'short_time'.") return "0:00h" seconds /= 60 m = seconds % 60 seconds /= 60 return "%d:%02dh" % (seconds, m) def format_datetime(datetime): return datetime.strftime(DATETIME_FORMAT) def format_time(datetime): return datetime.strftime(TIME_FORMAT)