58
Views
6
Comments
Time difference template
Question

Hi

I'm making the reactive web app about managing sports event. Now i'm trying to make a template for sports event. That is kind of countdown like TodoList of match. This is the example of Template.





You can see the countdown field. 00:00:00 is the Base time. and task can be added before base time or after base time. so After creating this template, it will be used like down bellow.

Every Match will use the template. and when user just set the only base time like "18:00:00" then other time will be filled automatically. So i tried to make this template, but there are few problems i can't handle.

1) Countdown Data Type

I made Countdown field as Time(data type) then it needs AM/PM data. i need only HH:mm:ss, so what data type should i use? if i use text type then i can get data but i have to adjuest and valid the number like time. (ex. 01:80:77 (X)) i want to know what is the most reasonable way. do i need to make 3 attributes like Hour, minute, second seperately?


2) Set Time

It's a related with first question, when user set the base time like "18:00:00" then the other times will be filled automatically. so i thought that using timediff or some function, but if i make the countdown attribute as text or integer type, then How can i deal with this? Maybe cut the number ##/##/## and calculate as time.... It will be terrible......


And i will use isBefore field. when time field is 00:15:00 and isbefore=no then it will display +00:15:00. and if isbefore=yes then display -00:15:00. isbefore means "is this time before the base time?"

I will wait for you guys opinions... and i'm not used to outsystems.. so please give me some advice.

Thank you.



2023-03-16 16-29-51
Paulo Rosário

Hello Jiwon,

So let's tackle point by point.

1) Countdown Data Type 

Time is a valid Data type in OutSystems but I think that in your case you should use DateTime. There are some system functions in the platform that allow you to create a datetime variable using inputs.

You can use the NewDateTime() function to create a Date time variable with the user's input. 

2) Set Time 

Once you have your date time you can use some more date and time functions to manipulate that date time, like AddHours(), AddMinutes(), and so on. Note that you can add negative values to get date times in the past. 

Once you are done with the manipulations you can save your data as a Time variable using something like NewTime(Hour(DateTime),Minutes(DateTime ),Seconds(DateTime)) ( other functions).

In short take some time to rad about all the function in the links and I'm sure you will be able to work something out :) 

Hope it helps !

Paulo Rosário

UserImage.jpg
JIWON KIM

Hello,

Thanks for replying.

I understand what you said. but there's another thing i need to figure out. If i use DateTime Data type for countdown attribute, It requires Date esentially . but countdown attribute doesn't need date. because it's just template based only time. 

That's why i tried to use Time data type. but i turned out that Time Data type requires AM or PM... because in the input box, I need to choose AM or PM.  but you know, the time is not a real time like PM 18:00:00 . It's just relative to some base time.

So I hope you to give me some more advice.. Is there any way to get a Time data without AM or PM? Luckly the sports event is for one day event. so I don't need to care about the time over 24 hours. (if i need to do that, i think i can't use Time data type. 24:00:00 is the biggest(?) data for Time data type i guess.)

Thanks.

2023-03-16 16-29-51
Paulo Rosário

Hello, 

You are right; date time variables have a date component that you don't need, but I suggested you use date time because of the system functions I mentioned. 

Most system functions used to manipulate dates and times require a DateTime type variable. You can remove the date part of the variable after you are done processing by using the NewTime() function mentioned above, so the date remains irrelevant but you can access all the system functions you need.


2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @JIWON KIM ,

as for the datamodel, i would probably choose to store the countdown value as a single integer MinutesFromBase, being either a positive or negative number. (assuming your smallest unit is minutes, never seconds)

That makes displaying the actual time of each step in the schedule, very simple calculation AddMinutes(RealBaseTime, MinutesFromBase)

As for entering the value of a template, I would test if the people making the templates are comfortable with just entering the value directly (i.e. would they be happy entering -90 if something has to start 1.5 hours before base)  If the answer is yes, that makes it very easy for you.

If the answer is no,  you'll have to allow them to enter in for example a time field, with a before or after flag, and then you'll have to translate that into an integer value before storing.

Dorine

UserImage.jpg
JIWON KIM

Hello,

Unfortunately, I need hours, minutes and seconds all...! Becuase there are a few tasks that happen before the kickoff that are second-by-second. 

But your idea helps me. maybe i need to use Integer Type and use Newtime function and do something... Thank you for replying!

2021-09-06 15-09-53
Dorine Boudry
 
MVP

if your timer goes down to the second, then store the seconds in your integer, not the minutes, the idea remains the same.  

It is less likely however, that whoever is going to make the templates, will be happy with having to specify it in seconds, so you'll have to let him enter in hours, minutes and seconds, and then calculate the seconds when storing.

I'm not sure what you mean with NewTime, where you would use that ??

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.