KVIrc 5.2.4
Developer APIs
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
37class 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
54extern KVILIB_API void kvi_gettimeofday(struct timeval * tmv);
55#else
56#include <sys/time.h> // gettimeofday(), struct timeval
57
64inline void kvi_gettimeofday(struct timeval * tmv)
65{
66 gettimeofday(tmv, nullptr);
67}
68#endif
69
76{
77public:
79
80protected:
81 unsigned long m_uReferenceSecs;
82 unsigned long m_uReferenceUSecs;
83
84public:
91 unsigned long mark();
92
100 unsigned long secondsCounter() { return m_uReferenceSecs; };
101};
102
107namespace KviTimeUtils
108{
114
124 KVILIB_API void secondsToDaysHoursMinsSecs(unsigned int uSecs,
125 unsigned int * uD, unsigned int * uH, unsigned int * uM, unsigned int * uS);
126
134
141 KVILIB_API QString formatTimeInterval(unsigned int uSeconds, int iFlags = 0);
142}
143
144#endif //_KVI_TIME_H_
void kvi_gettimeofday(struct timeval *tmv)
Gets the time of the day.
Definition KviTimeUtils.h:64
A class to retrieve the time interval This works for time intervals a bit longer than 24 days.
Definition KviTimeUtils.h:76
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
unsigned long m_uReferenceUSecs
Definition KviTimeUtils.h:82
unsigned long m_uReferenceSecs
Definition KviTimeUtils.h:81
This file contains compile time settings.
#define KVILIB_API
Definition kvi_settings.h:124
Time utilities.
Definition KviTimeUtils.cpp:82
long long getCurrentTimeMills()
Returns the current time mills.
Definition KviTimeUtils.cpp:83
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:91
QString formatTimeInterval(unsigned int uSeconds, int iFlags)
Returns a string formatted like x d x h xx m xx s.
Definition KviTimeUtils.cpp:102
FormatTimeSpanFlags
Definition KviTimeUtils.h:129
@ FillWithHypens
Definition KviTimeUtils.h:132
@ NoLeadingEmptyIntervals
Definition KviTimeUtils.h:130
@ NoLeadingZeroes
Definition KviTimeUtils.h:131