屏蔽睡眠时间戳为0的数据不做字符串处理 860/3 860/head 861/target/1
authorCaisking <3449750381@qq.com>
Tue, 3 Sep 2024 02:20:04 +0000 (10:20 +0800)
committerCaisking <3449750381@qq.com>
Tue, 3 Sep 2024 02:20:04 +0000 (10:20 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp

index b86e0e8..1db41a7 100644 (file)
@@ -536,16 +536,24 @@ namespace OHOS
         return true;
     }
 
+    // 时间戳->字符串
     void SleepModel::update_time_info(uint32_t timestamp, std::string &timeStr)
     {
+        // 如果时间戳为0,设置时间字符串为默认值
+        if (timestamp == 0)
+        {
+            timeStr = "--";
+            return;
+        }
+        // 解析时间戳
         char labelTime[20];
         if (uapi_get_TIME_STR(timestamp, labelTime, '.', ':', DATE_H_M) == ERRCODE_SUCC)
         {
-            timeStr = std::string(labelTime);
+            timeStr.assign(labelTime);
         }
         else
         {
-            timeStr = "--";
+            timeStr = "--"; // 如果获取失败,设置为默认值
         }
     }