Repository: apache/airflow

Issue:
UI time zone not used in Gantt charts tooltips
**Apache Airflow version**: v2.0.0.dev0

**Kubernetes version (if you are using kubernetes)** (use `kubectl version`): -

**Environment**: Docker 

- **Cloud provider or hardware configuration**: -
- **OS** (e.g. from /etc/os-release): Debian GNU/Linux 10 (buster)
- **Kernel** (e.g. `uname -a`): 
Linux 6dac905dd519 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux
- **Install tools**: Airflow Breeze (image: apache/airflow:master-python3.6-ci)
- **Others**: -
**What happened**:

Gantt charts seem to always use UTC for displaying task start/end dates, but use local time for time axis, regardless of the time zone set in UI (see screens below: my local time zone is CEST).
<img width="815" alt="Zrzut ekranu 2020-04-8 o 09 18 50" src="https://user-images.githubusercontent.com/34898234/78764706-3c73f680-7987-11ea-925b-e394ac329298.png">
<img width="840" alt="Zrzut ekranu 2020-04-8 o 09 17 17" src="https://user-images.githubusercontent.com/34898234/78764752-4eee3000-7987-11ea-957b-338376d1bf41.png">
<img width="925" alt="Zrzut ekranu 2020-04-8 o 10 58 09" src="https://user-images.githubusercontent.com/34898234/78765233-01be8e00-7988-11ea-8215-9179102cb390.png">

**What you expected to happen**:

Time zone of the time axis and task start/end dates should be the same - probably the time zone specified in the UI should be used.

**How to reproduce it**:

Simply go to Gantt chart of any Dag Run and try changing the time zone in the UI to see that neither the time axis nor task start/end dates reflect the change.

You can also change the local time on your workstation and refresh the page with Gantt chart to see that time axis changed to reflect the new time zone.

**Anything else we need to know**: -


Discussion:
Thanks for opening your first issue here! Be sure to follow the issue template!

@ashb Can you look at it
Yup, valid bug, missed the tooltips on that in my timezone revamp. I will try and make them use the same tooltip code as graph and tree view (which now share the same JS)

Resolving patch:
diff --git a/airflow/www/views.py b/airflow/www/views.py
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1931,6 +1931,8 @@ def gantt(self, session=None):
 
         # determine bars to show in the gantt chart
         gantt_bar_items = []
+
+        tasks = []
         for ti in tis:
             end_date = ti.end_date or timezone.utcnow()
             # prev_attempted_tries will reflect the currently running try_number
@@ -1938,6 +1940,7 @@ def gantt(self, session=None):
             # https://issues.apache.org/jira/browse/AIRFLOW-2143
             try_count = ti.prev_attempted_tries
             gantt_bar_items.append((ti.task_id, ti.start_date, end_date, ti.state, try_count))
+            tasks.append(alchemy_to_dict(ti))
 
         tf_count = 0
         try_count = 1
@@ -1952,6 +1955,11 @@ def gantt(self, session=None):
             prev_task_id = tf.task_id
             gantt_bar_items.append((tf.task_id, start_date, end_date, State.FAILED, try_count))
             tf_count = tf_count + 1
+            d = alchemy_to_dict(tf)
+            d['state'] = State.FAILED
+            d['operator'] = dag.get_task(tf.task_id).task_type
+            d['try_number'] = try_count
+            tasks.append(d)
 
         task_types = {}
         extra_links = {}
@@ -1959,33 +1967,9 @@ def gantt(self, session=None):
             task_types[t.task_id] = t.task_type
             extra_links[t.task_id] = t.extra_links
 
-        tasks = []
-        for gantt_bar_item in gantt_bar_items:
-            task_id = gantt_bar_item[0]
-            start_date = gantt_bar_item[1]
-            end_date = gantt_bar_item[2]
-            state = gantt_bar_item[3]
-            try_count = gantt_bar_item[4]
-            tasks.append({
-                'startDate': wwwutils.epoch(start_date),
-                'endDate': wwwutils.epoch(end_date),
-                'isoStart': start_date.isoformat()[:-4],
-                'isoEnd': end_date.isoformat()[:-4],
-                'taskName': task_id,
-                'taskType': task_types[ti.task_id],
-                'duration': (end_date - start_date).total_seconds(),
-                'status': state,
-                'executionDate': dttm.isoformat(),
-                'try_number': try_count,
-                'extraLinks': extra_links[ti.task_id],
-            })
-
-        states = {task['status']: task['status'] for task in tasks}
-
         data = {
             'taskNames': [ti.task_id for ti in tis],
             'tasks': tasks,
-            'taskStatus': states,
             'height': len(tis) * 25 + 25,
         }
 


Test patch: