clockify

Duration data type in TimeIntervalDto object


I am creating a database to store time entries that have been created in Clockify, I need to declare a data type for the duration field. A string is returned in the TimeIntervalDto and an example provided in the API documentation is "PT1M4S" or "PT1H30M15S". This is obviously a meaningful string if you know how to decode it.

The example given in the API documentation is:

"timeInterval": { "duration": "PT1M4S", (Example: PT1H30M15S - 1 hour 30 minutes 15 seconds) "end": "2018-06-12T14:01:41Z", "start": "2018-06-12T14:00:37Z" },

My questions are:

  1. How to I translate duration to something meaningful; and
  2. What is the maximum size I would need to cater for, assuming that I'm using varchar, or nvarchar as the data type?

Solution

  • You are working with the ISO 8601:2004(en) duration ISO format.

    You have a pattern like the follow: "PnnYnnMnnDTnnHnnMnnS"

    In detail:

    So for your question:

    If you can use C# languange before saving to database you can decode de pattern using something like this:

     String pattern = "PT1H30M15S";
     TimeSpan ts = System.Xml.XmlConvert.ToTimeSpan(pattern); //Use System.Xml because it works with ISO 8601:2004
    

    You can look for further information on in the ISO webpage. https://www.iso.org/obp/ui/#iso:std:iso:8601:ed-3:v1:en