using strftime instead of a personnal function
This commit is contained in:
parent
de3db1405e
commit
e6854d7987
1 changed files with 6 additions and 46 deletions
|
@ -1,73 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils import timezone
|
||||
|
||||
french_days = {
|
||||
1: "lundi",
|
||||
2: "mardi",
|
||||
3: "mercredi",
|
||||
4: "jeudi",
|
||||
5: "vendredi",
|
||||
6: "samedi",
|
||||
7: "dimanche",
|
||||
}
|
||||
|
||||
french_months = {
|
||||
1: "janvier",
|
||||
2: "février",
|
||||
3: "mars",
|
||||
4: "avril",
|
||||
5: "mai",
|
||||
6: "juin",
|
||||
7: "juillet",
|
||||
8: "août",
|
||||
9: "septembre",
|
||||
10: "octobre",
|
||||
11: "novembre",
|
||||
12: "décembre",
|
||||
}
|
||||
|
||||
|
||||
def dayname(date):
|
||||
return french_days[date.isoweekday()]
|
||||
|
||||
|
||||
def weekname(date):
|
||||
(_, a, _) = date.isocalendar()
|
||||
week_num = a
|
||||
return "semaine %d" % week_num
|
||||
|
||||
|
||||
def monthname(date):
|
||||
return french_months[date.month]
|
||||
|
||||
|
||||
# Pareil mais pour une liste de dates
|
||||
# donne le nom des jours d'une liste de dates
|
||||
# dans un dico ordonné
|
||||
def daynames(dates):
|
||||
names = {}
|
||||
for i in dates:
|
||||
names[i] = dayname(dates[i])
|
||||
names[i] = dates[i].strftime("%A")
|
||||
return names
|
||||
|
||||
|
||||
# Pareil mais pour une liste de dates
|
||||
# donne le nom des semaines une liste de dates
|
||||
# dans un dico ordonné
|
||||
def weeknames(dates):
|
||||
names = {}
|
||||
for i in dates:
|
||||
names[i] = weekname(dates[i])
|
||||
names[i] = dates[i].strftime("Semaine %W")
|
||||
return names
|
||||
|
||||
|
||||
# Pareil mais pour une liste de dates
|
||||
# donne le nom des mois d'une liste de dates
|
||||
# dans un dico ordonné
|
||||
def monthnames(dates):
|
||||
names = {}
|
||||
for i in dates:
|
||||
names[i] = monthname(dates[i])
|
||||
names[i] = dates[i].strftime("%B")
|
||||
return names
|
||||
|
||||
|
||||
# rend les dates des nb derniers jours
|
||||
# dans l'ordre chronologique
|
||||
# aujourd'hui compris
|
||||
|
|
Loading…
Reference in a new issue