HKStatisticsCollectionQuery pulling data for each week of the month

I am trying to create a chart that displays monthly data versus last month's data broken down by week.

For example, viewing the chart today shows July versus June, each chart will have 5 points with the following dates:

June: 1-8, 9-15, 16-22, 23-29, 30 July: 1-8, 9-15, 16-22, 23-29, 30-31

The predicate looks like

NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:self.pastStartDate endDate:self.currentEndDate options:HKQueryOptionStrictStartDate];

      

where self.pastStartDate

is the first of the last months, and self.currentEndDate

is the last of the current month.

Then we create a request like this

HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:predicate options:HKStatisticsOptionDiscreteAverage anchorDate:self.pastStartDate intervalComponents:self.interval];

      

So, for a month is self.interval.day = 7

set in such a way that we retrieve data for a week for each interval. The problem is that this interval is not known to the calendar, so it doesn't know that the last month's data endpoint should only have 1 day, so we get some overlap.

We tried it too self.interval.weekOfMonth = 1

, but again, the interval doesn't know what month it is in, so that doesn't work either.

Is there a way to create a calendar-based interval so that it doesn't include more than the end of the month in a given interval?

+3
ios objective-c nscalendar health-kit


source to share


No one has answered this question yet

Check out similar questions:

1300
Transferring data between view controllers
372
Master data: the fastest way to delete all instances of an object
275
NSDate get year / month / day
five
NSCalendar: problem getting weeks in a month
1
Find all days of week / month / year and add to NSMutableArray
1
calculate the number of weeks given by month
1
Using NSDateComponents / NSCalendar to decode weeks of the month
0
Getting user data in week, month and year format from healthkit in swift
0
Swift: how to create a custom update element for its size
0
LineChart plot data not filling UIView



All Articles
Loading...
X
Show
Funny
Dev
Pics