KVIrc  4.9.2
DeveloperAPIs
KviTimeUtils.h
Go to the documentation of this file.
1 #ifndef _KVI_TIME_H_
2 #define _KVI_TIME_H_
3 //=============================================================================
4 //
5 // File : KviTimeUtils.h
6 // Creation date : Tue Sep 25 17:28:46 2001 GMT by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
33 #include "kvi_settings.h"
34 
35 #include <time.h> // for time()
36 
37 class QString;
38 
39 #define kvi_unixTime() time(0)
40 #define kvi_timeSpan(_time_now, _time_before) ((_time_now) - (_time_before))
41 #define kvi_secondsSince(_that_time_t) kvi_timeSpan(kvi_unixTime(), _that_time_t)
42 
43 #define kvi_time_t time_t
44 
45 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
46 #include <winsock2.h> // struct timeval
47 
54 extern KVILIB_API void kvi_gettimeofday(struct timeval * tmv, struct timezone * tmz);
55 #else
56 #include <sys/time.h> // gettimeofday(), struct timeval
57 
64 inline void kvi_gettimeofday(struct timeval * tmv, struct timezone * tmz)
65 {
66  gettimeofday(tmv, tmz);
67 }
68 #endif
69 
76 {
77 public:
79 
80 protected:
81  unsigned long m_uReferenceSecs;
82  unsigned long m_uReferenceUSecs;
83 
84 public:
91  unsigned long mark();
92 
100  unsigned long secondsCounter() { return m_uReferenceSecs; };
101 };
102 
107 namespace KviTimeUtils
108 {
113  KVILIB_API long long getCurrentTimeMills();
114 
124  KVILIB_API void secondsToDaysHoursMinsSecs(unsigned int uSecs,
125  unsigned int * uD, unsigned int * uH, unsigned int * uM, unsigned int * uS);
126 
129  {
133  };
134 
141  KVILIB_API QString formatTimeInterval(unsigned int uSeconds, int iFlags = 0);
142 }
143 
144 #endif //_KVI_TIME_H_
Definition: KviTimeUtils.h:130
unsigned long m_uReferenceSecs
Definition: KviTimeUtils.h:81
A class to retrieve the time interval This works for time intervals a bit longer than 24 days...
Definition: KviTimeUtils.h:75
long long getCurrentTimeMills()
Returns the current time mills.
Definition: KviTimeUtils.cpp:81
unsigned long m_uReferenceUSecs
Definition: KviTimeUtils.h:82
FormatTimeSpanFlags
Definition: KviTimeUtils.h:128
unsigned long secondsCounter()
Returns the number of seconds This wors ONLY in the same second that mark was called in and returns t...
Definition: KviTimeUtils.h:100
QString formatTimeInterval(unsigned int uSeconds, int iFlags)
Returns a string formatted like x d x h xx m xx s.
Definition: KviTimeUtils.cpp:100
Definition: KviTimeUtils.h:132
This file contains compile time settings.
void kvi_gettimeofday(struct timeval *tmv, struct timezone *tmz)
Gets the time of the day.
Definition: KviTimeUtils.h:64
void secondsToDaysHoursMinsSecs(unsigned int uSecs, unsigned int *uD, unsigned int *uH, unsigned int *uM, unsigned int *uS)
Splits the time span uSecs in days, hours, minutes and seconds.
Definition: KviTimeUtils.cpp:89
#define KVILIB_API
Definition: kvi_settings.h:125
Definition: KviTimeUtils.h:131