2 /* $Id: timeval.cc 2 2003-01-07 16:59:16Z murrayc $ */
6 * Copyright (C) 2002 The gtkmm Development Team
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <glib/gmain.h>
25 #include <glib/gtimer.h>
27 #include <glibmm/timeval.h>
33 void TimeVal::assign_current_time()
35 g_get_current_time(this);
38 void TimeVal::add(const TimeVal& rhs)
40 g_return_if_fail(tv_usec >= 0 && tv_usec < G_USEC_PER_SEC);
41 g_return_if_fail(rhs.tv_usec >= 0 && rhs.tv_usec < G_USEC_PER_SEC);
43 tv_usec += rhs.tv_usec;
45 if(tv_usec >= G_USEC_PER_SEC)
47 tv_usec -= G_USEC_PER_SEC;
54 void TimeVal::subtract(const TimeVal& rhs)
56 g_return_if_fail(tv_usec >= 0 && tv_usec < G_USEC_PER_SEC);
57 g_return_if_fail(rhs.tv_usec >= 0 && rhs.tv_usec < G_USEC_PER_SEC);
59 tv_usec -= rhs.tv_usec;
63 tv_usec += G_USEC_PER_SEC;
70 void TimeVal::add_seconds(long seconds)
72 g_return_if_fail(tv_usec >= 0 && tv_usec < G_USEC_PER_SEC);
77 void TimeVal::subtract_seconds(long seconds)
79 g_return_if_fail(tv_usec >= 0 && tv_usec < G_USEC_PER_SEC);
84 void TimeVal::add_milliseconds(long milliseconds)
86 g_return_if_fail(tv_usec >= 0 && tv_usec < G_USEC_PER_SEC);
88 tv_usec += (milliseconds % 1000) * 1000;
92 tv_usec += G_USEC_PER_SEC;
95 else if(tv_usec >= G_USEC_PER_SEC)
97 tv_usec -= G_USEC_PER_SEC;
101 tv_sec += milliseconds / 1000;
104 void TimeVal::subtract_milliseconds(long milliseconds)
106 add_milliseconds(-1 * milliseconds);
109 void TimeVal::add_microseconds(long microseconds)
111 g_time_val_add(this, microseconds);
114 void TimeVal::subtract_microseconds(long microseconds)
116 g_time_val_add(this, -1 * microseconds);