.. versionadded:: 0.2.0

    Returns a timestamp in the format produced by |date_tostring|_, e.g.::

        Mon Sep 02 14:00:54 EDT 2016

    If ``timestamp`` is `True` (the default), the current date & time is
    returned.

    If ``timestamp`` is `None` or `False`, an empty string is returned.

    If ``timestamp`` is a number, it is converted from seconds since the epoch
    to local time.

    If ``timestamp`` is a `datetime.datetime` object, its value is used
    directly, with naïve objects assumed to be in the local timezone.

    The timestamp is always constructed using the C locale.

    :param timestamp: the date & time to display
    :type timestamp: `None`, `bool`, number, or `datetime.datetime`
    :rtype: text string

    .. |date_tostring| replace:: Java 8's ``Date.toString()``
    .. _date_tostring: https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toString--

def java_timestamp(timestamp=True):
    """
    .. versionadded:: 0.2.0

    Returns a timestamp in the format produced by |date_tostring|_, e.g.::

        Mon Sep 02 14:00:54 EDT 2016

    If ``timestamp`` is `True` (the default), the current date & time is
    returned.

    If ``timestamp`` is `None` or `False`, an empty string is returned.

    If ``timestamp`` is a number, it is converted from seconds since the epoch
    to local time.

    If ``timestamp`` is a `datetime.datetime` object, its value is used
    directly, with naïve objects assumed to be in the local timezone.

    The timestamp is always constructed using the C locale.

    :param timestamp: the date & time to display
    :type timestamp: `None`, `bool`, number, or `datetime.datetime`
    :rtype: text string

    .. |date_tostring| replace:: Java 8's ``Date.toString()``
    .. _date_tostring: https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toString--
    """
    if timestamp is None or timestamp is False:
        return ''
    if isinstance(timestamp, datetime) and timestamp.tzinfo is not None:
        timebits = timestamp.timetuple()
        # Assumes `timestamp.tzinfo.tzname()` is meaningful/useful
        tzname = timestamp.tzname()
    else:
        if timestamp is True:
            timestamp = None
        elif isinstance(timestamp, datetime):
            try:
                # Use `datetime.timestamp()` if it's available, as it (unlike
                # `datetime.timetuple()`) takes `fold` into account for naïve
                # datetimes
                timestamp = timestamp.timestamp()
            except AttributeError:  # Pre-Python 3.3
                # Mapping `timetuple` through `mktime` and `localtime` is
                # necessary for determining whether DST is in effect (which, in
                # turn, is necessary for determining which timezone name to
                # use).  The only downside to using standard functions instead
                # of `python-dateutil` is that `mktime`, apparently, handles
                # times duplicated by DST non-deterministically (cf.
                # <https://git.io/vixsE>), but there's no right way to deal
                # with those anyway, so...
                timestamp = time.mktime(timestamp.timetuple())
        elif not isinstance(timestamp, numbers.Number):
            raise TypeError('Timestamp must be number or datetime.datetime')
        timebits = time.localtime(timestamp)
        try:
            tzname = timebits.tm_zone
        except AttributeError:
            # This assumes that `time.tzname` is meaningful/useful.
            tzname = time.tzname[timebits.tm_isdst > 0]
    assert 1 <= timebits.tm_mon <= 12, 'invalid month'
    assert 0 <= timebits.tm_wday <= 6, 'invalid day of week'
    return '{wday} {mon} {t.tm_mday:02d}' \
           ' {t.tm_hour:02d}:{t.tm_min:02d}:{t.tm_sec:02d}' \
           ' {tz} {t.tm_year:04d}'.format(
                t=timebits,
                tz=tzname,
                mon=MONTHS[timebits.tm_mon-1],
                wday=DAYS_OF_WEEK[timebits.tm_wday]
            )