u
This commit is contained in:
@@ -28,9 +28,19 @@ class Dashboard extends Component {
|
||||
const { range, offset } = this.state;
|
||||
|
||||
const nowMs = Date.now();
|
||||
const durationSec = (range === 'week' ? 7 * 24 * 3600 : (range === 'month' ? 30 * 24 * 3600 : 24 * 3600));
|
||||
const endMs = nowMs - (offset * durationSec * 1000);
|
||||
const startMs = endMs - (durationSec * 1000);
|
||||
let startMs, endMs;
|
||||
|
||||
if (range === 'today') {
|
||||
const d = new Date(nowMs);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
const midnightMs = d.getTime();
|
||||
startMs = midnightMs - (offset * 24 * 3600 * 1000);
|
||||
endMs = startMs + (24 * 3600 * 1000);
|
||||
} else {
|
||||
const durationSec = (range === 'week' ? 7 * 24 * 3600 : (range === 'month' ? 30 * 24 * 3600 : 24 * 3600));
|
||||
endMs = nowMs - (offset * durationSec * 1000);
|
||||
startMs = endMs - (durationSec * 1000);
|
||||
}
|
||||
|
||||
const dateOpts = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };
|
||||
const dateRangeLabel = `${new Date(startMs).toLocaleString([], dateOpts)} - ${new Date(endMs).toLocaleString([], dateOpts)}`;
|
||||
@@ -71,6 +81,12 @@ class Dashboard extends Component {
|
||||
>
|
||||
{t('dashboard.hours24')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => this.setRange('today')}
|
||||
color={range === 'today' ? 'primary' : 'inherit'}
|
||||
>
|
||||
1 Tag
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => this.setRange('week')}
|
||||
color={range === 'week' ? 'primary' : 'inherit'}
|
||||
|
||||
Reference in New Issue
Block a user