von Karolus » So, 11.05.2014 16:20
Hallo
der Python Code wäre dann als Funktion anwendbar?
Nein, das ist nur ein schneller Entwurf per c&p aus einer Ipython-shell und noch ohne Korrektur falls Neujahr des Jahres auf Freitag bis Sonntag fällt.
Etwas ausgebaut mit mehreren Teststrings:
Code: Alles auswählen
from datetime import date, datetime, timedelta
dstrings = ['10245', '13245', '13432']
for dst in dstrings:
weeknum = int(dst[2:4])
d = datetime.strptime( dst , '%y%W%w')
correction = (not d.isocalendar()[1] == weeknum)
d = d-timedelta(weeks=correction)
print(date.isoformat(d), correction)
das ergibt die Ausgabe:
Karolus
Karolus
Hallo
[quote]der Python Code wäre dann als Funktion anwendbar?[/quote]
Nein, das ist nur ein schneller Entwurf per c&p aus einer Ipython-shell und noch ohne Korrektur falls Neujahr des Jahres auf Freitag bis Sonntag fällt.
Etwas ausgebaut mit mehreren Teststrings:
[code=php]from datetime import date, datetime, timedelta
dstrings = ['10245', '13245', '13432']
for dst in dstrings:
weeknum = int(dst[2:4])
d = datetime.strptime( dst , '%y%W%w')
correction = (not d.isocalendar()[1] == weeknum)
d = d-timedelta(weeks=correction)
print(date.isoformat(d), correction) [/code]
das ergibt die Ausgabe:
[code]2010-06-18 False
2013-06-14 True
2013-10-22 True[/code]
Karolus
Karolus