import math


def time_to_frame(t, shift):
    """Convert time (in seconds) to frame index (zero-indexed).

    The frame index means that this timestamp belongs to this frame.

    Args:
        t: Time in seconds. This marks the start time of the frame.
        shift: Window shift in ms.

    Returns:
        frame_idx: Frame index (non-negative int).
    """
    if t < 0:
        raise ValueError("Time should be positive!")
    frame_idx = math.floor(
        float(t) * 1000 / float(shift))  # The frame this timestamp belongs to.
    frame_idx = int(frame_idx)
    assert frame_idx >= 0, "Frame index should be non-negative."
    return frame_idx