# Path: fastavro/const.py
# MCS_PER_HOUR = MCS_PER_MINUTE * 60
# 
# MCS_PER_MINUTE = MCS_PER_SECOND * 60
# 
# MCS_PER_SECOND = 1000000
# 
# MLS_PER_HOUR = MLS_PER_MINUTE * 60
# 
# MLS_PER_MINUTE = MLS_PER_SECOND * 60
# 
# MLS_PER_SECOND = 1000
# 
# DAYS_SHIFT = datetime.date(1970, 1, 1).toordinal()


import datetime
import decimal
import os
import time
import uuid
from io import BytesIO
from typing import Dict, Union
from .const import (
    MCS_PER_HOUR,
    MCS_PER_MINUTE,
    MCS_PER_SECOND,
    MLS_PER_HOUR,
    MLS_PER_MINUTE,
    MLS_PER_SECOND,
    DAYS_SHIFT,
)
# cython: auto_cpdef=True



is_windows = os.name == "nt"
epoch = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
epoch_naive = datetime.datetime(1970, 1, 1)


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:

# Path: fastavro/const.py
# MCS_PER_HOUR = MCS_PER_MINUTE * 60
# 
# MCS_PER_MINUTE = MCS_PER_SECOND * 60
# 
# MCS_PER_SECOND = 1000000
# 
# MLS_PER_HOUR = MLS_PER_MINUTE * 60
# 
# MLS_PER_MINUTE = MLS_PER_SECOND * 60
# 
# MLS_PER_SECOND = 1000
# 
# DAYS_SHIFT = datetime.date(1970, 1, 1).toordinal()


# Path: fastavro/_logical_writers_py.py
import datetime
import decimal
import os
import time
import uuid
from io import BytesIO
from typing import Dict, Union
from .const import (
    MCS_PER_HOUR,
    MCS_PER_MINUTE,
    MCS_PER_SECOND,
    MLS_PER_HOUR,
    MLS_PER_MINUTE,
    MLS_PER_SECOND,
    DAYS_SHIFT,
)

# cython: auto_cpdef=True



is_windows = os.name == "nt"
epoch = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
epoch_naive = datetime.datetime(1970, 1, 1)


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(