from typing import Union
from datetime import datetime


def parse_nanotimestamp(s: str) -> Union[int, float]:
    """Parse datetime string with nanoseconds

    Args:
        s (str): datetime string

    Returns:
        datetime: datetime object
    """
    tz = ""
    if s[-1] == "Z":
        # Add explicit UTC timezone
        tz = "Z+0000"
    # Get milliseconds and convert it to unix timestamp
    return datetime.strptime(s[0:23] + tz, "%Y-%m-%dT%H:%M:%S.%fZ%z").timestamp()