Coverage for kwai/core/domain/value_objects/traceable_time.py: 91%
11 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that defines a value object to trace creation/update time of an entity."""
2from dataclasses import dataclass, field
4from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp
7@dataclass(frozen=True, kw_only=True)
8class TraceableTime:
9 """A value object to track creation/update time."""
11 created_at: LocalTimestamp = field(default_factory=LocalTimestamp.create_now)
12 updated_at: LocalTimestamp = field(default_factory=LocalTimestamp)
14 @property
15 def is_updated(self):
16 """Check if this entity has been updated."""
17 return not self.updated_at.empty()
19 def mark_for_update(self) -> "TraceableTime":
20 """Set the update time to the current time."""
21 return TraceableTime(
22 created_at=self.created_at, updated_at=LocalTimestamp.create_now()
23 )