Display type _time

We use the display type _time

Is it possible to type in the time (hour and minute) directly to this field?

and can this be change to an 24 hour time view?

Manual Time Entry:
Unfortunately, it’s not currently feasible to directly type the time (hour and minute) into this field.

24-hour Format:
The 24-hour time view isn’t ready yet, but it will be considered for future updates.

Hi CloudFuchs, I think I have the same use case. See this animated gift.

input-time

The fields in the database are of datatype “Time”. Is this what you want to do?

hey, this is exactly what I need. How did you manag that?

Thank you,

Fabian

1- I made a custom display type (Setup > Display types) with Display Type: Text and Mask: 99.99

2- In the form, set the display type of your time field to the custom type

3- In the same form field, call a function on the event ‘On Validate’

Here is the function for the startTime field. It is similar for the endTime field.
This validates the time format, displays the time difference and ensures that startTime < endTime.

In the next message, I will send the accessoiries functions stored in the libraries.
Don’t forget to add the libraries functions in the Libraires tab of your function.

2 Likes

Here are the accessories functions, maybe the Five Team can optimize my solution. Hope this help!
Jean

====================================================================
function formatTime(inputTime)
{
  const rawHours = inputTime.substring(0, 2);
  const rawMinutes = inputTime.substring(3, 5);

  const hoursWithoutSpace = removeSpaces(rawHours);
  const minutesWithoutSpace = removeSpaces(rawMinutes);

  if(isEmpty(hoursWithoutSpace))
  {
    throw new Error('Doit contenir l\'heure.');
  }

  if(isEmpty(minutesWithoutSpace))
  {
    throw new Error('Doit contenir les minutes.');
  }

  const hours = adjustLengthToTwoChars(hoursWithoutSpace);
  const minutes = adjustLengthToTwoChars(minutesWithoutSpace);

  if(parseInt(hours) > 23)
  {
    throw new Error('L\'heure doit ĂȘtre plus petite que 24.');
  }
  if(parseInt(minutes) > 59)
  {
    throw new Error('Les minutes doivent ĂȘtre plus petites que 60.');
  }
     
  return  hours + ':'+ minutes + ":00";
}

function adjustLengthToTwoChars(chaine)
{
  if (chaine.length === 1)
  {
    return '0' + chaine;  
  }
  return chaine;
}

function removeSpaces(chaine) {
    return chaine.replace(/\s/g, '');
}
====================================================================
function getPositiveTimeDifference(begin, end)  {

if ( !isEmpty(begin) && !isEmpty(end)) {

    const beginInSecond = mySqlTimeToSeconds(begin);
    const endInSecond = mySqlTimeToSeconds(end);
    const diff = endInSecond-beginInSecond;

      if(diff <= 0)
      {
         throw new Error("L\'heure de fin doit ĂȘtre supĂ©rieure Ă  l\'heure du dĂ©but.");
      }

    return secondsToHHMM(diff);
  }
  return 0;
}
====================================================================
function isEmpty(string)  {
    return (string.length === 0);
}
====================================================================
function mySqlTimeToSeconds(time) {
    const [hours, minutes, seconds] = time.split(":").map(Number); // SĂ©pare les parties et convertit en nombres
    return hours * 3600 + minutes * 60 + (seconds || 0); // Calcule le total en secondes
}
====================================================================
function secondsToHHMM(seconds) {

    const totalMinutes = Math.floor(seconds / 60);
    const hours = Math.floor(totalMinutes / 60);
    const minutes = totalMinutes % 60;
    return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
====================================================================

Thank you very much for your help!!!

I just needed another way to get a 24h time in the form, so I just used Regex for the validation:
([01]?[0-9]|2[0-3]):[0-5][0-9]

the difference between start and end and will try to get it in the report only.

1 Like