Mercurial > getan > getan
view getan/utils.py @ 135:ce707fbb9666
Change coding style of if clauses
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 31 Oct 2012 14:21:44 +0100 |
parents | 68cc10d082ab |
children | b5b3545ee1ea |
line wrap: on
line source
#!/usr/bin/env python # -*- 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 from datetime import datetime, timedelta global DATETIME_FORMAT DATETIME_FORMAT = "%Y-%m-%d" TIME_FORMAT = "%H:%M:%S" logger = logging.getLogger() def human_time(seconds): if seconds == 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)