Time Difference Calculator

Easy
14
67.5% Acceptance

In this lab, you will create a Python function time_difference() that calculates the difference in hours and minutes between two given times. The time will be in 24-hour format ('hh

'), and the output should be a dictionary with keys 'hours' and 'minutes'.

Constraints:

  • The time difference should not exceed 23 hours and 59 minutes.
  • The function must accurately handle times within the same day as well as times spanning across midnight.

Function Output:
The function should return a dictionary in the format: {'hours': <hours>, 'minutes': <minutes>}.

Examples:

  1. If start is '2:25' and end is '3:00', the function should return {'hours': 0, 'minutes': 35}.
  2. For start time '23:15' and end time '00:30' of the next day, the function should return {'hours': 1, 'minutes': 15}.

Your task is to implement the time_difference() function to pass all the challenges in this lab.