Donkie / Spoolman

Keep track of your inventory of 3D-printer filament spools.
MIT License
1.01k stars 93 forks source link

Dates from API output are missing UTC time zone indicator #114

Closed pedrolamas closed 1 year ago

pedrolamas commented 1 year ago

Following up on this Fluidd issue, I have now realized that the date & times returned by the Spoolman API are missing the time zone indicator as per ISO 8601.

Spoolman documentation states that all dates are UTC time zone based, but the serialized representation does not convey that - and I believe this to be incorrect!

For example, calling /api/v1/spool, we get a list of spools and I can see the data in all date fields have no time zone indication:

image

As these are all UTC dates & times, these strings should end with a single "Z" - following the ISO and thus solving this issue in Fluidd and any other frontend.

As an example, lets take the first date from that example, "2023-07-30T10:59:52", and assume that my system is using Europe/London time zone which is currently UTC+1 as per British Summer Time.

Here's what I get in JavaScript by using the Date constructor:

image

On the first example, as there is no indication of time zone, Date will assume that it is on local time and parse and convert to UTC.

On the second example, I just suffixed the date with "Z" so that the Date constructor understands that I am indeed passing an UTC value, so no conversion is needed.

Donkie commented 1 year ago

Ah yes that is indeed a miss. I will make sure the right timezone marker is added.

Ocraftyone commented 1 year ago

@Donkie This issue still persists. It seems that the local time to UTC conversion is doubled up somewhere. When I edit the spool and set last used to the current time (using the GUI), upon save, it is converted to UTC. The GUI then shows the converted UTC time as local time. Then when you poll the API, the already converted UTC time is then converted again. I will provide screenshots of what I am seeing below.

Set to now (current local time) image

Click Save

Spools home page shows converted time image

And so does the edit page for the spool image

When the API is polled (/api/v1/spool), the result is

JSON Response [ { "id": 1, "registered": "2023-09-25T11:13:20Z", "last_used": "2023-09-25T11:26:43.540000Z", "filament": { "id": 1, "registered": "2023-09-25T11:12:56Z", "name": "asdf", "vendor": { "id": 1, "registered": "2023-09-25T11:12:28Z", "name": "asdf" }, "material": "PLA", "price": 28, "density": 1.24, "diameter": 1.75 }, "used_weight": 800, "used_length": 268226.89553341153, "archived": false } ]

Edit: Replaced code block with collapsed section bc the code block made it a readability nightmare Also, this was done on a clean instance of Spoolman