diff babel/dates.py @ 221:898b9450f274

Implement day-of-year date format field. Closes #49.
author cmlenz
date Mon, 16 Jul 2007 20:51:49 +0000
parents 4de6f4604830
children bc22f5aef216
line wrap: on
line diff
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -452,6 +452,8 @@
             return self.format_week(char, num)
         elif char == 'd':
             return self.format(self.value.day, num)
+        elif char == 'D':
+            return self.format_day_of_year(num)
         elif char in ('E', 'e', 'c'):
             return self.format_weekday(char, num)
         elif char == 'a':
@@ -518,6 +520,10 @@
         context = {3: 'format', 4: 'format', 5: 'stand-alone'}[num]
         return get_day_names(width, context, self.locale)[weekday]
 
+    def format_day_of_year(self, num):
+        delta = self.value - date(self.value.year, 1, 1)
+        return self.format(delta.days + 1, num)
+
     def format_period(self, char):
         period = {0: 'am', 1: 'pm'}[int(self.value.hour > 12)]
         return get_period_names(locale=self.locale)[period]
Copyright (C) 2012-2017 Edgewall Software