import datetime
from flask import current_app
import dateutil

app = current_app


@app.template_filter()
def to_month(m):
    return [
        "januari",
        "februari",
        "maart",
        "april",
        "mei",
        "juni",
        "juli",
        "augustus",
        "september",
        "oktober",
        "november",
        "december",
    ][m - 1]


@app.template_filter()
def datetime_format(value: datetime.datetime):
    value = value.astimezone(dateutil.tz.gettz("Europe/Amsterdam"))
    return (
        f"{value.day} {to_month(value.month)} {value.year} om {value.strftime('%H:%M')}"
    )


@app.template_filter()
def date_format(value: datetime.date):
    return f"{value.day} {to_month(value.month)} {value.year}"
