Coverage for src/kwai/core/domain/value_objects/traceable_time.py: 91%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines a value object to trace creation/update time of an entity.""" 

2 

3from dataclasses import dataclass, field 

4 

5from kwai.core.domain.value_objects.timestamp import Timestamp 

6 

7 

8@dataclass(frozen=True, kw_only=True) 

9class TraceableTime: 

10 """A value object to track creation/update time.""" 

11 

12 created_at: Timestamp = field(default_factory=Timestamp.create_now) 

13 updated_at: Timestamp = field(default_factory=Timestamp) 

14 

15 @property 

16 def is_updated(self): 

17 """Check if this entity has been updated.""" 

18 return not self.updated_at.empty() 

19 

20 def mark_for_update(self) -> "TraceableTime": 

21 """Set the update time to the current time.""" 

22 return TraceableTime( 

23 created_at=self.created_at, updated_at=Timestamp.create_now() 

24 )