User bio
404 bio not found
Member since Jan 20, 2016
Replies:

Thanks all for the feedback and interesting code examples. Although it's twice as slow as the approach as @Julius.Kavay's clever numbers-only approach, I'm going with the string manipulation approach after all. I find it easier to document and therefore easier for an ObjectScript newby to understand. (Newby asks: "What do all those numbers mean? ☺)

/// Round the supplied PosixTime to whole seconds (strip microseconds)
ClassMethod RoundPosixToSeconds(posix As %Library.PosixTime) As %Library.PosixTime
{

    // Get the String representation of the posix time
    set str = ##class(%Library.PosixTime).LogicalToTimeStamp(posix)

    // Strip the microseconds value and the decimal point
    set stripped = $E(str,1,19)
    
    // Reconstruct the PosixTime object from the stripped String representation
    set newposix = ##class(%Library.PosixTime).TimeStampToLogical(stripped)
    quit newposix
}

NOTE: That last comment was generated by Tabnine VS Code extension. Needs an edit. 

I also appreciate the "timing" code that Julius provided. Here are the stats (after I ended up using $E instead of $P. (Thank you @Robert Cemper !)

CRMBI>set posix = 1154669852181849976
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w $zh-t
1.969733
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w $zh-t
2.025097
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w $zh-t
1.975352
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w $zh-t
1.057825
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w $zh-t
.92929
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w $zh-t
.9343
CRMBI>while $zh#1 {} s t=$zh f i=1:1:1E6 { s x=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w $zh-t
.941494
CRMBI>


Thank you all again

Hi again Robert,

I also would have expected the plans for both 18 and 19 to be the same, but "quelle surprise!":

18: Beautiful, expected plan:

19: What? I must have messed something up in the evolution of this class to have such an expensive plan that produces incorrect results:

I'll investigate further to figure out how to address that second plan, but any input from you or others would be welcome.

Thanks and best regards.

Certifications & Credly badges:
Global Masters badges:
Followers:
Following:
Jean has not followed anybody yet.