Pretty print dates (closes #2)

This commit is contained in:
Drew DeVault 2017-09-08 16:47:09 +09:00
parent 3d8e4f5903
commit 1aec362689
4 changed files with 13 additions and 4 deletions

View File

@ -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",

5
src/date.js Normal file
View File

@ -0,0 +1,5 @@
import moment from 'moment';
export default function date(when) {
return `${when.format("YYYY-MM-DD LTS")} (${when.from(moment())})`;
}

View File

@ -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
};

View File

@ -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 }) {
</h3>
<dl>
<dt>Running since</dt>
{/* TODO: pretty print dates */}
<dd>{server.started}</dd>
<dd>{date(moment(server.started))}</dd>
<dt>Rate up</dt>
<dd>{formatBitrate(server.rate_up)}</dd>
<dt>Rate down</dt>