A closer look at the format_timestamp() function

This function serves the same purpose as the prior iteration, but returns a datetime object instead, since Peewee uses this object to write the data to the cell for datetime values. As we saw in the previous iteration, by using the fromtimestamp() method, we can convert the integer date value into a datetime object with ease. We can return the datetime object as is because Peewee handles the rest of the string formatting and conversion for us. This is shown in the following code:

216 def format_timestamp(ts):
217 """
218 The format_timestamp function converts an integer into a
219 datetime object
220 :param ts: An integer timestamp
221 :return: A datetime object
222 """
223 return datetime.datetime.fromtimestamp(ts)