About time functions and daylight savings

D

DiAvOl

Hello everyone,

I am implementing a cybercafe software which keeps track of how much
time a client "stays" at the pc in order to charge him accordingly.
Which function should I use to mark a client's start time/end time
without accounting the daylight saving? For example a situation I want
to avoid is when the time goes one hour forward or backard when the
client is on a pc. The server should not account those time changes,
in order to charge the client correctly.

Thanks for your help & time.
Sorry for my bad english

Charalampos
 
K

Kenneth Brody

DiAvOl said:
Hello everyone,

I am implementing a cybercafe software which keeps track of how much
time a client "stays" at the pc in order to charge him accordingly.
Which function should I use to mark a client's start time/end time
without accounting the daylight saving? For example a situation I want
to avoid is when the time goes one hour forward or backard when the
client is on a pc. The server should not account those time changes,
in order to charge the client correctly.

Check out time() and difftime(). If you call time() two minutes
before DST ends, and again 2 minutes after DST ends, I believe that
difftime() will return 240.0 (ie: 4 minutes), despite the fact that
the clock has gone backwards 56 minutes.

Unfortunately, my documentation isn't clear (at least to me) as to
whether or not this will function as expected when crossing a DST
boundary.

n1124 seems to imply that this should work.

7.23.2.4p2

The time function determines the current calendar time.

7.23.1p1

Many functions deal with a calendar time that represents the
current date (according to the Gregorian calendar) and time.
Some functions deal with local time, which is the calendar
time expressed for some specific time zone, and with Daylight
Saving Time, which is a temporary change in the algorithm for
determining local time.

To me, this says that time() returns a "time" that is unrelated to
your current timezone or DST, and that changing DST won't affect
the value returned. ie: even though my clock might say 5:00PM and
yours might say 8:00PM, time() will return the same value for both
of us for a given implementation if time().

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
B

Ben Bacarisse

DiAvOl said:
I am implementing a cybercafe software which keeps track of how much
time a client "stays" at the pc in order to charge him accordingly.
Which function should I use to mark a client's start time/end time
without accounting the daylight saving? For example a situation I want
to avoid is when the time goes one hour forward or backard when the
client is on a pc. The server should not account those time changes,
in order to charge the client correctly.

You should read up on time and difftime. That will give you a
portable solution in standard C.
 
L

lawrence.jones

DiAvOl said:
Which function should I use to mark a client's start time/end time
without accounting the daylight saving?

Look at time(), difftime(), and gmtime().

-Larry Jones

Geez, I gotta have a REASON for everything? -- Calvin
 
T

Tor Rustad

DiAvOl said:
Hello everyone,

I am implementing a cybercafe software which keeps track of how much
time a client "stays" at the pc in order to charge him accordingly.

In my country, we switch daylight saving on Sundays, 02:00 and 03:00. No
cybercafe's here would be open at this time, are you sure this is a
relevant problem?
Which function should I use to mark a client's start time/end time
without accounting the daylight saving?
time()

For example a situation I want
to avoid is when the time goes one hour forward or backard when the
client is on a pc. The server should not account those time changes,
in order to charge the client correctly.

difftime()
 
J

jameskuyper

Tor said:
In my country, we switch daylight saving on Sundays, 02:00 and 03:00. No
cybercafe's here would be open at this time, are you sure this is a
relevant problem?

Which country is that? I don't know where DiAvOl is posting from, but
in the US in most major cities you can find a few places that are open
24 (or in this case, 25) hours a day. I gather that it's even easier
to find such places in the densely populated parts of the Pacific Rim,
and in many European cities as well.
 
T

Tor Rustad

Which country is that?

Not many places here are open for service 24h. It's a small, but a
rather wealthy country. I live practically next door to "Mozart of
chess" (GM Carlsen).
I don't know where DiAvOl is posting from, but
in the US in most major cities you can find a few places that are open
24 (or in this case, 25) hours a day.

Everything is big in US. :) Once a year, only 23h though.
I gather that it's even easier
to find such places in the densely populated parts of the Pacific Rim,
and in many European cities as well.

The other day, I helped someone getting their laptop working, had no
less than 9 private wireless networks to choose from.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top