]> oss.titaniummirror.com Git - webber.git/commitdiff
webber.py: allow custom format for get_time() and format_date()
authorHolger Schurig <holgerschurig@gmail.com>
Wed, 7 Jul 2010 08:01:37 +0000 (10:01 +0200)
committerHolger Schurig <holgerschurig@gmail.com>
Wed, 7 Jul 2010 08:19:02 +0000 (10:19 +0200)
in/functions.md
webber.py

index 38a5d1e658fb767d04233c16bc9f74580b97d880..ea291ebd629e5c1d464780eeae8d2192b524967c 100644 (file)
@@ -2,8 +2,8 @@ title: Functions
 parent: Webber
 lang: en
 ctime: 2009-06-24
-mtime: 2010-06-24
-change: described get_toc()
+mtime: 2010-07-07
+change: allow custom format for get_time() and format_date()
 
 You can call functions only from [[template_mako]], not from
 [[pages|pageformat]]. If you need the latter, look at [[macros]].
@@ -17,17 +17,25 @@ You can call functions only from [[template_mako]], not from
 Here's list of functions defined by webber and it's default plugins:
 
 
-== format_date(timestamp) ==
+== format_date(timestamp, format) ==
 
 Takes a timestamp (seconds since 1st January 1970) and converts it into
-a string, using to `cfg.date_format`.
+a string.
+
+"`format`" is optional. If not used, "`cfg.date_format`" will be used.
+Otherwise it should be a format-string as documted by "`man strftime`". For
+example, "`%Y-%m-%d`" stands for year-month-date.
 
 Defined in `webber.py`.
 
 
-== get_time() ==
+== get_time(format) ==
+
+Returns the current date/time as a string.
 
-Returns the current date/time as a string according to `cfg.date_format`.
+"`format`" is optional. If not used, "`cfg.date_format`" will be used.
+Otherwise it should be a format-string as documted by "`man strftime`". For
+example, "`%Y-%m-%d`" stands for year-month-date.
 
 Defined in `webber.py`.
 
index 687e182fa89b93b70bf5c96e5606d2b52144e9ef..8d73f11c456f1679de1b04667b92147c6abd698a 100644 (file)
--- a/webber.py
+++ b/webber.py
@@ -445,12 +445,14 @@ def iso_to_time(val):
        return int(time.mktime(t))
 
 @set_function("format_date")
-def format_date(timestamp):
-       return time.strftime(cfg.date_format, time.localtime(timestamp))
+def format_date(timestamp, format=None):
+       if not format:
+               format = cfg.date_format
+       return time.strftime(format, time.localtime(timestamp))
 
 @set_function("get_time")
-def get_time():
-       return format_date(time.time())
+def get_time(format=None):
+       return format_date(time.time(), format)
 
 @set_function("get_current_file")
 def get_current_file():