11"""
22Time Delta Calculator
33
4- This module provides functionality to calculate the absolute difference
4+ This module provides functionality to calculate the absolute difference
55in seconds between two timestamps in the format: Day dd Mon yyyy hh:mm:ss +xxxx
66"""
77# -----------------------------------------------------------------------------
3131# 88200
3232# ------------------------------------------------------------------------------
3333
34-
3534import datetime
3635from typing import List , Tuple
3736
3837
3938def parse_timestamp (timestamp : str ) -> datetime .datetime :
4039 """
4140 Parse a timestamp string into a datetime object.
42-
41+
4342 Args:
4443 timestamp: String in the format "Day dd Mon yyyy hh:mm:ss +xxxx"
45-
44+
4645 Returns:
4746 A datetime object with timezone information
4847 """
@@ -54,18 +53,18 @@ def parse_timestamp(timestamp: str) -> datetime.datetime:
5453def calculate_time_delta (t1 : str , t2 : str ) -> int :
5554 """
5655 Calculate the absolute time difference between two timestamps in seconds.
57-
56+
5857 Args:
5958 t1: First timestamp string
6059 t2: Second timestamp string
61-
60+
6261 Returns:
6362 Absolute time difference in seconds as an integer
6463 """
6564 # Parse both timestamps
6665 dt1 = parse_timestamp (t1 )
6766 dt2 = parse_timestamp (t2 )
68-
67+
6968 # Calculate absolute difference and convert to seconds
7069 time_difference = abs (dt1 - dt2 )
7170 return int (time_difference .total_seconds ())
@@ -74,7 +73,7 @@ def calculate_time_delta(t1: str, t2: str) -> int:
7473def read_test_cases () -> Tuple [int , List [Tuple [str , str ]]]:
7574 """
7675 Read test cases from standard input.
77-
76+
7877 Returns:
7978 A tuple containing:
8079 - Number of test cases
@@ -83,12 +82,12 @@ def read_test_cases() -> Tuple[int, List[Tuple[str, str]]]:
8382 try :
8483 num_test_cases = int (input ().strip ())
8584 test_cases = []
86-
85+
8786 for _ in range (num_test_cases ):
8887 timestamp1 = input ().strip ()
8988 timestamp2 = input ().strip ()
9089 test_cases .append ((timestamp1 , timestamp2 ))
91-
90+
9291 return num_test_cases , test_cases
9392 except ValueError as e :
9493 raise ValueError ("Invalid input format" ) from e
@@ -100,11 +99,11 @@ def main() -> None:
10099 """
101100 try :
102101 num_test_cases , test_cases = read_test_cases ()
103-
102+
104103 for t1 , t2 in test_cases :
105104 result = calculate_time_delta (t1 , t2 )
106105 print (result )
107-
106+
108107 except ValueError as e :
109108 print (f"Error: { e } " )
110109 except Exception as e :
0 commit comments