- Log in to post comments
User bio
404 bio not found
Member since Jan 20, 2016
Posts:
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 timeset str = ##class(%Library.PosixTime).LogicalToTimeStamp(posix)
// Strip the microseconds value and the decimal pointset stripped = $E(str,1,19)
// Reconstruct the PosixTime object from the stripped String representationset 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 { sx=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w$zh-t
1.969733
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w$zh-t
2.025097
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).RoundPosixToSeconds(posix) } w$zh-t
1.975352
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w$zh-t
1.057825
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w$zh-t
.92929
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w$zh-t
.9343
CRMBI>while$zh#1 {} s t=$zh f i=1:1:1E6 { sx=##class(CRMBI.JSONSynced).PosixToTimeStamp(posix) } w$zh-t
.941494
CRMBI>
Thank you all again
- Log in to post comments
I should have copied and saved its suggestion, but the DC AI offered another approach that also required some string manipulation. :-)
- Log in to post comments
Certifications & Credly badges:
Followers:
Jean has no followers yet.
Following:
Jean has not followed anybody yet.
Thank you for the links; I'll investigate the differences in NLS/locale settings between the systems.
I'm helping to debug an app that uses $c(254) and $c(255) as line and field terminators for parsing a large ASCII data file. I moved the relevant code and the data file to a system I use for general debugging and was surprised by the different behavior of those $c() calls, hence the question.
I'll post what I needed to reconfigure to get the "debugging" system to work like the original system.
Thanks again.