I am building a SCORM 2004 javascript API for an LMS, and one of the SCORM 2004 requirements is that timeintervals passed into it must follow the following format. Does anyone know what the regular expression of this would be? I am trying to wrap my mind around it, but to no avail. Note: P must always be the first character.
P[yY][mM][dD][T[hH][nM][s[.s]S]] where:
- y: The number of years (integer, >= 0, not restricted)
- m: The number of months (integer, >=0, not restricted)
- d: The number of days (integer, >=0, not restricted)
- h: The number of hours (integer, >=0, not restricted)
- n: The number of minutes (integer, >=0, not restricted)
- s: The number of seconds or fraction of seconds (real or integer, >=0, not restricted). If fractions of a second are used, SCORM further restricts the string to a maximum of 2 digits (e.g., 34.45 – valid, 34.45454545 – not valid).
- The character literals designators P, Y, M, D, T, H, M and S shall appear if the corresponding non-zero value is present.
- Zero-padding of the values shall be supported. Zero-padding does not change the integer value of the number being represented by a set of characters. For example, PT05H is equivalent to PT5H and PT000005H.
Example -
- P1Y3M2DT3H indicates a period of time of 1 year, 3 months, 2 days and 3 hours
- PT3H5M indicates a period of time of 3 hours and 5 minutes
Any help would be greatly appreciated.
Thanks!
UPDATE:
I have added some additional standards that must be kept -
- The designator P shall be present
- If the value of years, months, days, hours, minutes or seconds is zero, the value and corresponding character literal designation may be omitted, but at least one character literal designator and value shall be present in addition to the designator P
- The designator T shall be omitted if all of the time components (hours, minutes and seconds) are not used. A zero value may be used with any of the time components (e.g., PT0S)