import time
import timeit

"""
Explanation: Timing Functions in Python
<code>time</code> library link to docs <br>
<code>timeit</code> library link to docs <br>
End of explanation
"""


currentTime = time.gmtime()
print(currentTime)

"""
Explanation: UTC and local time
<code>time</code> has methods which return the UTC time and local time in a somewhat useless structure format. <br>
<code>time.gmtime()</code> returns the structure with the current gm or UTC time. <br>
<code>time.localtime()</code> returns a structure with the current local time <br>
End of explanation
"""


time.strftime("%a, %d %b %Y %H:%M:%S +0000", currentTime)

"""
Explanation: As you can see, the returned values are not very interesting or useful themselves. Lets parse structure into more useful forms. <br>
<br>
First, lets parse it into a human-readable form. This is useful for printing the time to the console, but generally would be used with a secondary form that is easier for a computer to read.
End of explanation
"""


type(currentTime)

"""
Explanation: Now lets parse it into a computer-friendly form. To start with, we should understand what type of structure <code>currentTime</code> is.
End of explanation
"""


currentTime.tm_hour

"""
Explanation: As we can see, <code>currentTime</code> is an instance of a class, <code>struct_time</code> as is defined in the <code>time</code> library.
The string that was returned when we ran <code>print(currentTime)</code> showed us the values associated with several of the class variables. We can access these class variables by using the dot "<code>.</code>" notation.
End of explanation
"""


def parseTime(timeObj):
    '''parseTime:
    takes time.struct_time instances
    :return  time displayed as string -  year month day hour min sec'''
    return (str(timeObj.tm_year) + str(timeObj.tm_mon) + str(timeObj.tm_mday) +
            str(timeObj.tm_hour) + str(timeObj.tm_min) + str(timeObj.tm_sec))

parseTime(currentTime)

"""
Explanation: With this knowledge, it becomes trivial to parse this data into a more usable format.
End of explanation
"""


