How do I filter repeaters according to a timeframe?

Hi all!
I am just learning repeaters and can’t understand how to set up filters for a range of time. I see that I can filter per letter or number, but it seems that with the colon in the mix (i.e. 13:00), the functionality breaks. I want to be able to filter time results in an XL file, so that I display a range from 12:00-15:00, for instance. I can sort of figure out workarounds, but I want to properly understand how to solve for this.

I realize this is a basic question, but I can’t find an answer anywhere. Can someone please help?

You can use substr() to parse out the characters you want to filter by. This is pretty easy if you’re using a 24-hour clock. If you’re a silly American like me, that’s used to AM/PM, it gets trickier (but still doable). :smile:
Filtering_Time.rp (80.0 KB)

Things will get more complicated if you want to start filtering ranges longer than a single 24 hour period. Computers and date/time get’s annoying fast.


Thank you, @huban! I am a silly American as well, so having the example is great. Isn’t it so nice using “standard” measurements?? :smiley:

I am going to play with the file, and follow up if I can extra questions. Again, I really appreciate this!

@huban Can you explain in baby steps what you’re doing with the substr(0,2) line of code? I am coming from a background design, so my programming is limited to some html (and BASIC :stuck_out_tongue:)

[[Item.Start.substr(0,2) > wgt_Start.substr(0,2) && Item.Start.substr(0,2) < wgt_End.substr(0,2)]]

When I read this, I see that you’re saying the item (i guess, time) is bigger than the Start widget plus the item; and the same item (i guess time) is smaller than the End widget.

Does that sound about right?

Item.Start is referencing the column named “Start” in the repeater. It’s where the time value is stored for each row.
wgt_Start and wgt_End are local variables I created. They reference whatever value is selected in their respective drop lists.

In both cases, those values are stored as strings so in order for the math operators to work, we need to turn them into numbers. This is where the substr() method comes into play. We’re taking the first two characters (the “0” means start at the first character, the “2” is the total number of characters to return) of the values and comparing them.

The && means that both arguments must be true in order for the action to trigger. In this case, for the row to be filtered out or not.

So if we were to write it all out it would be:

“The value of the first two characters in Item.Start is greater than the value of the first two characters in wgt.Start” is a true statement.
“The value of the first two characters in Item.Start is less than the value of the first two characters in wgt.End” is also a true statement.
the row can stay visible.
If either one is false, filter out the row.

@huban Big props for the explanation! I can’t tell you how many times my eyes start to glaze over as I’m trying to understand this stuff. It’s clearly a learned language to speak with computers, and also a learned skill to explain it to fellow humans. Thank you for taking the time to do that, truly.

Your explanation makes sense. Thank you for taking the time to spell it out. I’m going to play around again to get familiar with it.

@huban I’m now trying to set up buttons that would act as time ranges (i.e. 6 hours, 12 hours, 24 hours). How does that change the (0,2) aspect? I assume I set up a function to tell the item to read a particular widget, which becomes >6 and <12. But I’m missing something since it doesn’t work. I’m trying to set up a 6 hour widget, 12 hour widget, 24 hour widget, and All widget (which is just removing all filters). But I think the (0,2) indicator is particular to the Dropdown list, correct? How do I make a direction using a Radio Button, which should be an easy “On/Off”/If/Else" filter function (right)?

I’m trying this line of code (based on what you shared), but I’m clearly missing something.

[[Item.Start.substr(0,2) > wgt_6.substr(0,2) && Item.Start.substr(0,2) < wgt_12.substr(0,2)]]

…it’s possible things just got a lot more complicated.

I’m having a little trouble visualizing what you’re trying to do but you could use buttons to filter the list so long as there is a specific “start” and “end”.

For example, you setup a group of radio buttons that to define certain “sets” of time:
{ } Early Morning 0:00 - 04:00
{ } Morning 05:00 - 11:00
{ } Afternoon 12:00 - 17:00
{ } Evening 18:00 - 20:00
{ } Night 21:00 - 23:00

Or you could add specific number of hours to a specified time.

Another issue you’ll run into is when your range extends into a new day. Six hours from 8:00 PM (20:00) is 2:00 AM (02:00) not 26:00 (20:00 + 6hrs != 26).

If it’s possible, you might link an example .rp file of what you’re trying to do. It would help give better context.

I am not supposed to share the file, unfortunately, since it’s for a client who is a bit secretive about their work. I promise you it’s nothing impressive…But your guess is right! I’m looking for a way to show the user how to look at data that fits within particular time periods.

They’d want to see what meetings (for instance) happen during:
{ } Morning 0:00 - 06:00
{ } Long shift 00:00 - 12:00
{ } Day 00:00 - 24:00
{ } All of Eternity (remove all filters)

I won’t have to worry about the next day issue (yet :P) This is a prototype for filtering hour blocks in one day.

Thank you!!

In that case, your code just got simpler, you don’t need the wgt_Start or wgt_End variables anymore since you’ll know the exact start and end number.

Radio Button “Morning” onSelect Add Filter:
[[Item.Start.substr(0,2) > 6 && Item.Start.substr(0,2) < 12]]

This is so cool, @huban May you receive great karma today from the prototyping gods!

I changed the fields to 0 and 6, so that it edits between the designated pretend time and 6:00 pretend time. This gives me a better understanding of how the rptr works.
Thanks so much!

Feels like time filtering could be its own set of tutorials. I’ve had two different developers tell me how tricky time filtering is, especially when you get into different time zones or new days. Thanks for giving it a crack.