def _parse_timestamp(timestamp):
    """Parse and return a utc timestamp

    - raise HTTPError(400) on parse error
    - handle and strip tz info for internal consistency
      (we use naive utc timestamps everywhere)
    """
    try:
        dt = parse_date(timestamp)
    except Exception:
        raise web.HTTPError(400, "Not a valid timestamp: %r", timestamp)
    if dt.tzinfo:
        # strip timezone info to naive UTC datetime
        dt = dt.astimezone(timezone.utc).replace(tzinfo=None)

    now = utcnow(with_tz=False)
    if (dt - now) > timedelta(minutes=59):
        raise web.HTTPError(
            400,
            f"Rejecting activity from more than an hour in the future: {isoformat(dt)}",
        )
    return dt
Parse and return a utc timestamp

- raise HTTPError(400) on parse error
- handle and strip tz info for internal consistency
(we use naive utc timestamps everywhere)
jupyterhub/apihandlers/users.py