add reverse function

This commit is contained in:
WorldTeacher
2024-07-29 10:29:21 +02:00
parent 0e8e6c5c40
commit a088c723fb

View File

@@ -1,7 +1,6 @@
# import qdate # import qdate
from PyQt6 import QtCore from PyQt6 import QtCore
from .debug import debugMessage
def stringToDate(date: str) -> QtCore.QDate: def stringToDate(date: str) -> QtCore.QDate:
"""Takes an input string and returns a QDate object. """Takes an input string and returns a QDate object.
@@ -11,21 +10,31 @@ def stringToDate(date: str) -> QtCore.QDate:
Returns: Returns:
QtCore.QDate: the QDate object in string format DD.MM.yyyy QtCore.QDate: the QDate object in string format DD.MM.yyyy
""" """
debugMessage(date=date)
datedata = date.split(" ")[1:] if not date:
month = datedata[0] return ""
day = datedata[1] if "." in date:
year = datedata[2] # converts the date from dd.mm.yyyy to qdate
month = month.replace("Jan", "01") datedata = date.split(".")
month = month.replace("Feb", "02") day = datedata[0]
month = month.replace("Mar", "03") month = datedata[1]
month = month.replace("Apr", "04") year = datedata[2]
month = month.replace("May", "05") return QtCore.QDate(int(year), int(month), int(day)) # .toString("dd.MM.yyyy")
month = month.replace("Jun", "06") else:
month = month.replace("Jul", "07") datedata = date.split(" ")[1:]
month = month.replace("Aug", "08") month = datedata[0]
month = month.replace("Sep", "09") day = datedata[1]
month = month.replace("Oct", "10") year = datedata[2]
month = month.replace("Nov", "11") month = month.replace("Jan", "01")
month = month.replace("Dec", "12") month = month.replace("Feb", "02")
return QtCore.QDate(int(year), int(month), int(day)).toString("dd.MM.yyyy") 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")