From 0c14649a2cb2e017643f2625b1ebcd3aa5061ab4 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 31 Jan 2014 00:19:08 +0100 Subject: [PATCH] =?UTF-8?q?[wiki]=20Pour=20calculer=20son=20=C3=A2ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wiki/macro/BirthDate.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 wiki/macro/BirthDate.py diff --git a/wiki/macro/BirthDate.py b/wiki/macro/BirthDate.py new file mode 100644 index 00000000..dd2ab96b --- /dev/null +++ b/wiki/macro/BirthDate.py @@ -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))