fix: 更正二代时间显示
This commit is contained in:
parent
9db639be7c
commit
1d3072d878
|
@ -1,4 +1,4 @@
|
|||
import time
|
||||
import pytz
|
||||
from typing import Optional
|
||||
from django.db.models import Q, Min, Max
|
||||
from django.core.cache import cache
|
||||
|
@ -286,6 +286,13 @@ class DeviceInfoSerializer(serializers.ModelSerializer):
|
|||
return None
|
||||
|
||||
def get_time(self, obj):
|
||||
# 区分一代和二代设备
|
||||
if obj.chip_type == 'AIR-V2':
|
||||
if self.mosq_device_info and self.mosq_device_info.update_time:
|
||||
eastern = pytz.timezone('Asia/Shanghai')
|
||||
update_time = self.mosq_device_info.update_time.astimezone(eastern)
|
||||
return update_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
if self.latest:
|
||||
return self.latest['data_time'].replace('T', ' ').replace('Z', '')
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue