简体   繁体   中英

Cube.js React QueryBuilder : "This month" and "Weekly" not getting data from start of week if month changes mid-week

I understand why "This month" combined with "Weekly" doesn't get the full week's data if the month starts at the middle. For example the week starting September 27th still shows as starting 2021-09-27 but the data is only taken from 2021-10-01 as the "This month" filter is set, it makes sense but sometimes we would like to get the full week even if the month changed midweek but we don't want to set a broader filter ( "This quarter" or even "This year" are too many weeks to consider). I tried tracing the TimeDimensions function back and ended at the "QueryBuilder" component, on the "updateTimeDimensions" but it's imported from '@cubejs-client/react' so I cannot see what the component accepts as "Time Dimension" or if you can add an option of "This month + full weeks" . Does someone have any suggestion on how to make this work?

you can always manipulate your dates in the front-end before feeding them to query time_dimensions.

Define a function that takes your dateRange ['2021-10-1', '2021-10-31'] and returns a dateRange that includes weeks completed, that's possible with date-fns or moment.js or day.js. and call that function when you select 'Weekly'.

here is an imperative example :

dateRange: any = [new Date('2021-10-1'), new Date('2021-10-31')];
startAndendWeeksIncluded = [
    startOfWeek(this.dateRange[0], { weekStartsOn: 1 }),
    endOfWeek(this.dateRange[1], { weekStartsOn: 1 }),
  ];
 
//OutPut ["2021-09-26T23:00:00.000Z", "2021-10-31T22:59:59.999Z"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM