You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When reading datetime fields from a file the @dateformat() works well but when writing the same dataclass with DataclassWriter it does not write them to the file in this format.
The text was updated successfully, but these errors were encountered:
Thank you for your comment. I am looking forward to next release!
Anyway, here is workaround that I'm using so far.
I hope this will help someone until next release.
# Create mydatetime to override the behaviour of the initializing (new) and saving (str) functions of datetime.classmydatetime(datetime.datetime):
def__new__(cls, *args, **kwargs):
iflen(args) ==1andtype(args[0]) isstr:
# Must not conflict with superclass implementations.# https://github.com/python/cpython/blob/d174ebe91ebc9f7388a22cc81cdc5f7be8bb8c9b/Lib/datetime.py#L1563returnsuper().strptime(args[0], "%Y-%m-%d %H:%M:%S.%f")
else:
returnsuper().__new__(cls, *args, *kwargs)
def__str__(self):
result=super().__str__()
ifint(self.microsecond) ==0:
# In the default str function, when microsecond is 0, the . %f" is not output, so make it output.returnresult+".0"else:
returnresult
When reading datetime fields from a file the @dateformat() works well but when writing the same dataclass with DataclassWriter it does not write them to the file in this format.
The text was updated successfully, but these errors were encountered: