Time duration field format

I’d like to create a format for entering time duration information under the form hh:mm:ss (hour:minute:second). The aim would be to be able to integrate the duration of a recording, its start and also its end. This would be useful for our ‘Animal sound archive’ collection.

I’ve managed to create a format in the form ##:##:## but I’d like it to default to 00:00:00 and I’d also like the first digit to be limited to numbers 1 to 24, and the second and third to be limited to numbers 1 to 60.


image

Does this have anything to do with ?

And also, does Specify have any other way of integrating durations?

Thanks

Hi @Marion,

Thanks for your question! You were in the right place when you asked about this problem, as a regular expression field format is the only way to handle this as you describe.

In the Field Formatter app resource (UIFormatters, you can create one if none exists), you need to add the following format:

[!warning]
Make sure to replace the class and fieldname with the name of the table (e.g. CollectingEvent) and the name of the field (e.g. text5) in the corresponding spaces below. You can create multiple formats for additional fields if needed.

  <format
    system="false"
    name="DurationHHMMSS"
    class="edu.ku.brc.specify.datamodel.CollectingEvent" 
    fieldname="text5">
  <!-- Enforce exactly 8 characters: hh:mm:ss -->
    <field
      type="regex"
      size="8"
      value="(0[0-9]|1[0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9])"
      pattern="00:00:00" />
  </format>

In the Schema Config, you will need to assign the field you want to assign a format to to that (e.g. DurationHHMMSS):

In your View Definition XML, you just need to make sure the field you want to format is visible and this is where you would want to set the default for the field (e.g. 00:00:00):

<row>
	<cell type="label" labelfor="timeDuration"/>
	<cell type="field" id="timeDuration" name="text5" uitype="text" default="00:00:00"/>
</row>

Now you have a working timestamp field with the restrictions you described (*slight adjustment with “1 to 59” instead of “1 to 60”)!

Invalid (25 > 24, restricted by the format):

Valid (23:59:20 matches the format)


There are no other specific integrations for durations in Specify, but I am interested to hear what you have in mind!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.