You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by fo...@apache.org on 2018/05/25 08:13:55 UTC

incubator-airflow git commit: [AIRFLOW-2510] Introduce new macros: prev_ds and next_ds

Repository: incubator-airflow
Updated Branches:
  refs/heads/master e4e7b55ad -> 66f00bbf7


[AIRFLOW-2510] Introduce new macros: prev_ds and next_ds

Closes #3418 from milton0825/introduce-next_ds-
prev_ds


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/66f00bbf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/66f00bbf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/66f00bbf

Branch: refs/heads/master
Commit: 66f00bbf7b296823fbe35c157d839da321aa6162
Parents: e4e7b55
Author: Chao-Han Tsai <ct...@lyft.com>
Authored: Fri May 25 10:13:49 2018 +0200
Committer: Fokko Driesprong <fo...@godatadriven.com>
Committed: Fri May 25 10:13:49 2018 +0200

----------------------------------------------------------------------
 airflow/models.py | 16 +++++++++++++---
 docs/code.rst     |  6 ++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/66f00bbf/airflow/models.py
----------------------------------------------------------------------
diff --git a/airflow/models.py b/airflow/models.py
index da18ec7..afd6e70 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -1751,14 +1751,22 @@ class TaskInstance(Base, LoggingMixin):
         if 'tables' in task.params:
             tables = task.params['tables']
 
-        ds = self.execution_date.isoformat()[:10]
+        ds = self.execution_date.strftime('%Y-%m-%d')
         ts = self.execution_date.isoformat()
-        yesterday_ds = (self.execution_date - timedelta(1)).isoformat()[:10]
-        tomorrow_ds = (self.execution_date + timedelta(1)).isoformat()[:10]
+        yesterday_ds = (self.execution_date - timedelta(1)).strftime('%Y-%m-%d')
+        tomorrow_ds = (self.execution_date + timedelta(1)).strftime('%Y-%m-%d')
 
         prev_execution_date = task.dag.previous_schedule(self.execution_date)
         next_execution_date = task.dag.following_schedule(self.execution_date)
 
+        next_ds = None
+        if next_execution_date:
+            next_ds = next_execution_date.strftime('%Y-%m-%d')
+
+        prev_ds = None
+        if prev_execution_date:
+            prev_ds = prev_execution_date.strftime('%Y-%m-%d')
+
         ds_nodash = ds.replace('-', '')
         ts_nodash = ts.replace('-', '').replace(':', '')
         yesterday_ds_nodash = yesterday_ds.replace('-', '')
@@ -1820,6 +1828,8 @@ class TaskInstance(Base, LoggingMixin):
         return {
             'dag': task.dag,
             'ds': ds,
+            'next_ds': next_ds,
+            'prev_ds': prev_ds,
             'ds_nodash': ds_nodash,
             'ts': ts,
             'ts_nodash': ts_nodash,

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/66f00bbf/docs/code.rst
----------------------------------------------------------------------
diff --git a/docs/code.rst b/docs/code.rst
index 1737d15..5343509 100644
--- a/docs/code.rst
+++ b/docs/code.rst
@@ -231,6 +231,12 @@ Variable                            Description
 =================================   ====================================
 ``{{ ds }}``                        the execution date as ``YYYY-MM-DD``
 ``{{ ds_nodash }}``                 the execution date as ``YYYYMMDD``
+``{{ prev_ds }}``                   the previous execution date as ``YYYY-MM-DD``.
+                                    if ``{{ ds }}`` is ``2016-01-08`` and ``schedule_interval`` is ``@weekly``,
+                                    ``{{ prev_ds }}`` will be ``2016-01-01``.
+``{{ next_ds }}``                   the next execution date as ``YYYY-MM-DD``.
+                                    if ``{{ ds }}`` is ``2016-01-01`` and ``schedule_interval`` is ``@weekly``,
+                                    ``{{ prev_ds }}`` will be ``2016-01-08``.
 ``{{ yesterday_ds }}``              yesterday's date as ``YYYY-MM-DD``
 ``{{ yesterday_ds_nodash }}``       yesterday's date as ``YYYYMMDD``
 ``{{ tomorrow_ds }}``               tomorrow's date as ``YYYY-MM-DD``