from datetime import datetime
import pytz


def day_of_week(check_datetime, local_timezone):
    """
    @param check_datetime: integer, use an ArcGIS date field or a 13-digit Unix timestamp (millisecond precision).
    @param local_timezone: string, Use a standard timezone name (eg., US/Eastern). This should be the agency's local
    timezone.
    :return Day of the week as a string.
    """

    if check_datetime:
        # Days of the week
        weekdays = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')

        check_datetime = datetime.fromtimestamp(int(check_datetime / 1000), tz=pytz.utc)
        check_datetime = check_datetime.astimezone(pytz.timezone(local_timezone))
        check_datetime = check_datetime.weekday()

        # Convert weekday to string
        weekday = weekdays[check_datetime]
    else:
        weekday = None

    return weekday