소스 검색

fix (datetime): timedelta can only deal with days and weeks

Since timedelta cannot deal with months and years (due to variable length),
split into y/m and d h:m:s. This allows entities with only day or second
for example, with large values, while still handling entities that specify
all components.

Issue #4466
Jason Rumney 6 일 전
부모
커밋
e5751ca1d8
1개의 변경된 파일3개의 추가작업 그리고 5개의 파일을 삭제
  1. 3 5
      custom_components/tuya_local/datetime.py

+ 3 - 5
custom_components/tuya_local/datetime.py

@@ -89,19 +89,17 @@ class TuyaLocalDateTime(TuyaLocalEntity, DateTimeEntity):
             return None
         year = year or 1970
         month = month or 1
-        day = day or 1
+        days = day or 1
         hours = hours or 0
         minutes = minutes or 0
         seconds = seconds or 0
         delta = timedelta(
-            years=int(year) - 1970,
-            months=int(month) - 1,
-            days=int(day) - 1,
+            days=int(days) - 1,
             hours=int(hours),
             minutes=int(minutes),
             seconds=int(seconds),
         )
-        return (EPOCH.astimezone(tz) + delta).datetime()
+        return (datetime(year=year, month=month, day=1, tzinfo=tz) + delta).datetime()
 
     async def async_set_value(self, value: datetime):
         """Set the datetime."""