"""Tests para parse_iso_datetime."""

import sys
import os

sys.path.insert(0, os.path.dirname(__file__))

from datetime import datetime, timezone, timedelta
from parse_iso_datetime import parse_iso_datetime


def test_iso_normal_sin_fraccion():
    result = parse_iso_datetime("2026-02-21T13:20:23+08:00")
    assert result.year == 2026
    assert result.month == 2
    assert result.day == 21
    assert result.hour == 13
    assert result.minute == 20
    assert result.second == 23
    assert result.tzinfo is not None


def test_iso_con_z_como_utc():
    result = parse_iso_datetime("2026-02-21T13:20:23Z")
    assert result.tzinfo is not None
    assert result.utcoffset() == timedelta(0)


def test_iso_con_fraccion_de_mas_de_6_digitos():
    # Windows produce fracciones con 7 digitos: .1470042
    result = parse_iso_datetime("2026-02-21T13:20:23.1470042+08:00")
    assert result.year == 2026
    assert result.microsecond == 147004  # truncado a 6 digitos: 147004
    assert result.tzinfo is not None


def test_iso_con_timezone_offset():
    result = parse_iso_datetime("2026-06-15T09:00:00.000000-05:00")
    assert result.hour == 9
    expected_offset = timedelta(hours=-5)
    assert result.utcoffset() == expected_offset
