From 1aec36268955869ea1921f9f531eae473c2b25d6 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 8 Sep 2017 16:47:09 +0900 Subject: [PATCH] Pretty print dates (closes #2) --- package.json | 1 + src/date.js | 5 +++++ src/ui/add_torrent.js | 6 ++++-- src/ui/server.js | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/date.js diff --git a/package.json b/package.json index cd0933a..edf622a 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "font-awesome-sass-loader": "^2.0.1", "history": "^4.7.2", "isomorphic-fetch": "^2.2.1", + "moment": "^2.18.1", "node-sass": "^4.5.3", "preact": "^8.2.4", "preact-compat": "^3.17.0", diff --git a/src/date.js b/src/date.js new file mode 100644 index 0000000..2ef698e --- /dev/null +++ b/src/date.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +export default function date(when) { + return `${when.format("YYYY-MM-DD LTS")} (${when.from(moment())})`; +} diff --git a/src/ui/add_torrent.js b/src/ui/add_torrent.js index 1845ce9..a2077c5 100644 --- a/src/ui/add_torrent.js +++ b/src/ui/add_torrent.js @@ -12,11 +12,13 @@ import { Label, Input } from 'reactstrap'; -import ToggleContainer from './toggle_container'; import fetch from 'isomorphic-fetch'; import bencode from 'bencode'; +import moment from 'moment'; +import ToggleContainer from './toggle_container'; import ws_send from '../socket'; import { convertToBitrate } from '../bitrate'; +import date from '../date'; class Throttle extends Component { constructor() { @@ -325,7 +327,7 @@ class AddTorrent extends Component { const details = { "comment": d => d, - "creation date": d => new Date(d * 1000).toDateString(), + "creation date": d => date(moment(new Date(d * 1000))), "created by": d => d }; diff --git a/src/ui/server.js b/src/ui/server.js index 7712d19..3c8941e 100644 --- a/src/ui/server.js +++ b/src/ui/server.js @@ -1,7 +1,9 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; +import moment from 'moment'; import { formatBitrate } from '../bitrate'; import { ws_disconnect } from '../socket'; +import date from '../date'; const throttle = _ => _ === null ? "Unlimited" : formatBitrate(_); @@ -23,8 +25,7 @@ function Server({ server }) {
Running since
- {/* TODO: pretty print dates */} -
{server.started}
+
{date(moment(server.started))}
Rate up
{formatBitrate(server.rate_up)}
Rate down