# 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):
        hour, minute, second = time_string.split(':')
        hour   = int(hour) 
        minute = int(minute)
        second = int(second)
        self.seconds = hour * 60 * 60 + minute * 60 + second
        
    # returns a string in the form HH:MM:SS AM/PM  
    def format_time(self):
        hour = self.seconds // (60 * 60)
        remainder = self.seconds % (60 * 60)
        minute = remainder // 60
        second = remainder % 60
        am_pm = 'AM'
        if hour > 12:
            hour -= 12
            am_pm = 'PM'
        return str(hour) + ':' + str(minute) + ':' + str(second) + ' ' + am_pm

    # returns the difference in seconds between two times      
    def difference(self, other_time):
        return self.seconds - other_time.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'
        
        
