Coverage for annotation/timestamp_processor.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-12 17:57 +0000

1from datetime import timedelta 

2from util.functions import parse_datetime 

3 

4 

5class TimestampProcessor: 

6 """ 

7 Stores/accesses timestamp for annotations. 

8 """ 

9 

10 def __init__(self, timestamp: str): 

11 """ 

12 Parses loaded string into datetime object. 

13 

14 :param str timestamp: The timestamp to parse. 

15 """ 

16 self.timestamp = parse_datetime(timestamp=timestamp) 

17 if self.timestamp.microsecond >= 500000: 

18 self.timestamp = self.timestamp + timedelta(seconds=1) 

19 self.timestamp = self.timestamp.replace(microsecond=0) 

20 

21 def get_formatted_timestamp(self) -> str: 

22 """ 

23 Returns timestamp in format 00:00:00. 

24 

25 :return str: Timestamp as a formatted string. 

26 """ 

27 return '{:02}:{:02}:{:02}'.format(self.timestamp.hour, self.timestamp.minute, self.timestamp.second)