Skip to content

Commit

Permalink
replaces moment.humanize with a more exact value
Browse files Browse the repository at this point in the history
  • Loading branch information
RingoRohe committed May 6, 2020
1 parent 8080115 commit be9e5ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/components/naps/charts/daily/ChartDaily.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../tooltip.scss';
import Duration from 'components/shared/duration/Duration';

const ChartDaily = props => {
var moment = require("moment");
const moment = require("moment");
moment().format();

let data = [];
Expand All @@ -19,11 +19,11 @@ const ChartDaily = props => {
const tooltip = (nap) => {
let startDate = moment(nap.start);
let endDate = moment(nap.end);
let duration = moment.duration(endDate.diff(startDate));
let duration = moment(moment.duration(endDate.diff(startDate)).asMilliseconds()).utc();
return `<div class="tootltip">
<h3>${nap.notes ? nap.notes : "no notes"}</h3>
<p class="duration">${startDate.format('HH:mm')} - ${endDate.format('HH:mm')}</p>
<p class="duration">${duration.humanize()}</p>
<p class="duration">${duration.format('HH:mm')}</p>
</div>`;
}

Expand Down Expand Up @@ -65,13 +65,13 @@ const ChartDaily = props => {
newEndDate.setTime(newEndDate.getTime() - offset);
}

let duration = moment.duration(
moment(newEndDate).diff(newStartDate)
);
let duration = moment(
moment.duration(moment(newEndDate).diff(newStartDate)).asMilliseconds()
).utc();

return [
"naps",
duration.humanize(),
duration.format('HH:mm'),
tooltip(nap),
newStartDate,
newEndDate,
Expand Down
7 changes: 5 additions & 2 deletions src/components/naps/charts/sleeptime/ChartSleeptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import styles from './chartSleeptime.scss';
import { useEffect } from 'react';

const ChartSleeptime = props => {
const moment = require("moment");
moment().format();

let data = [];
let timeout = null;
const { maxDays = 5 } = props;
Expand Down Expand Up @@ -105,7 +108,7 @@ const ChartSleeptime = props => {
data.push([
date,
decimalTime,
decimalTime
moment(dates[date]).utc().format('HH:mm')
]);
}
}
Expand All @@ -124,7 +127,7 @@ const ChartSleeptime = props => {

dataTable.addColumn("string", "Date");
dataTable.addColumn("number", "Hours of Sleep");
dataTable.addColumn({ type: "number", role: "annotation" });
dataTable.addColumn({ type: "string", role: "annotation" });
dataTable.addRows(data);

const min = Math.floor(data.reduce((a, b) => a[1] < b[1] ? a : b)[1]) - 2;
Expand Down

0 comments on commit be9e5ec

Please sign in to comment.