From f8a2eeeb97ddefb3d5c192a43200ba680f749d17 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 21 Apr 2025 15:25:58 -0400 Subject: [PATCH] Simplify `datetime_to_timestamp` --- tubesync/common/timestamp.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tubesync/common/timestamp.py b/tubesync/common/timestamp.py index 833c488f..b36e32e2 100644 --- a/tubesync/common/timestamp.py +++ b/tubesync/common/timestamp.py @@ -18,17 +18,12 @@ def subtract_epoch(arg_dt, /): return utc_dt - epoch -def datetime_to_timestamp(arg_dt, /): +def datetime_to_timestamp(arg_dt, /, *, integer=True): timestamp = subtract_epoch(arg_dt).total_seconds() - try: - timestamp_int = int(timestamp) - except (TypeError, ValueError,): - pass - else: - return timestamp_int - - return timestamp + if not integer: + return timestamp + return int(timestamp) def timestamp_to_datetime(seconds, /): return add_epoch(seconds=seconds).astimezone(utc_tz)