diff mbox series

[layerindex-web] settings: fix the minutes in REST API timestamps

Message ID 20261018214948.69706-1-tim.orling@konsulko.com
State New
Headers show
Series [layerindex-web] settings: fix the minutes in REST API timestamps | expand

Commit Message

Tim Orling Oct. 18, 2026, 9:49 p.m. UTC
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 <tim.orling@konsulko.com>
---
 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


base-commit: e6040597ae0f614581de241fe78f20e34dae13ac
diff mbox series

Patch

diff --git a/docker/settings.py b/docker/settings.py
index 90bc5f4..a4ea2d9 100644
--- a/docker/settings.py
+++ b/docker/settings.py
@@ -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
diff --git a/settings.py b/settings.py
index b318687..324ad50 100644
--- a/settings.py
+++ b/settings.py
@@ -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
diff --git a/tests/test_restapi.py b/tests/test_restapi.py
new file mode 100644
index 0000000..af1f708
--- /dev/null
+++ b/tests/test_restapi.py
@@ -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
+
+
+@pytest.mark.django_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')