I know the name is not god but I don't know how to call it. If you find a better name please rename it.

   1 import re
   2 import calendar, cgi, time, re, string
   3 from MoinMoin import user
   4 from MoinMoin import config
   5 from MoinMoin import wikiutil
   6 from MoinMoin.i18n import _
   7 import MoinMoin.macro.IncludePages
   8 _args_re_dayoffset = r'^\s*(?P<dayoffset>-?\d+)'
   9 def execute(macro, text, args_re=re.compile(_args_re_dayoffset)):
  10     # parse and check arguments
  11     args = args_re.match(text)
  12     if not args:
  13         return ('<p><strong class="error">%s</strong></p>' %
  14             _('Invalid dateoffset arguments "%s"!')) % (text,)
  15     # get the arguments
  16     dayoffset = int(args.group('dayoffset'))
  17     # There are 86400 seconds in a day.
  18     datetofind = time.time() + dayoffset * 86400
  19     (year,month,day,h,m,s,wd,yd,ds) = time.localtime(datetofind)
  20     return macro.request.user.getFormattedDate(datetofind)

Sorry for the dump question, but what exactly is this macro good for? -- FlorianFesti 2003-10-07 07:56:50
it's good to display the date of a day relative to today. I haven't found something that does that. Please correct me if i'm wrong -- 1st-angel 2003-10-07 14:36:21
Yes, I got that. But I can't imagine a use for it.
I created a Wiki for my class in school where we write down the Homework we have to do. On this page i wrote a overview page where the Homework for the next 5 days are displayed.It looks like this
<date of today>
<homework for today>
<date of tomorrow>
<homework for tomorrow>
...
For this page I needed such a script because I don't want to change the page every day.
The Content is done via a MonthCalendar.
-- 1st-angel 2003-10-07 15:50:58

Does this work with the latest version? I am having issues... can't find the macro. :(


The macro is useful for time tables, project plans and release dates; "version 1.2 will be released at DateOffset(+1)" or "Deadline: DateOffset(-1)"; like in the little [[tomorrow]] - macro:

   1 """
   2   MoinMoin - tomorrow Macro
   3 
   4   Written by Daniela Nicklas <dani@miracle-solutions.de>
   5 
   6   Useful for project plans, release dates and time tables:
   7   inserts tomorrow's date
   8 """
   9 import time
  10 def execute(macro, args):
  11     tomorrow = time.time() + 3600*24
  12     return = macro.execute('Date', str(tomorrow))

:-) -- DanielaNicklas 2003-12-01 09:46:42

MoinMoin: macro/DateOffset.py (last edited 2007-10-29 19:11:59 by localhost)