I have an app that adds dates that have been picked by the user to a list however, I was wondering if it was possible to make a condition that states that:
if selected day is 7 days away from current day:
set list item green
if selected day is 3 days away from current day:
set list item red
Would it be possible to change the colour of individual text items in a list viewer depending on the selected dates relation to the current day? Any help you be much appreciated, here is what I have so far:
Hi, @jakeheron! I donât know if checking for a relation between dates is doable, but what I know is we cannot customize font-color/font-size/etc. for specific items in a listviewer.
However, you can try using the DVL (Data Viewer List), and build a custom-layout, and add the labelâs text-color in the Advance Bindable Properties. Hereâs a demo project - Thunkable
Let me know if this works for you. Cheers!
Also, since this is a public community, please avoid tagging particular people in your first post.
As for date comparison, Thunkable does not provide any specific blocks but what I do is I create an app variable that store the Year followed by the Month and the Day of the date to be compared as text (example 20211026) and multiply it by 1. This gives me a number that I can compare it with another number. If I am comparing two dates then I will convert both dates to numbers using the same formula.
Thanks for the sample code. What I would like to occur however is when the user adds an list item with the date, the code adds something to indicate that the task is due soon. This is an example:
So when this screen opens, could there be a code that can parse each assignment, check its due date and add a string to the assignment such as âtask due soonâ'. Here is some pseudocode to explain.
when assignment screen opens:
for each item j in list assignments:
if current day of month - j due date < 4:
set j to join jâs text with âtask due soonâ
hopefully this explains what I would like to occur.
Your pseudo code is logically correct and you can go ahead implementing it.
Because you parse number of strings in one list entry this will not work directly
You will, instead need the substring that contains the date and parse it again to have all numbers before you can evaluate it.
So for the example above, the date shown in the screen is Oct 29, 2021 you will need to take the last 4 characters then you will need a list of months in 3 letters to convert Oct to 10 and last adding the day of the month to it.
once this is done then you can check if the difference between that date and today is less than 4 days.
I am trying to implement this parsing algorithm you described however, it is much harder than I initially thought. I have successfully managed to parse j to retrieve the year and month. I have used an if statement to convert the month into a number; would there be a better way of doing this to avoid using lots of if statements?
Plus, parsing the day poses a slight problem; the algorithm wonât work for all days since say the first day of the month is â1â and the 20th is â20â. These days have different number of characters so I am not sure how I could get the day.
Hi, @jakeheron! You can try delimiting the date by spaces (using the list from text block in lists section), which would give you a list of Oct | 29, | 2021.
Now since we are splitting by spaces, this wonât have a character count issue. (you can use the get list item #(1/2/3) block to get any of the three items from the delimited list)
There is one slight problem. When the list is created using a delimiter, each list item is essentially each letter from the string, not the individual date components. For instance, if the date is Oct 29, 2021, the least created is O, c, t, 29, 2, etc. Is there a way to work around this? Here is a link to the project. Go to the âHomeworkâ screen to see the code.
I had a look into your project, and found out that you are trying to delimit the text by 2 spaces , instead of one. I think entering a single space should do the job.
Here you can see that there is a list âstored variable assignmentsâ that contains all of the user inputed tasks. For each item âjâ in that list, âapp variable assignment due dateâ is being set as the substring of âjâ containing the date. This date is later parsed again to separate all of the date components: day, month, year.
The problem here is that the parsing wonât work as the number of characters within the date substring will change depending on the day. Therefore, this algorithm will only work with days containing two digits eg. 29.
This shows you apply different date formats within your app which will make it difficult to extract
The image is from your earlier post.
Anyway, let us assume you will standardize it on Oct 29,2021 format
If I would take the first entry in your list "Mathematics: Oct 29, 2021 Do this then I will do the following (I will use more variables that I would normally do for clarification)
Thank you so much @muneer for taking the time to design this code. I have tried to implement your solution but using a for loop to check each item, j, within an assignment list. I added one assignment to the list and made it so a label would display the date. The result was that the date displayed was a weird mess of the list item, bearing no resemblance to the date you got in your testing. I have carefully checked for errors but I couldnât spot the issue so iâve included the code:
I can see where you got wrong.
The algorithm is to extract the date from the assignment and then use the date extracted to split it further in year, month and day but when you coded your blocks you continued using âjâ where you should use âassignment dateâ.
See the circles around wrong variables in your code
Thank you @muneer , the parsing algorithm is working perfectly now. The last small thing is creating a condition that labels tasks due soon. I have had a go at implementing this:
However, the if statement seems to be returning true no matter what date I select. Additionally, the âAssignment due soonâ message keeps getting duplicated when the screen opens.