EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: epicsTime::strftime
From: Andrew Johnson <[email protected]>
To: Eric Norum <[email protected]>
Cc: EPICS core-talk <[email protected]>
Date: Wed, 29 Jan 2014 16:28:53 -0600
Hi Eric,

On 01/29/2014 01:21 PM, Eric Norum wrote:
> Really busy today — is it as simple as the following?

Thanks for the pointer, I think this is slightly better (it clamps at
all 9s); test cases included.

- Andrew
-- 
Advertising may be described as the science of arresting the human
intelligence long enough to get money from it. -- Stephen Leacock
=== modified file 'src/libCom/osi/epicsTime.cpp'
--- src/libCom/osi/epicsTime.cpp	2011-04-05 15:23:22 +0000
+++ src/libCom/osi/epicsTime.cpp	2014-01-29 22:20:13 +0000
@@ -554,9 +554,11 @@
                         static_cast < unsigned long > ( 1e1 ),
                         static_cast < unsigned long > ( 1e0 )
                     };
-                    // round and convert nanosecs to integer of correct range
+                    // round without overflowing into whole seconds
                     unsigned long frac = tmns.nSec + div[fracWid] / 2;
-                    frac %= static_cast < unsigned long > ( 1e9 );
+                    if (frac >= nSecPerSec)
+                        frac = nSecPerSec - 1;
+                    // convert nanosecs to integer of correct range
                     frac /= div[fracWid];
                     char fracFormat[32];
                     sprintf ( fracFormat, "%%0%lulu", fracWid );

=== modified file 'src/libCom/test/epicsTimeTest.cpp'
--- src/libCom/test/epicsTimeTest.cpp	2013-06-07 19:35:45 +0000
+++ src/libCom/test/epicsTimeTest.cpp	2014-01-29 22:06:58 +0000
@@ -48,7 +48,7 @@
     const int wasteTime = 100000;
     const int nTimes = 10;
 
-    testPlan(12 + nTimes * 18);
+    testPlan(15 + nTimes * 18);
 
     try {
         const epicsTimeStamp epochTS = {0, 0};
@@ -96,6 +96,10 @@
         et.strftime(buf, sizeof(buf), pFormat);
         testOk(strcmp(buf, "1990-01-01 00.098765432") == 0, "'%s' => '%s'", pFormat, buf);
 
+        pFormat = "%S.%03f";
+        et.strftime(buf, sizeof(buf), pFormat);
+        testOk(strcmp(buf, "00.099") == 0, "'%s' => '%s'", pFormat, buf);
+
         pFormat = "%S.%04f";
         et.strftime(buf, sizeof(buf), pFormat);
         testOk(strcmp(buf, "00.0988") == 0, "'%s' => '%s'", pFormat, buf);
@@ -113,6 +117,14 @@
         et.strftime(smbuf, sizeof(smbuf), pFormat);
         testOk(strcmp(smbuf, "00.*") == 0, "'%s' => '%s'", pFormat, smbuf);
 
+        pFormat = "%S.%03f";
+        (et + 0.9).strftime(buf, sizeof(buf), pFormat);
+        testOk(strcmp(buf, "00.999") == 0, "0.998765 => '%s'", buf);
+
+        pFormat = "%S.%03f";
+        (et + 0.901).strftime(buf, sizeof(buf), pFormat);
+        testOk(strcmp(buf, "00.999") == 0, "0.999765 => '%s'", buf);
+
         pFormat = "%%S.%%05f";
         et.strftime(buf, sizeof(buf), pFormat);
         testOk(strcmp(buf, "%S.%05f") == 0, "'%s' => '%s'", pFormat, buf);


References:
epicsTime::strftime Pearson, Matthew R.

Navigate by Date:
Prev: epicsTime::strftime Pearson, Matthew R.
Next: Build failed in Jenkins: epics-base-3.14-cyg64 #2 APS Jenkins
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: epicsTime::strftime Pearson, Matthew R.
Next: Build failed in Jenkins: epics-base-3.14-cyg64 #2 APS Jenkins
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 16 May 2014 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·