473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

time() sleep() and dst

Hi Ng,

i have some (maybe simple) questions.

1. Is it safe to sleep() while system time is adjusted?
2. Is it safe to sleep() while DST- State changes?

3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc *according to
the system clock *
whatever that may be. s I'd expect it not to jump.

4. In which cases will it change +-3600 sec.
Linux: TZ-Env-Variable,Ntpd,/etc/localtime symlink, Adjusting via date
Win32: Dialog System-Timezone / Adjust automatically
Oct 27 '06 #1
14 2101
reppisch <sp**@reppisch.dewrote:
1. Is it safe to sleep() while system time is adjusted?
2. Is it safe to sleep() while DST- State changes?
sleep() is not ISO C, so it's off-topic here.
3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc *according to
the system clock *
time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares.

I believe the questions you ask are pertinent to POSIX. If so, ask in
comp.unix.programmer - but do, please, at least read _their_ FAQ before
posting.

Richard
Oct 27 '06 #2
2006-10-27 <eh**********@online.de>,
reppisch wrote:
Hi Ng,

i have some (maybe simple) questions.
These are off-topic, but I'll answer anyway. My answers assume
a unix-like system and may have hidden assumptions based on my
experience.
1. Is it safe to sleep() while system time is adjusted?
No. If time is adjusted backward you may end up waiting even longer; if
it is adjusted forward you may end up waking up prematurely. I have had
this happen, but it may not be the case on all systems. I would not
characterize relying on either behavior as "safe" - the best solution is
to make sure that your system time is never off by more than a few
seconds
2. Is it safe to sleep() while DST- State changes?
Yes. System time is maintained in UTC on most modern systems, and DST
will not affect this.
3. Will time() returnvalues "jump"?
Only when system time is adjusted.
The man-page says it returnes seconds since 1970 in utc *according to
the system clock *
whatever that may be. s I'd expect it not to jump.

4. In which cases will it change +-3600 sec.
Linux: TZ-Env-Variable,Ntpd,/etc/localtime symlink, Adjusting via date
Adjusting via date, assuming you are adjusting by one hour, which would
be an odd thing to do. Ntpd will also change the system clock, but it
is, again, unlikely it will do so by one hour (NTP uses utc information
and therefore does not care about daylight savings)
Oct 27 '06 #3
2006-10-27 <45***************@news.xs4all.nl>,
Richard Bos wrote:
>3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc *according to
the system clock *

time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares
A question which _is_ relevant to ISO would be - if I call time() once
before daylight savings ends, and call it again an hour later, what will
difftime() return on those two values? Is it guaranteed to be 3600
[subject to time and floating point error]?
Oct 27 '06 #4
Jordan Abel wrote:
Richard Bos wrote:
>>3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc
*according to the system clock *

time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares

A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?
What does the phrase "seconds since 1970 in utc" tell you?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Oct 27 '06 #5
Jordan Abel wrote:
reppisch wrote:
>>
i have some (maybe simple) questions.

These are off-topic, but I'll answer anyway. My answers assume
a unix-like system and may have hidden assumptions based on my
experience.
Which you shouldn't, since erroneous answers will probably not be
corrected here. Just refer the OP to the appropriate newsgroup.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Oct 27 '06 #6

reppisch wrote:
Hi Ng,

i have some (maybe simple) questions.

1. Is it safe to sleep() while system time is adjusted?
2. Is it safe to sleep() while DST- State changes?

3. Will time() returnvalues "jump"?

This hasnt much to do with the C standard, which tries to ignore
real-time issues.

but anyway:

Your better OS's, and Unix, Linux, and Windows too, try to minimize the
damage when the time is asked to change suddenly. They often slowly
slew the time as to minimize the impact on programs that are expecting
time to go forward and at a constant rate.

On PC DOS, you'll see glitches around midnight where the time goes:

11:59:59 Jan 1
12:00:00 Jan 1
12:00:01 Jan 1
12:00:02 Jan 1
12:00:03 Jan 1
12:00:00 Jan 1
12:00:00 Jan 2
Oops...

Oct 27 '06 #7
2006-10-27 <45***************@yahoo.com>,
CBFalconer wrote:
Jordan Abel wrote:
>Richard Bos wrote:
>>>
time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares

A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?

What does the phrase "seconds since 1970 in utc" tell you?
That he's got a platform-specific assumption. However, the issue of
whether time()'s return value might "jump" (in terms of what time it
represents and how it will compare to representations taken at other
times) at the DST changeover does not depend on that assumption.

Yes or no, is it possible for the return values from time(), taken an
hour apart, to compare equal (or, if equality comparison is not
meaningful, for difftime() to return zero)?
Oct 27 '06 #8
CBFalconer wrote:
Jordan Abel wrote:
>Richard Bos wrote:
>>>3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc
*according to the system clock *
time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares
A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?

What does the phrase "seconds since 1970 in utc" tell you?
That it is referring to a specific implementation rather than what the
standard specifies. ;-)

The standard says that time() returns an approximation to calendar time
and difftime() returns the difference between two calendar times, so I
think that it is implicit that difftime should work as expected on times
straddling switches between daylight savings time (or summer time) and
standard time. I.e. in your example it would return an approximation of
3600 assuming neither call to time() returned (time_t)-1
--
Flash Gordon
Oct 27 '06 #9
2006-10-27 <g1************@news.flash-gordon.me.uk>,
Flash Gordon wrote:
CBFalconer wrote:
>Jordan Abel wrote:
>>Richard Bos wrote:

