Here's a couple of methods I wrote for juggling CacheMV and *nix epoch dates. These might give you a running start. You can plonk them into an existing library class. Just set [Language = MVBasic] in the function declaration line or I can translate them to COS.
Bill
/// Convert between Pick and Unix Epoch dates</p>
/// <p>Options can be in any order and consist of the following flags:</p>
///
/// <li>D - Return only the date part</li>
/// <li>T - Return only the time part</li>
/// <li>I - Return the requested value part in internal format</li>
/// </ul>
/// <P>If no options are specified, then an external date-and-time string
/// is returned.</P>
///
/// <p>If "I" is specified, then either "D" or "T" must be specified.</p>
ClassMethod UDate(UnixDate As %Integer = 0, OptionFlags As %String = "") As %String [Language = mvbasic]
{
If Unassigned( %MVBDebugging ) Then %MVBDebugging = @false
IF Unassigned( %MVBExtendedDebugging ) Then %MVBExtendedDebugging = @false
If $Get(%MVBCommon) = "" Then %MVBCommon = "MVBooster.Common"->%New()
IF Abs( UnixDate ) = 0 THEN
RETURN OCONV( @date, "D4/" )
END
Time = REM( UnixDate, 86400 )
Days = INT( ( UnixDate - Time ) / 86400 ) + 732
BEGIN CASE
CASE OptionFlags = %MVBCommon->nil
Results = OCONV( Days, "D4/" ) : " " : OCONV( Time, "MTS" )
CASE ( INDEX( OptionFlags, "D", 1 ) > 0 )
IF INDEX( OptionFlags, "I", 1 ) > 0 THEN
Results = Days
END ELSE
Results = OCONV( Days, "D4/" )
END
CASE ( INDEX( OptionFlags, "T", 1 ) > 0 )
IF INDEX( OptionFlags, "I", 1 ) > 0 THEN
Results = Time
END ELSE
Results = OCONV( Time, "MTS" )
END
END CASE
RETURN Results
}
/// Return the unix epoch equivalent of a pick date and time. If the time isn't
/// supplied, midnight (the start of the day) is assumed
ClassMethod UDateFromPDate(PickDate As %Integer, PickTime As %Integer) As %BigInt [Language = mvbasic]
{
If $Get( %MVBCommon ) = "" Then %MVBCommon = "MVBooster.Common"->%New()
If Not( PickDate Matches "1N0N" ) Then InternalPickDate = IConv( PickDate, 'D' )
If Not( PickTime Matches "1N0N" ) Then InternalPickTime = IConv( PickTime, "MTS" )
If Status() <> %MVBCommon->successful Then
"MVBooster.Library"->SetCondition( Status(), "Invalid date for conversion." )
Return 0
End
JDate = ( PickDate - 732 ) * 86400
Return JDate + PickTime