Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time2Internaldate is not working with int or float time #52

Open
iliyan85 opened this issue Jul 28, 2024 · 1 comment
Open

Time2Internaldate is not working with int or float time #52

iliyan85 opened this issue Jul 28, 2024 · 1 comment
Labels

Comments

@iliyan85
Copy link

time.time() or other int or float value throws an exception when it is using as date_time input for Time2Internaldate function.

The error message is:
UnboundLocalError: cannot access local variable 'dt' where it is not associated with a value

if isinstance(date_time, (int, float)): #time.time() returns True
tt = time.localtime(date_time)

and after that
fmt = '"%d-{}-%Y %H:%M:%S %z"'.format(MonthNames[dt.month])

'dt' cannot be used.

Time2Internaldate works correctly by the following way:

dt = datetime.datetime.now(pytz.timezone('Europe/Sofia'))
imaplib2.Time2Internaldate(dt)

@iliyan85 iliyan85 changed the title Time2Internaldate is not working with int of float time Time2Internaldate is not working with int or float time Jul 28, 2024
@piyueh
Copy link
Member

piyueh commented Aug 1, 2024

Thanks. I haven't taken a deeper look into it, but I think it can be fixed by changing the following line:

tt = time.localtime(date_time)

to dt = datetime.fromtimestamp(time.mktime(time.localtime(date_time))).

But again, I haven't had time to actually test it.

@piyueh piyueh added the bug label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants