@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
60 lines (59 loc) • 2.2 kB
JavaScript
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-22 02:56:43
* Update:: import { makeTheTimeObject } to '@mikezimm/fps-core-v7/lib/logic/Time/timeObject;'
*/
import { monthStr3 } from "../../Time/monthLabels";
import { makeTheTimeObject } from "../../Time/timeObject";
/**
* 2024-08-24: Migrated from drillFunctions
* getGroupByDate
* @param fieldValue
* @param ruleSet
* @returns
*/
export function getGroupByDate(fieldValue, ruleSet) {
fieldValue = fieldValue.trim();
let tempDate = makeTheTimeObject(fieldValue);
let reFormattedDate = null;
// 'groupByDays' | 'groupByWeeks' | 'groupByMonths' | 'groupByYears' | 'groupByDayOfWeek' |
if (ruleSet.indexOf('groupByDays') > -1) {
reFormattedDate = tempDate.dayYYYYMMDD;
}
else if (ruleSet.indexOf('groupByWeeks') > -1) {
reFormattedDate = tempDate.year + '-' + tempDate.week;
}
else if (ruleSet.indexOf('groupByMonthsYYMM') > -1) {
reFormattedDate = tempDate.year + '-' + ("0" + (tempDate.month ? tempDate.month + 1 : 0)).slice(-2);
}
else if (ruleSet.indexOf('groupByMonthsMMM') > -1) {
reFormattedDate = monthStr3['en-us'][tempDate.month ? tempDate.month + 1 : 0];
}
else if (ruleSet.indexOf('groupByYears') > -1) {
reFormattedDate = tempDate.year ? tempDate.year.toString() : '';
}
else if (ruleSet.indexOf('groupByDayOfWeek') > -1) {
reFormattedDate = tempDate.dayOfWeekDDD;
}
else if (ruleSet.indexOf('groupByDateBuckets') > -1) {
if (tempDate.daysAgo === undefined) {
reFormattedDate = 'Unknown';
}
else if (tempDate.daysAgo > 360) {
reFormattedDate = '> 1 Year';
}
else if (tempDate.daysAgo > 30) {
reFormattedDate = '> 1 Month';
}
else if (tempDate.daysAgo > 7) {
reFormattedDate = '> 1 Week';
}
else if (tempDate.daysAgo > 1) {
reFormattedDate = '> 1 Day';
}
else {
reFormattedDate = 'Today';
}
}
return reFormattedDate;
}
//# sourceMappingURL=getGroupByDate.js.map