Ver Fonte

变量名称修改

lifanagju_citu há 2 meses atrás
pai
commit
3846fe3929
1 ficheiros alterados com 4 adições e 6 exclusões
  1. 4 6
      src/utils/transform/date.js

+ 4 - 6
src/utils/transform/date.js

@@ -29,13 +29,11 @@ export const getTimeStamp = (str) => {
 export const timestampToAge = (timestamp) => {
   if (!timestamp) return null
   const birthDate = new Date(timestamp);
-  const currentDate = new Date();
-  let age = currentDate.getFullYear() - birthDate.getFullYear();
-  const monthDiff = currentDate.getMonth() - birthDate.getMonth();
+  const today = new Date();
+  let age = today.getFullYear() - birthDate.getFullYear();
+  const monthDiff = today.getMonth() - birthDate.getMonth();
   // 如果当前月份小于出生月份,或者月份相同但日期未到生日
-  if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) {
-    age--;
-  }
+  if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) age--;
   return age;
 }