Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019 
<== Date ==> <== Thread ==>

Subject: Re: pyEpics time stamps
From: Matt Newville <newville@cars.uchicago.edu>
To: Eric Norum <wenorum@lbl.gov>
Cc: EPICS mailing list <tech-talk@aps.anl.gov>
Date: Tue, 13 May 2014 18:20:10 +0200
Hi Eric,

As Mark said, I am still maintaining pyepics, and was traveling yesterday and at a meeting (wifi-less) most of today.

On Mon, May 12, 2014 at 6:39 PM, Eric Norum <wenorum@lbl.gov> wrote:
I’ve found the problem — the code in lib/dbr.py looks just plain wrong:
EPICS2UNIX_EPOCH = 631173600.0 - time.timezone
. . .
def make_unixtime(stamp):
    "UNIX timestamp (seconds) from Epics TimeStamp structure"
    return (EPICS2UNIX_EPOCH + stamp.secs + 1.e-6*int(1.e-3*stamp.nsec))

Problem one — that constant is wrong.  The correct value, as defined in <base>/include/epicsTime.h is: #define POSIX_TIME_AT_EPICS_EPOCH 631152000u
Problem two — what’s ‘time.timezone’ doing in there?   The unix time stamp is in UTC as is the EPICS time stamp.

Hmm, not sure how that happened. I probably did
  >>> time.mktime((1990,1,1,0,0,0,0,0,0))
631173600.0
which I probably thought returns UTC but actually returns local time, and then applied the correction, incorrectly assuming that the timezone was needed.   Of course, I've only tested on machines in CST, and there are no unit tests involving absolute values of timestamp.  Still, I'm a little surprise it wasn't noticed before!



I propose the following fix:
diff -u lib/dbr.py.orig lib/dbr.py
--- lib/dbr.py.orig 2014-05-12 16:37:58.000000000 -0700
+++ lib/dbr.py 2014-05-12 16:38:00.000000000 -0700
@@ -66,7 +66,7 @@
 MAX_ENUM_STRING_SIZE = 26
 MAX_ENUMS            = 16

 

-EPICS2UNIX_EPOCH = 631173600.0 - time.timezone
+EPICS2UNIX_EPOCH = 631152000.0

 

 # create_subscription mask constants
 DBE_VALUE = 1


Who’s maintaining the pyEpics stuff now?
-- 
Eric Norum
wenorum@lbl.gov


I've fixed this (and clarified the doc in the doc source code) on the github repo.

Sorry for the trouble.

Cheers,

--
--Matt Newville <newville at cars.uchicago.edu> 630-252-0431

References:
pyEpics time stamps Eric Norum
Re: pyEpics time stamps Eric Norum

Navigate by Date:
Prev: ssrlApps for devIocStats, etc Phillip Sorensen
Next: Re: ssrlApps for devIocStats, etc Till Straumann
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019 
Navigate by Thread:
Prev: Re: pyEpics time stamps Mark Rivers
Next: about CSS BOY 岳敏
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·