Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvtimeutils.cc

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Various little time functions...
00006  */
00007 #include "wvtimeutils.h"
00008 
00009 #ifdef _WIN32
00010 int gettimeofday(struct timeval *tv, struct timezone *tz);
00011 #endif
00012 
00013 time_t msecdiff(const struct timeval &a, const struct timeval &b)
00014 {
00015     time_t secdiff = a.tv_sec - b.tv_sec;
00016     time_t usecdiff = a.tv_usec - b.tv_usec;
00017     return secdiff * 1000 + usecdiff / 1000;
00018 }
00019 
00020 
00021 struct timeval wvtime()
00022 {
00023     struct timeval tv;
00024     gettimeofday(&tv, 0);
00025     return tv;
00026 }
00027 
00028 
00029 struct timeval msecadd(const struct timeval &a, time_t msec)
00030 {
00031     struct timeval b;
00032     b.tv_sec = a.tv_sec + msec / 1000;
00033     b.tv_usec = a.tv_usec + (msec % 1000) * 1000;
00034     normalize(b);
00035     return b;
00036 }
00037 
00038 
00039 struct timeval tvdiff(const struct timeval &a,
00040                       const struct timeval &b)
00041 {
00042     struct timeval c;
00043     c.tv_sec = a.tv_sec - b.tv_sec;
00044     c.tv_usec = a.tv_usec;
00045 
00046     if (b.tv_usec > a.tv_usec)
00047     {
00048         c.tv_sec--;
00049         c.tv_usec += 1000000;
00050     }
00051 
00052     c.tv_usec -= b.tv_usec;
00053 
00054     normalize(c);
00055     return c;
00056 }
00057 

Generated on Sat Mar 13 14:56:00 2004 for WvStreams by doxygen 1.3.6-20040222