Skip to content

datetime_utils

Date/time utilities for the application.

datetime_to_applescript_timestamp

datetime_to_applescript_timestamp(dt)

Convert datetime to Unix timestamp expected by AppleScript filters.

Parameters:

Name Type Description Default
dt datetime

datetime object (can be naive or aware)

required

Returns:

Type Description
int

Unix timestamp as integer, floored to the minute

Source code in src/core/utils/datetime_utils.py
def datetime_to_applescript_timestamp(dt: datetime) -> int:
    """Convert datetime to Unix timestamp expected by AppleScript filters.

    Args:
        dt: datetime object (can be naive or aware)

    Returns:
        Unix timestamp as integer, floored to the minute

    """
    # Naive datetimes are assumed to be UTC (all internal datetimes use UTC)
    aware_dt = dt if dt.tzinfo is not None else dt.replace(tzinfo=UTC)
    utc_dt = aware_dt.astimezone(UTC)
    floored = utc_dt.replace(second=0, microsecond=0)
    return int(floored.timestamp())