From 3621789a47154dd25ae948b2614238088bd98be7 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:34:31 +0200 Subject: [PATCH] string to date parser --- src/utils/stringtodate.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/utils/stringtodate.py diff --git a/src/utils/stringtodate.py b/src/utils/stringtodate.py new file mode 100644 index 0000000..be623a8 --- /dev/null +++ b/src/utils/stringtodate.py @@ -0,0 +1,31 @@ +# import qdate +from PyQt6 import QtCore + + +def stringToDate(date: str) -> QtCore.QDate: + """Takes an input string and returns a QDate object. + + Args: + date (str): the string of the date in the database, format: WDay Month Day Year + + Returns: + QtCore.QDate: the QDate object in string format DD.MM.yyyy + """ + + datedata = date.split(" ")[1:] + month = datedata[0] + day = datedata[1] + year = datedata[2] + month = month.replace("Jan", "01") + month = month.replace("Feb", "02") + month = month.replace("Mar", "03") + month = month.replace("Apr", "04") + month = month.replace("May", "05") + month = month.replace("Jun", "06") + month = month.replace("Jul", "07") + month = month.replace("Aug", "08") + month = month.replace("Sep", "09") + month = month.replace("Oct", "10") + month = month.replace("Nov", "11") + month = month.replace("Dec", "12") + return QtCore.QDate(int(year), int(month), int(day)).toString("dd.MM.yyyy")