import copy
import time


def process_like(proc):
    """Make an exact clone of a process, including state and all subprocesses.

    The creation date is updated.

    :param proc:    process
    :type proc:     :class:`~climlab.process.process.Process`
    :return:        new process identical to the given process
    :rtype:         :class:`~climlab.process.process.Process`

    :Example:

        ::

            >>> import climlab
            >>> from climlab.process.process import process_like

            >>> model = climlab.EBM()
            >>> model.subprocess.keys()
            ['diffusion', 'LW', 'albedo', 'insolation']

            >>> albedo = model.subprocess['albedo']
            >>> albedo_copy = process_like(albedo)

            >>> albedo.creation_date
            'Thu, 24 Mar 2016 01:32:25 +0000'

            >>> albedo_copy.creation_date
            'Thu, 24 Mar 2016 01:33:29 +0000'

    """
    newproc = copy.deepcopy(proc)
    newproc.creation_date = time.strftime("%a, %d %b %Y %H:%M:%S %z",
                                          time.localtime())
    return newproc