Field of type time or decimal, how to solve?

Asked

Viewed 56 times

2

I have in the system that I am developing a field called flow, which can be filled either with a decimal value like 0.5 and 2.4 or with a value of time, like 15 min and 5 h.

What is the best solution when creating this field in my table? Leave as string same? My fear is that in the future they will have to use these values for some calculation and then may give problem.

And in my input to register this information, how can I mask this to prevent the user from typing what should not?

I’m thinking of creating 2 fields in the table, one for each type... And in the information register put a radio or something so the user choose whether to register time or decimal value, and then I apply the mask. That would be bad?

2 answers

4


I think you are thinking of the right solution. I will list the options.

  1. Imagining that you would need calculations, the best solution is not to do this. The correct one would be a way to normalize the value. For example, if you choose decimal notation, then record 0.25 to 15min or 5 to 5h.

  2. If it is not possible to normalize properly and really need to know when decimal or in time, then the solution is to have two distinct fields and an auxiliary indicating which of the two to use. Eventually I wouldn’t need this auxiliary field if I could work with null, so anything that’s not used would be null. Evidently the application (or a restriction in the database) would have to take care to never have both used.

If this cannot be done, any solution will be bad.

  1. However, if the field is merely descriptive and it matters little to the application what is inside it, then use a string may be the most appropriate.

The select button can be a good one. Depending on the option would prevent the completion of the other or even change the unique field shown to the user. You can change the mask. Might not even need this.

It is possible for the client application to identify that one was typed and prevent the other’s typing. You have to inform the user well that to release the other, if he wants, you have to delete one of these fields. I’m not saying it’s the best solution for your users.

I can’t tell you about the mask because I don’t know what can and can’t. Anyway I think this is already another question with a different problem (do it separately).

  • great options @bigown, I will see with the customer more in depth about the function of this field so that I can choose better, but I think the string type will supply well together with a show/Hide of the field that the user choose.

  • In case I need to do calculations, I could normalize to decimal and have an auxiliary field to tell how the value should behave, right?

  • If normalize would not need, because then time passes to be recorded as if it were a decimal value. It makes no difference if the user entered in hours or with decimals, it saves decimals and period. As you will present is application problem at each time, can present both in decimal and in time (have to do the conversion obviously)

0

Apparently the best option is the one you described: two distinct fields in the table and the user selects what will be entered by radio.

Because in the future it is easy if you need to calculate with the values and/ or filter everything that has been entered decimal or everything that is time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.