# 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,
)
            )
    else:
        return data


def prepare_local_timestamp_millis(
    data: Union[datetime.datetime, int], schema: Dict
) -> int:
    """Converts datetime.datetime object to int timestamp with milliseconds.

    The local-timestamp-millis logical type represents a timestamp in a local
    timezone, regardless of what specific time zone is considered local, with a
    precision of one millisecond.
    """
    if isinstance(data, datetime.datetime):
        delta = data.replace(tzinfo=datetime.timezone.utc) - epoch
        return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
            delta.microseconds / 1000
        )
    else:
        return data


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

# 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,
)

            )
    else:
        return data


def prepare_local_timestamp_millis(
    data: Union[datetime.datetime, int], schema: Dict
) -> int:
    """Converts datetime.datetime object to int timestamp with milliseconds.

    The local-timestamp-millis logical type represents a timestamp in a local
    timezone, regardless of what specific time zone is considered local, with a
    precision of one millisecond.
    """
    if isinstance(data, datetime.datetime):
        delta = data.replace(tzinfo=datetime.timezone.utc) - epoch
        return (delta.days * 24 * 3600 + delta.seconds) * MLS_PER_SECOND + int(
            delta.microseconds / 1000
        )
    else:
        return data


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