Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

execute_chore is formatting time in UTC time. grocy server ignores the timezone, so it shifts the date of chore execution #222

Closed
karwosts opened this issue Feb 26, 2022 · 3 comments

Comments

@karwosts
Copy link

karwosts commented Feb 26, 2022

I initially filed this issue on main grocy codebase, but it was closed as NAB

grocy/grocy#1799

When pygrocy calls track chores, it submits tracked time in UTC time (+00:00)

2022-02-25 16:56:59 DEBUG (SyncWorker_8) [pygrocy.grocy_api_client] -->	POST /chores/2/execute
2022-02-25 16:56:59 DEBUG (SyncWorker_8) [pygrocy.grocy_api_client] 		{'tracked_time': '2022-02-26T00:56:26.640992+00:00', 'done_by': 1}
2022-02-25 16:56:59 DEBUG (SyncWorker_8) [pygrocy.grocy_api_client] <--	200 for /chores/2/execute
2022-02-25 16:56:59 DEBUG (SyncWorker_8) [pygrocy.grocy_api_client] 		b'{"id":"14","chore_id":"2","tracked_time":"2022-02-26 00:00:00","done_by_user_id":"1","row_created_timestamp":"2022-02-25 16:56:59","undone":"0","undone_timestamp":null}'
2022-02-25 16:56:59 DEBUG (SyncWorker_7) [pygrocy.grocy_api_client] -->	GET //api/system/config
2022-02-25 16:56:59 DEBUG (SyncWorker_7) [pygrocy.grocy_api_client] <--	200 for //api/system/config

See how track chore called at 4:56pm local time is converted to a timestamp in utc time (12:56am+00:00)

Then in grocy they throw away the timestamp code

		if ($chore->track_date_only == 1)
		{
			$trackedTime = substr($trackedTime, 0, 10) . ' 00:00:00';
		}

So a chore executed in the afternoon of 2/25 is tracked in grocy server as completed on 2/26.

Can the track chore api be updated to submit the timestamp in the users local timezone, so that when grocy discards the timezone, the date is correct?

So submit the timestamp as 16:56:00-08:00, instead of 00:56:00+00:00.

@karwosts
Copy link
Author

Actually this might be doing the reverse of #51

I'm confused if it's not possible to fix this in a general way. It seems to me like grocy is not handling track_date_only chores correctly, but they claim it is not an issue.

@karwosts
Copy link
Author

Looks like maybe needs to be fixed here: hassio-addons/addon-grocy#274

@berrnd
Copy link

berrnd commented Feb 26, 2022

Just to note it also here what's the current state (since ever) about date-times in grocy to avoid confusion:

No timezone information is handled anywhere currently, so any date-time, on any API endpoint, needs to be provided without timezone information (or it would be ignored anyways).

So to make time related things work, all parts involved need to be in the same timezone - there are 3 settings:

  • The client (client side frontend JS uses that)
  • The OS setting of the server (SQLite uses that)
  • The php.ini setting date.timezone (PHP uses that)

This should be easily achievable in self hosted setups, when not already the case.

Timezone support in general is already tracked in grocy/grocy#214.

There is also the API endpoint /system/time which returns server-side time information:

grafik

time_local, time_local_sqlite3 and the local client time need to match.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants