Skip to content

Commit fd2177d

Browse files
author
Richard Jones
committed
expose the Date.pretty method to templating
1 parent 21143b7 commit fd2177d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ are given with the most recent entry first.
2424
- issues in 'done-cbb' are now also moved to 'chatting' on new messages
2525
- implemented the missing Interval.__add__
2626
- added ability to implement new templating utility methods
27+
- expose the Date.pretty method to templating
2728

2829

2930
2002-10-02 0.5.0

roundup/cgi/templating.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,16 @@ def reldate(self, pretty=1):
879879
return interval.pretty()
880880
return str(interval)
881881

882+
def pretty(self, format='%d %B %Y'):
883+
''' Render the date in a pretty format (eg. month names, spaces).
884+
885+
The format string is a standard python strftime format string.
886+
Note that if the day is zero, and appears at the start of the
887+
string, then it'll be stripped from the output. This is handy
888+
for the situatin when a date only specifies a month and a year.
889+
'''
890+
return self._value.pretty()
891+
882892
class IntervalHTMLProperty(HTMLProperty):
883893
def plain(self):
884894
''' Render a "plain" representation of the property

roundup/date.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.35 2002-10-11 01:25:40 richard Exp $
18+
# $Id: date.py,v 1.36 2002-10-12 23:10:36 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -206,12 +206,17 @@ def __str__(self):
206206
return '%4d-%02d-%02d.%02d:%02d:%02d'%(self.year, self.month, self.day,
207207
self.hour, self.minute, self.second)
208208

209-
def pretty(self):
209+
def pretty(self, format='%d %B %Y'):
210210
''' print up the date date using a pretty format...
211+
212+
Note that if the day is zero, and the day appears first in the
213+
format, then the day number will be removed from output.
211214
'''
212-
str = time.strftime('%d %B %Y', (self.year, self.month,
213-
self.day, self.hour, self.minute, self.second, 0, 0, 0))
214-
if str[0] == '0': return ' ' + str[1:]
215+
str = time.strftime(format, (self.year, self.month, self.day,
216+
self.hour, self.minute, self.second, 0, 0, 0))
217+
# handle zero day by removing it
218+
if format.startswith('%d') and str[0] == '0':
219+
return ' ' + str[1:]
215220
return str
216221

217222
def set(self, spec, offset=0, date_re=re.compile(r'''

0 commit comments

Comments
 (0)