'Convert to (potentially timezone-aware) `~datetime.datetime` object.
If ``timezone`` is not ``None``, return a timezone-aware datetime
object.
Parameters
timezone : {`~datetime.tzinfo`, None} (optional)
If not `None`, return timezone-aware datetime.
Returns
`~datetime.datetime`
If ``timezone`` is not ``None``, output will be timezone-aware.'

def to_value(self, timezone=None, parent=None):

    if (timezone is not None):
        if (self._scale != u'utc'):
            raise ScaleValueError(u"scale    is    {},    must    be    'utc'    when    timezone    is    supplied.".format(self._scale))
    scale = self.scale.upper().encode(u'ascii')
    (iys, ims, ids, ihmsfs) = erfa.d2dtf(scale, 6, self.jd1, self.jd2)
    ihrs = ihmsfs[..., 0]
    imins = ihmsfs[..., 1]
    isecs = ihmsfs[..., 2]
    ifracs = ihmsfs[..., 3]
    iterator = np.nditer([iys, ims, ids, ihrs, imins, isecs, ifracs, None], flags=[u'refs_ok'], op_dtypes=((7 * [iys.dtype]) + [np.object]))
    for (iy, im, id, ihr, imin, isec, ifracsec, out) in iterator:
        if (isec >= 60):
            raise ValueError(u'Time    {}    is    within    a    leap    second    but    datetime    does    not    support    leap    seconds'.format((iy, im, id, ihr, imin, isec, ifracsec)))
        if (timezone is not None):
            out[...] = datetime.datetime(iy, im, id, ihr, imin, isec, ifracsec, tzinfo=TimezoneInfo()).astimezone(timezone)
        else:
            out[...] = datetime.datetime(iy, im, id, ihr, imin, isec, ifracsec)
    return iterator.operands[(-1)]
