About time functions and daylight savings

Discussion in 'C Programming' started by DiAvOl, Nov 8, 2007.

  1. DiAvOl

    DiAvOl Guest

    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
    DiAvOl, Nov 8, 2007
    #1
    1. Advertising

  2. DiAvOl wrote:
    >
    > 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:>
    Kenneth Brody, Nov 8, 2007
    #2
    1. Advertising

  3. DiAvOl <> writes:

    > 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.

    --
    Ben.
    Ben Bacarisse, Nov 8, 2007
    #3
  4. DiAvOl

    Guest

    DiAvOl <> wrote:
    >
    > 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
    , Nov 8, 2007
    #4
  5. DiAvOl

    Tor Rustad Guest

    DiAvOl wrote:
    > 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()

    --
    Tor < | tr i-za-h a-z>
    Tor Rustad, Nov 8, 2007
    #5
  6. DiAvOl

    Guest

    Tor Rustad wrote:
    > DiAvOl wrote:
    > > 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 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.
    , Nov 9, 2007
    #6
  7. DiAvOl

    Tor Rustad Guest

    wrote:
    > Tor Rustad wrote:
    >> DiAvOl wrote:
    >>> 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 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.

    --
    Tor < | tr i-za-h a-z>
    Tor Rustad, Nov 9, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    1
    Views:
    1,461
    Ryan Ternier
    Oct 14, 2005
  2. Polaris431
    Replies:
    4
    Views:
    483
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    May 28, 2007
  3. Generic Usenet Account
    Replies:
    6
    Views:
    341
    Tim Slattery
    Jul 23, 2007
  4. Generic Usenet Account

    Handling daylight savings with standard time functions?

    Generic Usenet Account, Jul 20, 2007, in forum: C Programming
    Replies:
    6
    Views:
    581
    Tim Slattery
    Jul 23, 2007
  5. Washington Ratso
    Replies:
    1
    Views:
    50
    Chris “Kwpolska†Warrick
    Apr 3, 2014
Loading...

Share This Page