[Solved] Adding time from a DB to user input time

i think the sequence should be:

  1. take the FDP Start time
  2. adjust it according to the FDP correction
  3. use the adjusted value and loop thru the rows in the table until the adjusted value falls within the start and end of the FDP start and end,
  4. use the value in the desired column

I’ll admit to not fully understanding what you were trying to do. If the resulting value is in the same row then you’ll have to use a different lookup method than just adding/subtracting row amounts.

What you told me actually solved the problem. I expanded the rows so that each one spanned only one hour of time even when it used the same column values as the next row. Doesn’t probably make sense, but it worked like a champ.

But I just found an issue. If the user picks row 1, and the correction moves that index -3, then there is no more data. Since the rows are windows of time starting with 0000-0059, a correction of -3 to that should result in the row of time 2100-2159. Not sure how to make that happen. attached is the new data set

Your formula is: newRow# = currentRow# + modifier
So for row 4 if you’re adding a modifier of -3, you get row 1 which works.
But for row 2, if you’re adding a modifier of -3, you get row -1, which fails.

Instead, your formula should be: new row = test if [currentRow#+ modifier < 1] → [maxRow# + (currentRow# + modifier)] else → [currentRow# + modifier]

Use the test-->if/else block to set up the if condition within the formula.

So as an example, for row 2 with a modifier of -3, the new formula would be 2-3=-1 therefore return 24+(2-3) which equals 23 as the row #.

Another example: if the row is 1 and the modifier is -3, the formula would be 1-3=-2 therefore return 24+(1-3) which equals 22 as the row #.

Or simpler maybe to use these two lines of code:

newRow# = currentRow# + modifier
If newRow# < 1 then newRow# = newRow# + maxRow#

Try it out with a few more sample values to make sure it works. :wink:

I assume you’ll need to do something similar for cases where the row would exceed 24 (e.g. 23 + modifier of 2).

A whole other option is to extend your table a few rows above and below the current data set. Just leave out the first column value so that it doesn’t get found in the search results. Then add/subtract the modifier row number and move up or down the table.

1 Like

Tried the second two already with weird results. I used the block below to try to get to your first formula. It will not work for any value that returns a negative number for the index.

Check that…I refreshed the app and it worked! Thanks for the 10th time.

2 Likes

The app is returning “undefined” given this block:


-“Latt plus limit hours” might equal 15.133333.
-I take the second element of that number after the delimiter “.” so “Max LATT Min” equals 133333.
-I set the variable “minutes” to the substring of the first two letters of “Max LATT Min”, so I get 13.
-Since I have to convert that number to minutes, I multiply by .6 and round it, so I get 7.8 which rounds to 8.
-I then include a series of “if” statement to change the text visible to the user from “8” to “08” so that the number is in a recognizable minute, or time, form. The “if” statements change any number 0 through 9 to 00 through 09.
*Problem: it works for every number except “0.” If the number after the delimiter is “0”, then I get “undefined” presumably because it recognizes “0” after a decimal as not a number since it has no value? If I want to return “12:00”, I get “12:Un”.

1 Like

You can use an if/else block or a test block to check if Latt plus limit hours contains “.” or is “0” (choose one condition, not both!). Based on that, you can either apply your in list block from your screenshot or you can just set Max LATT Min's Text to “0”.

1 Like

Does this work for you?
image
You are effectively comparing the content of Max LATT Min which is text to 0 which is a number.

1 Like

when you are converting the first 2 letters of max_latt_min , use this formula:

temp=100+round(13*0.6)
you’ll get 108. simply use get the subtring of temp from position 2, that’s your answer. it will work very well when the minutes is zero.
in other words,
minutes=substr(temp,2,end)

2 Likes

That did it! Thanks for the 23rd time.

What about in the case where the first two letters of max_latt_min is “50”? I’d like the formula to use:
temp=100+round (50*0.6)

It uses (5 * 0.6), so the result is 3 and I want it to be 30. Likewise, when max_latt_min is “05”, it uses the exact same formula (5 * 0.6), so that result is also 3. I’ve set max_latt_min to return “03” when the formula yields “3”, so now I get the same answer for two different problems.

If the input to the equation is 5, do you want the output to be “3”, “30” or “03”?

If you need a trailing zero, multiply the result by 10. If you need a leading zero, join “0” to the result. You can use an if/else block or test block to check if the result is less than 10 and then apply either adjustment.

I’ll try that. The input to the equation would either be 05 or 50, never 5. Thx

If the input is “05” what is the expected output?

If the input is “50” what is the expected output?

Please post an updated screenshot of the blocks you’re using to make those calculations.

Because you’ve said above that the same equation yields the same result for different values and that shouldn’t be happening.

I find this set of blocks to be really confusing:

I think there’s a much simpler way using just math blocks. But I need to have the information you’ve mentioned in a different format, like this:

Latt plus limit hours value as a string → expected output value as a string

So maybe that’s something like this:

“05” → “03”
“12.05” → “03”
“50” → “30”
“8.5” → “30”

Can you provide that? A few examples, not just one.

Because my understanding of what you need is to convert a decimal number of hours (e.g. 5.2) to minutes (e.g. 0.2 minutes = 12 minutes) while ignoring the whole/integer hour value (5).

If it is… this should be much simpler:

It converts the sample value of 5.333 hours to 20 minutes because the remainder when dividing by 1 is the decimal value which is 0.333 and 0.333 * 60 rounds to 20.

Or are you trying to take the whole/integer number of hours and convert it to minutes? In that case, 5.333 hours would equate to 300 minutes because we drop the decimal value and calculate 5 * 60 = 300. That would be achieved using these blocks:

1 Like

The original intent is to take a list of the 24 hours and a list of the 60 minutes that a user can select as a “start” time. Depending on what that time is, I query a DB to find the total number of minutes that user can be on duty. I then add that minute limit to the selected start time (converted to minutes) to generate an end time called Max_LATT_Min. Max_LATT_Min then has to be converted back to hours, so I divide it by 60 to get a decimal number of hours like 5.333. I separate that number by delimiting with the decimal so that I can add hours to hours in one operation, and minutes to minutes in another operation (but I only did this because I can’t figure out an elegant way to do it). The inputs and outputs are exactly as you wrote:

 So maybe that’s something like this:

“05” → “03”
“12.05” → “03”
“50” → “30”
“8.5” → “30”

I’ll try this:


which is totally genius (to me).

Here is the new block:


Confusing, but the text block Latt_plus_limit_hours is a number like 15.13333 which is based on adding 540 minutes to the user input of 368 minutes, then dividing by 60. I plugged that text into your block using the variable Latt_plus_lim_hours. the answer to that is 15 hrs and 8. It should be 15 hours and 08 minutes.

I’m so lost. I really can’t follow what you’re saying, I’m sorry. I just need it formatted in a simple, straightforward way (input → output). It seems like maybe you’re calculating both hours and minutes or maybe you’re just mentioning the hours because you display that to the user but in terms of math, what is the input and what is the expected output?

If you’re starting with 15.13333 and expecting “08” to be the result then you’re really close if you’re getting 8. You just need to use the join block to join zero (“0”) to the result whenever it’s less than 10. But I haven’t seen you try that so I don’t know if that still doesn’t make sense to you or if you haven’t tried it.

If you’re starting with 15.13333 and getting “15 hrs and 8” (whatever that means) then again, I’m lost. I don’t see that in the blocks you’ve shared.