# Path: fastavro/const.py
# MCS_PER_SECOND = 1000000
# 
# MLS_PER_SECOND = 1000
# 
# Path: fastavro/_logical_writers_py.py
# def prepare_timestamp_micros(data, schema):
#     """Converts datetime.datetime to int timestamp with microseconds"""
#     if isinstance(data, datetime.datetime):
#         if data.tzinfo is not None:
#             delta = data - epoch
#             return (
#                 delta.days * 24 * 3600 + delta.seconds
#             ) * MCS_PER_SECOND + delta.microseconds
# 
#         # On Windows, mktime does not support pre-epoch, see e.g.
#         # https://stackoverflow.com/questions/2518706/python-mktime-overflow-error
#         if is_windows:
#             delta = data - epoch_naive
#             return (
#                 delta.days * 24 * 3600 + delta.seconds
#             ) * MCS_PER_SECOND + delta.microseconds
#         else:
#             return (
#                 int(time.mktime(data.timetuple())) * MCS_PER_SECOND + data.microsecond
#             )
#     else:
#         return data
# 
# Path: fastavro/_logical_writers_py.py
# def prepare_timestamp_millis(data, schema):
#     """Converts datetime.datetime object to int timestamp with milliseconds"""
#     if isinstance(data, datetime.datetime):
#         if data.tzinfo is not None:
#             delta = data - epoch
#             return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
#                 delta.microseconds / 1000
#             )
# 
#         # On Windows, mktime does not support pre-epoch, see e.g.
#         # https://stackoverflow.com/questions/2518706/python-mktime-overflow-error
#         if is_windows:
#             delta = data - epoch_naive
#             return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
#                 delta.microseconds / 1000
#             )
#         else:
#             return int(time.mktime(data.timetuple())) * MLS_PER_SECOND + int(
#                 data.microsecond / 1000
#             )
#     else:
#         return data
# 
# Path: tests/conftest.py
# def assert_naive_datetime_equal_to_tz_datetime(naive_datetime, tz_datetime):
#     # mktime appears to ignore microseconds, so do this manually
#     microseconds = int(time.mktime(naive_datetime.timetuple())) * 1000 * 1000
#     microseconds += naive_datetime.microsecond
#     aware_datetime = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(
#         microseconds=microseconds
#     )
#     assert aware_datetime == tz_datetime


import datetime
import fastavro
import pytest
from io import BytesIO
from fastavro.const import MCS_PER_SECOND, MLS_PER_SECOND
from fastavro._logical_writers_py import prepare_timestamp_micros
from fastavro._logical_writers_py import prepare_timestamp_millis
from .conftest import assert_naive_datetime_equal_to_tz_datetime
from datetime import timezone
    [
        datetime.datetime(1974, 4, 4, 0, 0, 0, 1000),
        datetime.datetime(2515, 1, 1, 0, 0, 0, 37000),
        datetime.datetime(2243, 1, 1, 0, 0, 0, 64000),
    ],
)
def test_problematic_timestamp_millis_naive_time(my_date):
    schema = {
        "fields": [
            {
                "name": "timestamp-millis",
                "type": {"type": "long", "logicalType": "timestamp-millis"},
            },
            {
                "name": "timestamp-micros",
                "type": {"type": "long", "logicalType": "timestamp-micros"},
            },
        ],
        "name": "test_problematic_timestamp_millis",
        "type": "record",
    }

    binary = serialize(
        schema, {"timestamp-millis": my_date, "timestamp-micros": my_date}
    )
    roundtrip_data = deserialize(schema, binary)

    assert_naive_datetime_equal_to_tz_datetime(
        my_date, roundtrip_data["timestamp-millis"]
    )

# Path: fastavro/const.py
# MCS_PER_SECOND = 1000000
# 
# MLS_PER_SECOND = 1000
# 
# Path: fastavro/_logical_writers_py.py
# def prepare_timestamp_micros(data, schema):
#     """Converts datetime.datetime to int timestamp with microseconds"""
#     if isinstance(data, datetime.datetime):
#         if data.tzinfo is not None:
#             delta = data - epoch
#             return (
#                 delta.days * 24 * 3600 + delta.seconds
#             ) * MCS_PER_SECOND + delta.microseconds
# 
#         # On Windows, mktime does not support pre-epoch, see e.g.
#         # https://stackoverflow.com/questions/2518706/python-mktime-overflow-error
#         if is_windows:
#             delta = data - epoch_naive
#             return (
#                 delta.days * 24 * 3600 + delta.seconds
#             ) * MCS_PER_SECOND + delta.microseconds
#         else:
#             return (
#                 int(time.mktime(data.timetuple())) * MCS_PER_SECOND + data.microsecond
#             )
#     else:
#         return data
# 
# Path: fastavro/_logical_writers_py.py
# def prepare_timestamp_millis(data, schema):
#     """Converts datetime.datetime object to int timestamp with milliseconds"""
#     if isinstance(data, datetime.datetime):
#         if data.tzinfo is not None:
#             delta = data - epoch
#             return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
#                 delta.microseconds / 1000
#             )
# 
#         # On Windows, mktime does not support pre-epoch, see e.g.
#         # https://stackoverflow.com/questions/2518706/python-mktime-overflow-error
#         if is_windows:
#             delta = data - epoch_naive
#             return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
#                 delta.microseconds / 1000
#             )
#         else:
#             return int(time.mktime(data.timetuple())) * MLS_PER_SECOND + int(
#                 data.microsecond / 1000
#             )
#     else:
#         return data
# 
# Path: tests/conftest.py
# def assert_naive_datetime_equal_to_tz_datetime(naive_datetime, tz_datetime):
#     # mktime appears to ignore microseconds, so do this manually
#     microseconds = int(time.mktime(naive_datetime.timetuple())) * 1000 * 1000
#     microseconds += naive_datetime.microsecond
#     aware_datetime = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(
#         microseconds=microseconds
#     )
#     assert aware_datetime == tz_datetime


# Path: tests/test_timezone.py
import datetime
import fastavro
import pytest
from io import BytesIO
from fastavro.const import MCS_PER_SECOND, MLS_PER_SECOND
from fastavro._logical_writers_py import prepare_timestamp_micros
from fastavro._logical_writers_py import prepare_timestamp_millis
from .conftest import assert_naive_datetime_equal_to_tz_datetime
from datetime import timezone

    [
        datetime.datetime(1974, 4, 4, 0, 0, 0, 1000),
        datetime.datetime(2515, 1, 1, 0, 0, 0, 37000),
        datetime.datetime(2243, 1, 1, 0, 0, 0, 64000),
    ],
)
def test_problematic_timestamp_millis_naive_time(my_date):
    schema = {
        "fields": [
            {
                "name": "timestamp-millis",
                "type": {"type": "long", "logicalType": "timestamp-millis"},
            },
            {
                "name": "timestamp-micros",
                "type": {"type": "long", "logicalType": "timestamp-micros"},
            },
        ],
        "name": "test_problematic_timestamp_millis",
        "type": "record",
    }

    binary = serialize(
        schema, {"timestamp-millis": my_date, "timestamp-micros": my_date}
    )
    roundtrip_data = deserialize(schema, binary)

    assert_naive_datetime_equal_to_tz_datetime(
        my_date, roundtrip_data["timestamp-millis"]
    )

    assert_naive_datetime_equal_to_tz_datetime(