2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Various little time functions...
9 #include "wvtimeutils.h"
11 time_t msecdiff(const WvTime
&a
, const WvTime
&b
)
13 long long secdiff
= a
.tv_sec
- b
.tv_sec
;
14 long long usecdiff
= a
.tv_usec
- b
.tv_usec
;
15 long long msecs
= secdiff
* 1000 + usecdiff
/ 1000;
20 else if (msecs
< INT_MIN
)
36 WvTime
msecadd(const WvTime
&a
, time_t msec
)
39 b
.tv_sec
= a
.tv_sec
+ msec
/ 1000;
40 b
.tv_usec
= a
.tv_usec
+ (msec
% 1000) * 1000;
46 WvTime
tvdiff(const WvTime
&a
, const WvTime
&b
)
49 c
.tv_sec
= a
.tv_sec
- b
.tv_sec
;
50 c
.tv_usec
= a
.tv_usec
;
52 if (b
.tv_usec
> a
.tv_usec
)
58 c
.tv_usec
-= b
.tv_usec
;
65 static WvTime wvstime_cur
= wvtime();
68 const WvTime
&wvstime()
74 static void do_wvstime_sync(bool forward_only
)
78 wvstime_cur
= wvtime();
82 WvTime now
= wvtime();
83 if (wvstime_cur
< now
)
91 do_wvstime_sync(false);
95 void wvstime_sync_forward()
97 do_wvstime_sync(true);
101 void wvstime_set(const WvTime
&_new_time
)
103 wvstime_cur
= _new_time
;