3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc
*according to the system clock *
time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares
A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?

What does the phrase "seconds since 1970 in utc" tell you?

That it is referring to a specific implementation rather than what the
standard specifies. ;-)

The standard says that time() returns an approximation to calendar time
and difftime() returns the difference between two calendar times, so I
think that it is implicit that difftime should work as expected on times
straddling switches between daylight savings time (or summer time) and
standard time. I.e. in your example it would return an approximation of
3600 assuming neither call to time() returned (time_t)-1
But is it required? and at this point we are going into pure
standards-hypothetical territory (might be more on-topic for comp.std.c,
not sure, since I _know_ what it will do on all platforms specifically
mentioned thus far, and on those it will return 3600[ish]).

And what's a "calendar time", anyway, my calendar only has dates.
If it's analogous to a calendar date - well... if I take the difference
between the calendar dates September 2 and September 14, the difference
is 12 days, even if the days immediately follow one another in _real_
time, as they did in 1752 in England and its colonies.
Oct 27 '06 #10
Jordan Abel wrote:
2006-10-27 <45***************@news.xs4all.nl>,
Richard Bos wrote:
>>>3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc *according to
the system clock *

time() is on-topic, but the only thing ISO C says of it is that it
returns _a_ representation of the time. Not which, not with which
precision, or anything else. Seconds since 1970 are by no means
guaranteed. time_t might be an unsigned long with the format
TTTSSMMHHDDMMYYYY, for all ISO C cares


A question which _is_ relevant to ISO would be - if I call time() once
before daylight savings ends, and call it again an hour later, what will
difftime() return on those two values? Is it guaranteed to be 3600
[subject to time and floating point error]?
No. time() returns "the implementation's best approximation
to the current calendar time" (7.24.2.3/3). There is no language
in the Standard to say how accurate that approximation must be or
how it is expressed. It might be considered unusual or even
perverse, but a time() that reported the logarithm of the number
of centifortnights since the most recent full Moon would (it seems
to me) meet all the requirements of the Standard.

In particular, there is no requirement that time_t be anchored
to any kind of "universal" clock. It's perfectly all right for
time() to report local statutory time, if that's what the system
provides.

--
Eric Sosman
es*****@acm-dot-org.invalid
Oct 28 '06 #11
>A question which _is_ relevant to ISO would be - if I call time()
>once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?

What does the phrase "seconds since 1970 in utc" tell you?
That someone is assuming a lot more than ISO C guarantees.
Oct 28 '06 #12
Gordon Burditt wrote:
>
>>A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?
>What does the phrase "seconds since 1970 in utc" tell you?

That someone is assuming a lot more than ISO C guarantees.
Yes, after posting that I checked the standard, and there is no
such phrase in it.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Oct 28 '06 #13
On Fri, 27 Oct 2006 12:55:10 -0400, CBFalconer <cb********@yahoo.com>
wrote:
Jordan Abel wrote:
Richard Bos wrote:
>3. Will time() returnvalues "jump"?
The man-page says it returnes seconds since 1970 in utc
*according to the system clock *
<snip>
A question which _is_ relevant to ISO would be - if I call time()
once before daylight savings ends, and call it again an hour later,
what will difftime() return on those two values? Is it guaranteed
to be 3600 [subject to time and floating point error]?

What does the phrase "seconds since 1970 in utc" tell you?
POSIX but not C specifies UTC which does of course ignore
daylight-savings aka summer changes. A more interesting question is
before and after a leap second; true UTC includes them, but my
understanding is POSIX is interpreted to exclude them.

Although, you may not get many more chances to test this in anger or
for it to make a difference; there is an apparently serious proposal
to do away with leap seconds and just let UTC and TAI diverge until it
gets up to minutes at least, which assuming no change in the Earth's
recently observed behavior means for centuries, by which time all of
us here will probably be dead and C likely forgotten.

- David.Thompson1 at worldnet.att.net
Nov 20 '06 #14
2006-11-20 <os********************************@4ax.com>,
Dave Thompson wrote:
On Fri, 27 Oct 2006 12:55:10 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>What does the phrase "seconds since 1970 in utc" tell you?

POSIX but not C specifies UTC which does of course ignore
daylight-savings aka summer changes. A more interesting question is
before and after a leap second; true UTC includes them, but my
understanding is POSIX is interpreted to exclude them.
"In UTC" is interpreted to mean that it's a number which has 1 added or
subtracted from it in the same way that the 'seconds' value of UTC does
whenever there's a leap second. "True UTC" does not "include" them in
the same sense that the alternative to the POSIX interpretation would;
that would be TAI.
Nov 20 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the...
0
by: Irmen de Jong | last post by:
Hi, when using the hotshot profiler, I can see no difference in the measurement of a function that is busy eating CPU cycles, and a function that is blocking/waiting on IO (or sleeping)... For...
5
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
1
by: Yin | last post by:
I am writing a script that monitors a child process. If the child process dies on its own, then the parent continues on. If the child process is still alive after a timeout period, the parent...
2
by: rbt | last post by:
I have a win32 service written in Python. It works well. It sends a report of the status of the machine via email periodically. The one problem I have is this... while trying to send an email, the...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
18
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.