Experimental Physics and Industrial Control System
|
Not too fast:
epicsTimeToGMTM
converts timestamp to UTC broken-down time. tm_isdst is already
zero since UTC has no DST.
Next:
epicsTimeFromTM()
converts a broken-down time back to a timestamp. It needs timezone
information
to know how to do the conversion (uses 'mktime' internally). The
conversion depends
on the timezone and DST where the broken-down time is interpreted.
Note that epicsTimeToStrftime again converts the timestamp to
broken-down
format internally; this time using 'localtime' - which also uses
timezone information.
You want the epicsTimeFromTM() and epicsTimeToStrftime from- and
(implicit) to-TM
conversions to cancel so that you display your UTC.
What went wrong? epicsTimeToGMTM() returns a tm with 'tm_dst==0'.
This is what you feed to epicsTimeFromTM(). However, the implicit
localtime()
operation uses the DST setting of the current timezone, which
right now
is probably 1.
In order to make this work you should set it to a negative value
epicsTimeToGMTM(&tm, &nsec, ×tamp);
tm.tm_isdst = -1; /* determine value from current timezone and
timestamp */
epicsTimeFromTM(&utc, &tm, 0);
/* Note that the 'utc' timestamp is not truly representing the
time 'tm' in UTC
but 'tm' interpreted as the local time. It is only the
subsequent, implicit
conversion of the timestamp back to a 'tm' (again in the local
timezone)
which renders a representation of UTC again in the guts of
epicsTimeToStrftime() -- ugly */
I recommend testing with various settings of the "TZ" environment
variable
to make sure you got it right.
Lesson learned:
epicsTimeFromTM() and epicsTimeToStrftime() both convert using
the local timezone.
HTH
- Till
On 04/16/2013 03:02 PM, Eric Norum wrote:
Good idea, but doesn't seem to help:
timestamp.secPastEpoch = 1366124582 -
POSIX_TIME_AT_EPICS_EPOCH;
timestamp.nsec = 0;
epicsTimeToGMTM(&tm, &nsec, ×tamp);
tm.tm_isdst = 0;
epicsTimeFromTM(&utc, &tm, 0);
epicsTimeToStrftime(cbuf, sizeof cbuf, "%F_%H:%M:%S",
&utc);
printf("%s\n", cbuf);
produces
2013-04-16_16:03:02
But
Tue Apr 16 15:03:02 UTC 2013
Hi Eric,
Perhaps force the isdst flag to 0 in between calls:
epicsTimeToGMTM(&tm, &nsec,
×tamp);
tm.tm_isdst = 0;
epicsTimeFromTM(&utc, &tm,
0);
|
- References:
- EPICS UTC Time conversion Eric Norum
- RE: EPICS UTC Time conversion Allison, Stephanie
- Re: EPICS UTC Time conversion Eric Norum
- Navigate by Date:
- Prev:
Re: EPICS UTC Time conversion Andrew Johnson
- Next:
Re: EPICS UTC Time conversion Eric Norum
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
<2013>
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: EPICS UTC Time conversion Eric Norum
- Next:
Check Box widget in CSS BOY Hovanes Egiyan
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
<2013>
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|
ANJ, 20 Apr 2015 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
·
Search
·
EPICS V4
·
IRMIS
·
Talk
·
Bugs
·
Documents
·
Links
·
Licensing
·
|