• + 0 comments

    I meet some difficulties to solve this problem because I first think that we have to used Calendar module. But in fact, we have to use datetime module. From the documentation, we have a full table with all meaning of %a, %b etc...

    Once we have this knowledge, we can just go step by step by solving each error one after one.

    Here, I convert both datetime in delta_time thanks to the conversion value of the documentation.

    Then, I do the difference.

    Finally, because test case 1 and 2 were not solved cause of values like "-123456" instead of "123456", I just add a small if/else condition to remove this possible "-".

    Here the code :

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    from datetime import datetime
    
    # Complete the time_delta function below.
    def time_delta(t1, t2):
        
        delta_time_t1 = datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
        delta_time_t2 = datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')
        
        difference_delta_time = delta_time_t1 - delta_time_t2
        
        #print(delta_time_t1)
        #print(delta_time_t2)
        #print(int(difference_delta_time.total_seconds()))
        
        output = str(int(difference_delta_time.total_seconds()))
        
        #print(output[0])    
        
        output = output[1:] if output.startswith('-') else output
    
        return output
        
        return 500
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(input())
    
        for t_itr in range(t):
            t1 = input()
    
            t2 = input()
    
            delta = time_delta(t1, t2)
    
            fptr.write(delta + '\n')
    
        fptr.close()