Skip to content

Commit

Permalink
update:更新时间处理方式
Browse files Browse the repository at this point in the history
  • Loading branch information
yunlong098 committed Jan 9, 2025
1 parent 13c4e81 commit f132ec5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion saas/backend/api/management/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion saas/backend/api/management/v2/views/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions saas/backend/util/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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):
Expand Down

0 comments on commit f132ec5

Please sign in to comment.