A decent storage for datetime values

Introduction
I don't know how many people wonder about the storage in Caché, but, coming from a world where a byte is a byte, I quickly dropped an eye into the way date-times values were stored in Caché. I also quickly put away the Timestamp format for it looked strange to store plain text datetimes at the global level. On the other hand the Horolog format was very convenient for calculations and searches. Thanks to the newsgroup community, I moved to the idea of building my own Datetime datatype. Here it is:

Code
Class BSE.DateTime Extends %Library.TimeStamp [ ClassType = datatype, ClientDataType = TIMESTAMP, OdbcType = TIMESTAMP, ProcedureBlock, SqlCategory = TIMESTAMP ] {

/// Declares the XSD type used when projecting XML Schemas. Parameter XSDTYPE = "timestamp";

///Convert a serialized format (DD/MM/AAAA HH:MM:SS) to internal indexable Horolog format ClassMethod DisplayToLogical(%val As %String) As BSE.DateTime {
 * s va=$S(%val="":"",1:$ZDTH(%val,4,1,,,,,,,""))
 * q:va="" ""
 * q +va_","_$E(100000+$P(va,",",2),2,6)

}

/// Check the validity of a date time ClassMethod IsValidDT(%val As BSE.DateTime) As %Integer {
 * q:(%val?1.5N1","1.5N) 1
 * q 0

}

/// Convert a serialized format to internal format $H ClassMethod LogicalToDisplay(%val As BSE.DateTime) As %String [ CodeMode = expression ] {
 * $S(%val="":"",1:$ZDT(%val,4,1,,,,,,,,""))

}

/// Convert an internal format to ODBC format ClassMethod LogicalToOdbc(%val As BSE.DateTime) As %String [ CodeMode = expression ] {
 * $S(%val="":"",1:$ZDT($P(%val," ",1),3,1,,,,,,,,""))

}

/// Convert an internal format to XSD format ClassMethod LogicalToXSD(%val As BSE.DateTime) As %String {
 * q $S(%val="":"",1:$ZDT(%val,4,1,,,,,,,,""))

}

/// Check the value and return an indexable Horolog format ClassMethod Normalize(%val As BSE.DateTime) As BSE.DateTime [ CodeMode = expression ] {
 * $S(%val="":"",1:$E(%val,1,5)_","_$E(100000+$P(%val,",",2),2,6))

}

/// Convert an ODBC format to internal indexable format ClassMethod OdbcToLogical(%val As %String) As BSE.DateTime {
 * s va=$S(%val="":"",1:$ZDTH(%val,3,1,,,,,,,""))
 * q:va="" ""
 * q +va_","_$E(100000+$P(va,",",2),2,6)

}

How to use Horolog in your code
The use of such datatype in your class is very easy, e.g.: Property myProperty As BSE.DateTime; (BSE stands for Business System Entity but you can place the DateTime definition anywhere else) When writing ObjectScript code, you can set a BSE.DateTime value as any Horolog value (including $H). But if this value is used as an index, you have to store it "clean". It means that $H is wrongly sorted for time under 02:46:40, because the number of seconds express with less than 5 figures. Example: 09/19/2007 01:05:00 (60892,3900 in Horolog) is sorted before 09/19/2007 00:06:40 (60892,400)

To solve that problem, we added a macros definition for a "super-$H" and an Horolog converter: (macros file...)
 * 1) define H      $E(+$H,1,5)_","_$E(100000+$P($H,",",2),2,6)
 * 2) define toH(%dt)      $E(+%dt,1,5)_","_$E(100000+$P(%dt,",",2),2,6)

- $$$H returns a well formated string for current date and time - $$$toH( HorologValue ) returns a well formatted value from a standard Horolog datetime