mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 20:17:59 +00:00
Ui/pricing metrics params (#10083)
metrics route takes start and end params and passes to the date display field, as well as the route's API call
This commit is contained in:
20
ui/app/helpers/parse-date-string.js
Normal file
20
ui/app/helpers/parse-date-string.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
import { isValid } from 'date-fns';
|
||||
|
||||
export function parseDateString(date, separator = '-') {
|
||||
// Expects format MM-YYYY by default: no dates
|
||||
let datePieces = date.split(separator);
|
||||
if (datePieces.length === 2) {
|
||||
if (datePieces[0] < 1 || datePieces[0] > 12) {
|
||||
throw new Error('Not a valid month value');
|
||||
}
|
||||
let firstOfMonth = new Date(datePieces[1], datePieces[0] - 1, 1);
|
||||
if (isValid(firstOfMonth)) {
|
||||
return firstOfMonth;
|
||||
}
|
||||
}
|
||||
// what to return if not valid?
|
||||
throw new Error(`Please use format MM${separator}YYYY`);
|
||||
}
|
||||
|
||||
export default helper(parseDateString);
|
||||
Reference in New Issue
Block a user