settings: fix the minutes in REST API timestamps
PATCH 1/1 settings: fix the minutes in REST API timestamps
REST_FRAMEWORK['DATETIME_FORMAT'] used %m (the month) where the minutes belong, so every timestamp the API returned had the month in place of the minutes: 14:37 in October came out as 14:10. Use %M.
bitbake's layerindexlib keeps these values as opaque strings, so it is not affected.
AI-Generated: Claude Opus 5.5
Signed-off-by Tim Orling <[email protected]>
--- docker/settings.py | 2 +- settings.py | 2 +- tests/test_restapi.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/test_restapi.py
docker/settings.py +1 -1
@@ -195,7 +195,7 @@ REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'layerindex.restperm.ReadOnlyPermission', ), - 'DATETIME_FORMAT': '%Y-%m-%dT%H:%m:%S+0000', + 'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%S+0000', } # A sample logging configuration. The only tangible logging
settings.py +1 -1
@@ -195,7 +195,7 @@ REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'layerindex.restperm.ReadOnlyPermission', ), - 'DATETIME_FORMAT': '%Y-%m-%dT%H:%m:%S+0000', + 'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%S+0000', } # A sample logging configuration. The only tangible logging
tests/test_restapi.py new file +30 -0
@@ -0,0 +1,30 @@ +# layerindex-web - tests for the REST API +# +# Licensed under the MIT license, see COPYING.MIT for details +# +# SPDX-License-Identifier: MIT + +import datetime + +import pytest +from django.test import TestCase + +from layerindex.models import LayerItem + + [email protected]_db +class TestRestApiDatetimes(TestCase): + + def test_datetime_format(self): + layer = LayerItem.objects.create(name='meta-test', status='P', layer_type='A', + summary='test', description='test', + vcs_url='git://example.com/meta-test.git') + # auto_now would overwrite a value passed to save() + LayerItem.objects.filter(pk=layer.pk).update(updated=datetime.datetime(2026, 10, 18, 14, 37, 5)) + + response = self.client.get('/layerindex/api/layerItems/', {'format': 'json'}) + self.assertEqual(response.status_code, 200) + data = response.json() + items = data['results'] if isinstance(data, dict) else data + item = next(i for i in items if i['name'] == 'meta-test') + self.assertEqual(item['updated'], '2026-10-18T14:37:05+0000')
base-commit: e6040597ae0f614581de241fe78f20e34dae13ac
Signature · 1 line
2.56.0