scripts/wiki/macro/BirthDate.py
Kévin "NeK" Moisy-Mabille b2003525a7 Je sais pas coder en python…
2014-02-03 16:52:30 +01:00

26 lines
746 B
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Calcule l'âge en fonction de la date d'anniversaire (année, mois, jour)
en utilisant la date actuelle. """
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])
if m==2 and d==29:
birthdate = datetime.datetime(now.year, 3, 01)
if now.month==2 and now.day==29:
now = datetime.datetime(now.year, 3, 01)
else:
birthdate = datetime.datetime(now.year, m, d)
age = now.year - y
if now < birthdate:
age -= 1
return macro.formatter.text(str(age))