mirror of
https://github.com/plausible/analytics.git
synced 2024-12-30 04:52:13 +03:00
e8f20e67cc
* Load dashboard with react * Rename stast2 to dashboard * Save timeframe on the frontend * Implement current visitors * Implement comparisons * React to route changes * Add modals * Show number of visitors on hover * Show 'Today' for today * Add 30 days * Show referrer drilldown * Arrow keys to go back and forward * Improve comparisons UI * Fix dropdown when clicking on it * Verify API access in a memoized fashion * Test API access * Test stats through controller * Move map formatting from stats controller to stats * Remove unused code * Remove dead code from query * Remove dead code from stats templates * Add stats view test back in * Render modal inside the modal component * Implement google search terms * Add explanation for screen sizes * Separate dashboard JS from the app js
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
// https://stackoverflow.com/a/50130338
|
|
export function formatISO(date) {
|
|
return new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
|
|
.toISOString()
|
|
.split("T")[0];
|
|
}
|
|
|
|
export function shiftMonths(date, months) {
|
|
const newDate = new Date(date.getTime())
|
|
newDate.setMonth(newDate.getMonth() + months)
|
|
return newDate
|
|
}
|
|
|
|
export function shiftDays(date, days) {
|
|
const newDate = new Date(date.getTime())
|
|
newDate.setDate(newDate.getDate() + days)
|
|
return newDate
|
|
}
|
|
|
|
const MONTHS = [
|
|
"January", "February", "March",
|
|
"April", "May", "June", "July",
|
|
"August", "September", "October",
|
|
"November", "December"
|
|
]
|
|
|
|
export function formatMonthYYYY(date) {
|
|
return `${MONTHS[date.getMonth()]} ${date.getFullYear()}`;
|
|
}
|
|
|
|
export function formatMonth(date) {
|
|
return `${MONTHS[date.getMonth()]}`;
|
|
}
|
|
|
|
export function formatDay(date) {
|
|
return `${date.getDate()} ${formatMonth(date)}`;
|
|
}
|
|
|
|
// https://stackoverflow.com/a/11124448
|
|
export function newDateInOffset(offset) {
|
|
return new Date(new Date().getTime() + offset * 1000)
|
|
}
|
|
|
|
export function isToday(site, date) {
|
|
return formatISO(date) === formatISO(newDateInOffset(site.offset))
|
|
}
|