ashb commented on a change in pull request #15397:
URL: https://github.com/apache/airflow/pull/15397#discussion_r616983846



##########
File path: airflow/models/dag.py
##########
@@ -109,6 +112,21 @@ def get_last_dagrun(dag_id, session, 
include_externally_triggered=False):
     return query.first()
 
 
+def coerce_datetime(v: Union[None, datetime, pendulum.DateTime]) -> 
Optional[pendulum.DateTime]:
+    """Convert whatever is passed in to ``pendulum.DateTime``.
+
+    This is for interfacing with the new ``timetables`` package, which
+    exclusively uses ``pendulum.DateTime`` internally.
+    """
+    if v is None:
+        return None
+    if isinstance(v, pendulum.DateTime):
+        return v
+    if v.tzinfo is None:
+        v = timezone.make_aware(v)
+    return pendulum.instance(v)

Review comment:
       This should probably live in airflow.utils.timezone
   
   (As much as I hate `utils` as a module namespace, keeping things together 
seems better)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to