# represents a point in time without a date attached
class Time:

    # expects a string of the form HH:MM:SS
    # where hour are expressed in numbers from 0 to 23  
    def __init__(self, time_string):
        self.hour, self.minute, self.second = time_string.split(':')
        self.hour   = int(self.hour) 
        self.minute = int(self.minute)
        self.second = int(self.second)
    
    # returns a string in the form HH:MM:SS AM/PM 
    def format_time(self):
        hour = self.hour
        am_pm = 'AM'
        if hour > 12:
            hour -= 12
            am_pm = 'PM'
        return str(hour) + ':' + str(self.minute) + ':' + str(self.second) + ' ' + am_pm
        
    # returns the difference in seconds between two times
    def difference(self, other_time):
        seconds  = (self.hour - other_time.hour) * 60 * 60
        seconds += (self.minute - other_time.minute) * 60
        seconds += self.second - other_time.second
        return seconds

    # returns a string formated as follows
    # H[H] hours M[M] minutes S[S] seconds    
    def format_seconds(seconds):
        hours = seconds // (60 * 60)
        remainder = seconds % (60 * 60)
        minutes = remainder // 60
        seconds = remainder % 60
        return str(hours) + ' hours ' + str(minutes)+ ' minutes ' + str(seconds) + ' seconds'
        