-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f54edb8
commit ad43f72
Showing
12 changed files
with
103 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
import { getStatsDateString } from '@utils' | ||
|
||
export function getDateInterval({ endDate, startDate }) { | ||
const today = new Date() | ||
const todayUTC = getStatsDateString(today) | ||
const end_date = endDate ? endDate : todayUTC | ||
const defaultStartDate = new Date() | ||
defaultStartDate.setUTCDate(today.getUTCDate() - 6) | ||
const start_date = startDate ? startDate : getStatsDateString(defaultStartDate) | ||
|
||
const differenceInDays = (new Date(end_date) - new Date(start_date)) / (1000 * 60 * 60 * 24) | ||
|
||
/* | ||
ERAS accepts queries in time interval "buckets" of day, week, month, or year. | ||
*/ | ||
function getInterval(differenceInDays) { | ||
if (differenceInDays <= 31) { | ||
return { | ||
end_date, | ||
period: 'day', | ||
start_date | ||
} | ||
return 'day' | ||
} | ||
|
||
if (differenceInDays <= 183) { | ||
return { | ||
end_date, | ||
period: 'week', | ||
start_date | ||
} | ||
return 'week' | ||
} | ||
|
||
if (differenceInDays <= 1460) { | ||
return { | ||
end_date, | ||
period: 'month', | ||
start_date | ||
} | ||
return 'month' | ||
} | ||
|
||
return 'year' | ||
} | ||
|
||
export function getDateInterval({ endDate, startDate }) { | ||
// Get new Date timestamps based on UTC strings, and then convert from ms to days. | ||
const differenceInDays = (new Date(endDate) - new Date(startDate)) / (1000 * 60 * 60 * 24) | ||
|
||
return { | ||
end_date, | ||
period: 'year', | ||
start_date | ||
} | ||
end_date: endDate, | ||
period: getInterval(differenceInDays), | ||
start_date: startDate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getStatsDateString } from '@utils' | ||
|
||
/* | ||
Get the default end date (UTC) for stats query | ||
*/ | ||
function getDefaultEndDate() { | ||
// Construct a new Javascript Date object | ||
const today = new Date() | ||
|
||
// .toISOString() in this function returns a UTC string like 2024-05-05 | ||
return getStatsDateString(today) | ||
} | ||
|
||
/* | ||
Get the default start date (UTC) for stats query | ||
*/ | ||
function getDefaultStartDate() { | ||
// Construct a new Javascript Date object | ||
const defaultStartDate = new Date() | ||
|
||
// .getUTCDate() returns numeric day of the month (UTC). | ||
// If a negative number is provided to .setUTCDate(), the date will be | ||
// set counting backwards from the last day of the previous month. | ||
const sevenDaysAgo = defaultStartDate.getUTCDate() - 6 | ||
defaultStartDate.setUTCDate(sevenDaysAgo) | ||
|
||
// .toISOString() in this function returns a UTC string | ||
return getStatsDateString(defaultStartDate) | ||
} | ||
|
||
export function getDefaultDateRange() { | ||
return { | ||
endDate: getDefaultEndDate(), | ||
startDate: getDefaultStartDate() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.