From 59b42ffd981017a9b606549907f6266c97fe8255 Mon Sep 17 00:00:00 2001 From: Alec Clowes Date: Sun, 3 Jun 2018 07:53:17 -0700 Subject: [PATCH] format datetimes (#38) * format datetimes fix next_run update after toggle schedule active * use moment-timezone to lock the timezone in tests --- frontend/package.json | 2 ++ frontend/src/ExecutionTable.js | 4 +++- frontend/src/TaskDetail.js | 5 +++-- frontend/src/WorkerDetail.js | 5 +++-- frontend/src/WorkerList.js | 5 +++-- frontend/src/WorkflowDetailForm.js | 4 +++- .../src/tests/__snapshots__/ExecutionList.test.js.snap | 2 +- .../src/tests/__snapshots__/TaskDetail.test.js.snap | 6 ++++-- .../src/tests/__snapshots__/WorkerDetail.test.js.snap | 6 +++--- .../src/tests/__snapshots__/WorkerList.test.js.snap | 4 ++-- .../tests/__snapshots__/WorkflowDetail.test.js.snap | 4 +++- frontend/src/tests/mocks.js | 8 ++++++++ frontend/src/utilities.js | 8 ++++++++ frontend/yarn.lock | 10 ++++++++++ setup.py | 2 +- 15 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 frontend/src/utilities.js diff --git a/frontend/package.json b/frontend/package.json index 50d7793..1d9ee95 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,8 @@ "dependencies": { "bootswatch": "^3.3.7", "dagre-d3": "^0.4.17", + "moment": "^2.22.2", + "moment-timezone": "^0.5.17", "react": "^15.6.1", "react-bootstrap": "^0.30.10", "react-dom": "^15.6.1", diff --git a/frontend/src/ExecutionTable.js b/frontend/src/ExecutionTable.js index e7f38ae..feeff47 100644 --- a/frontend/src/ExecutionTable.js +++ b/frontend/src/ExecutionTable.js @@ -2,6 +2,8 @@ import React from 'react'; import {Table} from 'react-bootstrap'; import {Link} from 'react-router'; +import {formatDateTime} from "./utilities"; + export default class ExecutionTable extends React.Component { @@ -19,7 +21,7 @@ export default class ExecutionTable extends React.Component { {execution.task.workflow && execution.task.workflow.name} {execution.task.name} {execution.status} - {execution.start_timestamp} + {formatDateTime(execution.start_timestamp)} {execution.minutes_running} )) diff --git a/frontend/src/TaskDetail.js b/frontend/src/TaskDetail.js index 2e7cd56..7577dfc 100644 --- a/frontend/src/TaskDetail.js +++ b/frontend/src/TaskDetail.js @@ -3,6 +3,7 @@ import {PanelGroup, Panel, Alert, Pagination, Button} from 'react-bootstrap'; import {Link} from 'react-router'; import API from "./API"; +import {formatDateTime} from "./utilities"; export default class TaskDetail extends React.Component { constructor(props) { @@ -92,9 +93,9 @@ export default class TaskDetail extends React.Component {
Start Time
-
{execution.start_timestamp}
+
{formatDateTime(execution.start_timestamp)}
Stop Time
-
{execution.stop_timestamp}
+
{formatDateTime(execution.stop_timestamp)}
Exit Code
{execution.exit_code}
Standard Output
diff --git a/frontend/src/WorkerDetail.js b/frontend/src/WorkerDetail.js index 2acb398..ce9788e 100644 --- a/frontend/src/WorkerDetail.js +++ b/frontend/src/WorkerDetail.js @@ -3,6 +3,7 @@ import {Panel, PanelGroup, Alert} from 'react-bootstrap'; import API from "./API"; import ExecutionTable from "./ExecutionTable"; +import {formatDateTime} from "./utilities"; export default class WorkerDetail extends React.Component { constructor(props) { @@ -36,9 +37,9 @@ export default class WorkerDetail extends React.Component {
Status
{worker.status}
Start Timestamp
-
{worker.start_timestamp}
+
{formatDateTime(worker.start_timestamp)}
Last Heartbeat
-
{worker.last_heartbeat}
+
{formatDateTime(worker.last_heartbeat)}
diff --git a/frontend/src/WorkerList.js b/frontend/src/WorkerList.js index 8823756..8d8c648 100644 --- a/frontend/src/WorkerList.js +++ b/frontend/src/WorkerList.js @@ -3,6 +3,7 @@ import {Table, Alert} from 'react-bootstrap'; import {Link} from 'react-router'; import API from "./API"; +import {formatDateTime} from "./utilities"; export default class WorkerList extends React.Component { constructor(props) { @@ -30,8 +31,8 @@ export default class WorkerList extends React.Component { {worker.name} {worker.status} - {worker.start_timestamp} - {worker.last_heartbeat} + {formatDateTime(worker.start_timestamp)} + {formatDateTime(worker.last_heartbeat)} ) }) diff --git a/frontend/src/WorkflowDetailForm.js b/frontend/src/WorkflowDetailForm.js index 7abb00b..b00a3ef 100644 --- a/frontend/src/WorkflowDetailForm.js +++ b/frontend/src/WorkflowDetailForm.js @@ -5,6 +5,7 @@ import { } from 'react-bootstrap'; import API from './API' +import {formatDateTime} from "./utilities"; /* Helper to extract form values from a given object */ function formValues(object) { @@ -26,6 +27,7 @@ function formValues(object) { schedule: object.schedule, schedule_active: object.schedule_active, parameters: parameters, + next_run: object.next_run, } } @@ -122,7 +124,7 @@ export default class WorkflowDetailForm extends React.Component {
Schedule
{this.state.schedule}
Next Run
-
{this.props.workflow.next_run}
+
{formatDateTime(this.state.next_run)}
Parameters
{this.state.parameters}
diff --git a/frontend/src/tests/__snapshots__/ExecutionList.test.js.snap b/frontend/src/tests/__snapshots__/ExecutionList.test.js.snap index b055f7f..1b72c19 100644 --- a/frontend/src/tests/__snapshots__/ExecutionList.test.js.snap +++ b/frontend/src/tests/__snapshots__/ExecutionList.test.js.snap @@ -147,7 +147,7 @@ exports[`ExecutionList success 1`] = ` succeeded - 2017-01-30T04:17:47.008524Z + January 30th 2017, 4:17:47 am 0m 0.05s diff --git a/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap b/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap index 6bda5c2..1f893db 100644 --- a/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap +++ b/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap @@ -156,12 +156,14 @@ exports[`TaskDetail success 1`] = ` Start Time
- 2017-01-30T03:26:38.211839Z + January 30th 2017, 3:26:38 am
Stop Time
-
+
+ +
Exit Code
diff --git a/frontend/src/tests/__snapshots__/WorkerDetail.test.js.snap b/frontend/src/tests/__snapshots__/WorkerDetail.test.js.snap index 835a3bf..ad1da6e 100644 --- a/frontend/src/tests/__snapshots__/WorkerDetail.test.js.snap +++ b/frontend/src/tests/__snapshots__/WorkerDetail.test.js.snap @@ -53,13 +53,13 @@ exports[`WorkerDetail success 1`] = ` Start Timestamp
- 2017-01-30T04:13:47.966080Z + January 30th 2017, 4:13:47 am
Last Heartbeat
- 2017-01-30T04:15:10.845289Z + January 30th 2017, 4:15:10 am
@@ -126,7 +126,7 @@ exports[`WorkerDetail success 1`] = ` succeeded - 2017-01-30T04:17:03.806599Z + January 30th 2017, 4:17:03 am diff --git a/frontend/src/tests/__snapshots__/WorkerList.test.js.snap b/frontend/src/tests/__snapshots__/WorkerList.test.js.snap index 01c1e6d..05926fe 100644 --- a/frontend/src/tests/__snapshots__/WorkerList.test.js.snap +++ b/frontend/src/tests/__snapshots__/WorkerList.test.js.snap @@ -118,10 +118,10 @@ exports[`WorkerList success 1`] = ` exited - 2017-01-30T04:13:47.966080Z + January 30th 2017, 4:13:47 am - 2017-01-30T04:15:10.845289Z + January 30th 2017, 4:15:10 am diff --git a/frontend/src/tests/__snapshots__/WorkflowDetail.test.js.snap b/frontend/src/tests/__snapshots__/WorkflowDetail.test.js.snap index ef2f96b..04cb3aa 100644 --- a/frontend/src/tests/__snapshots__/WorkflowDetail.test.js.snap +++ b/frontend/src/tests/__snapshots__/WorkflowDetail.test.js.snap @@ -78,7 +78,9 @@ exports[`WorkflowDetail success 1`] = `
Next Run
-
+
+ +
Parameters
diff --git a/frontend/src/tests/mocks.js b/frontend/src/tests/mocks.js index 2515242..11f1206 100644 --- a/frontend/src/tests/mocks.js +++ b/frontend/src/tests/mocks.js @@ -1,5 +1,13 @@ +import moment from "moment-timezone"; + import API from '../API'; +/* +* Set the timezone to UTC when running tests, for consistent +* snapshots. +* */ +moment.tz.setDefault('UTC'); + /* Mock API with canned responses; it will call the callback immediately instead of waiting for a Promise. This means diff --git a/frontend/src/utilities.js b/frontend/src/utilities.js new file mode 100644 index 0000000..2940445 --- /dev/null +++ b/frontend/src/utilities.js @@ -0,0 +1,8 @@ +import moment from "moment"; + +export function formatDateTime(datetime) { + if (!datetime) { + return ''; + } + return moment(datetime).format('MMMM Do YYYY, h:mm:ss a'); +} diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 4ee64eb..4c68eed 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -4058,6 +4058,16 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdi dependencies: minimist "0.0.8" +moment-timezone@^0.5.17: + version "0.5.17" + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.17.tgz#3c8fef32051d84c3af174d91dc52977dcb0ad7e5" + dependencies: + moment ">= 2.9.0" + +"moment@>= 2.9.0", moment@^2.22.2: + version "2.22.2" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66" + ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" diff --git a/setup.py b/setup.py index 79b9e73..e37b8db 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.2.2', + version='0.2.3', description='Yet Another Workflow Engine, a subprocess-based DAG execution system', long_description=long_description,