traggo / server

self-hosted tag-based time tracking
https://traggo.net
GNU General Public License v3.0
1.21k stars 58 forks source link

Error in duration #169

Closed seb49 closed 6 months ago

seb49 commented 6 months ago

Hello,

I'm in France, it's 05:25 PM, I have an active timer launch à 1:07 PM so barely 4 hours and 20 minutes. But traggo display only 2 hours and 20 minutes

image

jmattheis commented 6 months ago

Could you share your database file. You could send it to the email on my profile. This is likely due to starting and stopping the time span in different timezones, this can be due to different browser settings.

seb49 commented 6 months ago

This is done

seb49 commented 6 months ago

In the same way, there are 2 hours gap in this view image

jmattheis commented 6 months ago

Yeah, you likely use traggo from browsers that have different timezones configured. There are offsets for gmt+2, gmt+1 and utc in the database.

Tracking time across time zones is really difficult. In your first screenshat your browser is likely configured in utc time. So at 17:00 in france it's 15:00 utc and the the duration is fine. You can probably fix this by configuring your browser so that it has the correct timezone.

seb49 commented 6 months ago

Thanks for your reply

I think it's more touchy. I use graphql to create entries. But I show in database there is this field

start_utc
end_utc
start_user_time
end_user_time

but graphql use only start and end

createTimeSpan(
start: Time!
end: Time
tags: [InputTimeSpanTag!]
note: String!
): TimeSpan

here is some entries from databases

sqlite> select * from time_spans where id in (377,378,379);
377|2024-05-16 08:11:31+00:00||2024-05-16 08:11:31+00:00||0|1|PYTHON
378|2024-05-16 07:18:56+00:00|2024-05-16 07:20:54+00:00|2024-05-16 09:18:56+00:00|2024-05-16 09:20:54+00:00|7200|1|
379|2024-05-16 07:27:25+00:00||2024-05-16 09:27:25+00:00||7200|1|

if you read "Python", entry is create with graphql, otherwise, from browser. With browser there is 2 hours gap between user_time and utc

Regards

jmattheis commented 6 months ago

Then you have to fix this in your script and send your timestamps with a timezone offset.

seb49 commented 6 months ago

This is what I do to get time def GetCurrentDate(): current_datetime_utc = datetime.now(timezone.utc).replace(tzinfo=pytz.UTC) desired_timezone = pytz.timezone('Europe/Paris') current_datetime_Paris = current_datetime_utc.astimezone(desired_timezone) formatted_datetime_utc_plus_one = current_datetime_Paris.strftime("%Y-%m-%dT%H:%M:%SZ") return formatted_datetime_utc_plus_one

But event if I remove desired_timezone = pytz.timezone('Europe/Paris')

there is no logic

image

image

the good display is on the calendar

jmattheis commented 6 months ago

Not a python dev, but you can get the current time with a timezone which will return the right offset.

def GetCurrentDate():
    tz = pytz.timezone('Europe/Paris')
    return datetime.now(tz).isoformat()
# outputs: 2024-05-21T12:06:08.996211+02:00

Your method outputs 2024-05-21T12:06:08Z

seb49 commented 6 months ago

Great, it's work thanks. But I don't understand why the table contains more filed than graphql can use (start_utc, end_utc, start_user_time, end_user_time)