Time duration field format

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="(0[0-9]|1[0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9])" />
  </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!