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

Error in datediff calculation #1106

Open
Gravitar64 opened this issue Apr 28, 2022 · 3 comments
Open

Error in datediff calculation #1106

Gravitar64 opened this issue Apr 28, 2022 · 3 comments
Labels

Comments

@Gravitar64
Copy link

If i calculate the time difference between 2 datetime objects, the result is incorrect. Here an example:

import arrow
start = arrow.get('28.04.2022 14:00','DD.MM.YYYY HH:mm' )
end = arrow.now()
print(f'Start-Datetime: {start}')
print(f'End-Datetime : {end}')
print(f'Time-Difference: {end-start}')

Start-Datetime: 2022-04-28T14:00:00+00:00
End-Datetime : 2022-04-28T16:17:06.144073+02:00
Time-Difference: 0:17:06.144073

The correct Time-Difference should be 2:17:06......

System Info

  • 🖥 Windows 10 21H1:
  • 🐍 Python 3.9.9:
  • 🏹 Arrow 1.2.1:
@Gravitar64 Gravitar64 added the bug label Apr 28, 2022
@krisfremen
Copy link
Member

seems to be correct, the timezones differ by 2 hours, which makes up in the resulting time difference.

try specifying the timezones explicitly for now(), as it uses the local timezone, or switch to using utcnow().

@Gravitar64
Copy link
Author

Hi,

ok, I replaced the tzinfo for start to "Europe/Berlin". But that has no effect

start = arrow.now()
start.replace(tzinfo='Europe/Berlin')
end = arrow.get('30.04.2022 13:00','DD.MM.YYYY HH:mm')
print(f'Start-Datetime: {start}')
print(f'End-Datetime : {end}')
print(f'Time-Difference: {end-start}')

Start-Datetime: 2022-04-30T12:22:02.977434+02:00
End-Datetime : 2022-04-30T13:00:00+00:00
Time-Difference: 2:37:57.022566

The correct Time-Difference should be 00:37:57......

@systemcatch
Copy link
Collaborator

@Gravitar64 start and end are still in different timezones, you need to specify it for both of them.

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

3 participants