diff --git a/saas/backend/api/management/v2/serializers.py b/saas/backend/api/management/v2/serializers.py index 5ea8fa0dd..eaad5f30b 100644 --- a/saas/backend/api/management/v2/serializers.py +++ b/saas/backend/api/management/v2/serializers.py @@ -167,7 +167,7 @@ class ManagementGroupMemberSLZ(serializers.Serializer): id = serializers.CharField(label="成员id") name = serializers.CharField(label="名称") expired_at = serializers.IntegerField(label="过期时间戳(单位秒)") - created_time = serializers.IntegerField(label="创建时间戳(单位秒)") + created_at = serializers.IntegerField(label="创建时间戳(单位秒)") class ManagementGroupMemberDeleteSLZ(serializers.Serializer): diff --git a/saas/backend/api/management/v2/views/group.py b/saas/backend/api/management/v2/views/group.py index d1dc38134..3f948eaa5 100644 --- a/saas/backend/api/management/v2/views/group.py +++ b/saas/backend/api/management/v2/views/group.py @@ -364,7 +364,7 @@ def list(self, request, *args, **kwargs): count, group_members = self.biz.list_paging_thin_group_member(group.id, limit, offset) results = [one.dict(include={"type", "id", "name", "expired_at", "created_time"}) for one in group_members] for result in results: - result['created_time'] = int(result['created_time'].timestamp()) + result['created_at'] = int(result.pop('created_time').timestamp()) return Response({"count": count, "results": results}) @swagger_auto_schema( diff --git a/saas/backend/util/time.py b/saas/backend/util/time.py index a5ce1e893..341e3c6f5 100644 --- a/saas/backend/util/time.py +++ b/saas/backend/util/time.py @@ -12,7 +12,6 @@ import time from django.utils import timezone -from dateutil import parser # type: ignore def string_to_datetime(str_time, fmt="%Y-%m-%d %H:%M:%S"): @@ -34,8 +33,9 @@ def utc_string_to_timestamp(str_time: str) -> int: """ 后端UTC时间转换为时间戳 """ - t = parser.isoparse(str_time) - return int(t.timestamp()) + naive_t = string_to_datetime(str_time, fmt="%Y-%m-%dT%H:%M:%SZ") + aware_t = naive_t.replace(tzinfo=datetime.timezone.utc) + return int(aware_t.timestamp()) def utc_to_local(utc_time):