from datetime import datetime


def set_clock(child, timestamp=None):
    """Set the device's clock.

    :param pexpect.spawn child: The connection in a child application object.
    :param datetime timestamp: A datetime tuple (year, month, day, hour, minute, second).
    :returns: The updated connection in a child application object.
    :rtype: pexpect.spawn
    """
    if not timestamp:
        timestamp = datetime.utcnow()
    child.sendline("clock set {0}\r".format(timestamp.strftime("%H:%M:%S %d %b %Y")))
    child.expect_exact("{0}, configured from console by console".format(timestamp.strftime("%H:%M:%S UTC %a %b %d %Y")))
    return child