string to date parser
This commit is contained in:
31
src/utils/stringtodate.py
Normal file
31
src/utils/stringtodate.py
Normal file
@@ -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")
|
||||||
Reference in New Issue
Block a user