[wiki] Pour calculer son âge

This commit is contained in:
Vincent Le Gallic 2014-01-31 00:19:08 +01:00
parent 5b839ef541
commit 0c14649a2c

18
wiki/macro/BirthDate.py Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from MoinMoin.wikiutil import escape
import time
import datetime
import re
def execute(macro, text):
year, month, day = text.split(",")
y, m, d = int(year), int(month), int(day)
now = datetime.datetime(*time.localtime()[:6])
birthdate = datetime.datetime(now.year, m, d)
age = now.year - y
if now < birthdate:
age -= 1
return macro.formatter.text(str(age))