[Mpuls-commits] r775 - in wasko/branches/2.0: . waskaweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Jan 19 21:14:15 CET 2010
Author: bh
Date: 2010-01-19 21:14:14 +0100 (Tue, 19 Jan 2010)
New Revision: 775
Modified:
wasko/branches/2.0/ChangeLog.txt
wasko/branches/2.0/waskaweb/lib/helpers.py
Log:
* waskaweb/lib/helpers.py (dd_mm_YYYY, HH_MM, dd_mm_yyyy_HH_MM):
Improve doc-strings and comments. Implement dd_mm_yyyy_HH_MM in
terms of the other two.
Modified: wasko/branches/2.0/ChangeLog.txt
===================================================================
--- wasko/branches/2.0/ChangeLog.txt 2010-01-19 20:09:26 UTC (rev 774)
+++ wasko/branches/2.0/ChangeLog.txt 2010-01-19 20:14:14 UTC (rev 775)
@@ -1,5 +1,11 @@
2010-01-19 Bernhard Herzog <bh at intevation.de>
+ * waskaweb/lib/helpers.py (dd_mm_YYYY, HH_MM, dd_mm_yyyy_HH_MM):
+ Improve doc-strings and comments. Implement dd_mm_yyyy_HH_MM in
+ terms of the other two.
+
+2010-01-19 Bernhard Herzog <bh at intevation.de>
+
* waskaweb/lib/helpers.py (date2str, time2str, datetime2str)
(format_date, format_time, format_datetime): The format_*
functions are basically just aliases for the *2str functions.
Modified: wasko/branches/2.0/waskaweb/lib/helpers.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/helpers.py 2010-01-19 20:09:26 UTC (rev 774)
+++ wasko/branches/2.0/waskaweb/lib/helpers.py 2010-01-19 20:14:14 UTC (rev 775)
@@ -162,9 +162,15 @@
log.error(err)
return dd_mm_yyyy_HH_MM(dt)
-def dd_mm_YYYY(d, empty = ''):
- ''' datetime.strftime() dislikes years before 1900. '''
- if d is None: return empty
+def dd_mm_YYYY(d, empty=''):
+ """Format the date of the date/time object d as 'dd.mm.YYYY'.
+ The parameter d may be a string or a datetime instance. If d is
+ None, the function return the optional parameter empty (default "").
+ """
+ # datetime.strftime() dislikes years before 1900.
+ if d is None:
+ return empty
+ # TODO: what should happen if d is a unicode object?
if type(d) == str:
try:
y,m,d = d.split('-')
@@ -174,20 +180,28 @@
return "%02d.%02d.%d" % (d.day, d.month, d.year)
def HH_MM(d):
- ''' datetime.strftime() dislikes years before 1900. '''
- if d is None: return ''
+ """Format the time object d as 'HH:MM'.
+ The parameter d may be a time, datetime or date instance. If it is
+ a date instance, time 00:00 is assumed. If d is None, the function
+ returns the empty string.
+ """
+ # datetime.strftime() dislikes years before 1900.
+ if d is None:
+ return ''
if type(d) is datetime.date:
# not so smart
d = datetime.datetime(d.year, d.month, d.day)
return "%02d:%02d" % (d.hour, d.minute)
def dd_mm_yyyy_HH_MM(d, empty = ''):
- ''' datetime.strftime() dislikes years before 1900. '''
- if d is None: return empty
- if type(d) is datetime.date:
- # not so smart
- d = datetime.datetime(d.year, d.month, d.day)
- return "%02d.%02d.%d %02d:%02d" % (d.day, d.month, d.year, d.hour, d.minute)
+ """Format the time/date object d as 'dd.mm.YYYY HH:MM'.
+ The parameter d may be a time, datetime or date instance. If it is
+ a date instance, time 00:00 is assumed. If d is None, the function
+ return the optional parameter empty (default"").
+ """
+ if d is None:
+ return empty
+ return dd_mm_YYYY(d) + " " + HH_MM(d)
def status_message(s):
return "%s: %s" % (dd_mm_yyyy_HH_MM(datetime.datetime.now()), s)
More information about the Mpuls-commits
mailing list