You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/04/20 19:43:53 UTC

[GitHub] [airflow] ashb commented on a change in pull request #15397: AIP-39: Use TimeTable interface to implement scheduling inside the DAG class

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:
users@infra.apache.org