| 1 |
/* |
| 2 |
* Utility.h - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004 Chris Schlaeger <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of version 2 of the GNU General Public License as |
| 8 |
* published by the Free Software Foundation. |
| 9 |
* |
| 10 |
* $Id$ |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef _Utility_h_ |
| 14 |
#define _Utility_h_ |
| 15 |
|
| 16 |
#include <time.h> |
| 17 |
#include <QString> |
| 18 |
#include <QDateTime> |
| 19 |
|
| 20 |
namespace TJ |
| 21 |
{ |
| 22 |
|
| 23 |
const int MAXTIME = 0x7FFFFFFF; |
| 24 |
const int ONEDAY = 60 * 60 * 24; |
| 25 |
const int ONEHOUR = 60 * 60; |
| 26 |
|
| 27 |
void initUtility(long dizeSize); |
| 28 |
|
| 29 |
void exitUtility(); |
| 30 |
|
| 31 |
bool isRichText(const QString& str); |
| 32 |
|
| 33 |
bool setTimezone(const char* tz); |
| 34 |
|
| 35 |
const QString& getUtilityError(); |
| 36 |
|
| 37 |
const char* timezone2tz(const char* tzone); |
| 38 |
|
| 39 |
QString monthAndYear(time_t d); |
| 40 |
|
| 41 |
QString shortMonthName(int mon); |
| 42 |
|
| 43 |
int daysLeftInMonth(time_t d); |
| 44 |
|
| 45 |
int weeksLeftInMonth(time_t d); |
| 46 |
|
| 47 |
int monthLeftInYear(time_t d); |
| 48 |
|
| 49 |
int quartersLeftInYear(time_t d); |
| 50 |
|
| 51 |
int daysBetween(time_t t1, time_t t2); |
| 52 |
|
| 53 |
int weeksBetween(time_t t1, time_t t2); |
| 54 |
|
| 55 |
int monthsBetween(time_t t1, time_t t2); |
| 56 |
|
| 57 |
int quartersBetween(time_t t1, time_t t2); |
| 58 |
|
| 59 |
bool isWeekend(time_t d); |
| 60 |
|
| 61 |
time_t beginOfHour(time_t t); |
| 62 |
|
| 63 |
time_t midnight(time_t t); |
| 64 |
|
| 65 |
time_t beginOfWeek(time_t t, bool beginOnMonday); |
| 66 |
|
| 67 |
time_t beginOfMonth(time_t t); |
| 68 |
|
| 69 |
time_t beginOfQuarter(time_t t); |
| 70 |
|
| 71 |
time_t beginOfYear(time_t t); |
| 72 |
|
| 73 |
time_t hoursLater(int n, time_t t); |
| 74 |
|
| 75 |
time_t sameTimeNextDay(time_t t); |
| 76 |
|
| 77 |
time_t sameTimeYesterday(time_t t); |
| 78 |
|
| 79 |
time_t sameTimeNextWeek(time_t t); |
| 80 |
|
| 81 |
time_t sameTimeLastWeek(time_t t); |
| 82 |
|
| 83 |
time_t sameTimeNextQuarter(time_t t); |
| 84 |
|
| 85 |
time_t sameTimeNextMonth(time_t t); |
| 86 |
|
| 87 |
time_t sameTimeNextYear(time_t t); |
| 88 |
|
| 89 |
time_t sameTimeLastYear(time_t t); |
| 90 |
|
| 91 |
inline bool isSameDay(time_t d1, time_t d2) |
| 92 |
{ |
| 93 |
// TODO: make faster |
| 94 |
return midnight(d1) == midnight(d2); |
| 95 |
} |
| 96 |
|
| 97 |
inline bool isSameWeek(time_t d1, time_t d2, bool beginOnMonday) |
| 98 |
{ |
| 99 |
// TODO: make faster |
| 100 |
return beginOfWeek(d1, beginOnMonday) == beginOfWeek(d2, beginOnMonday); |
| 101 |
} |
| 102 |
|
| 103 |
inline bool isSameMonth(time_t d1, time_t d2) |
| 104 |
{ |
| 105 |
// TODO: make faster |
| 106 |
return beginOfMonth(d1) == beginOfMonth(d2); |
| 107 |
} |
| 108 |
|
| 109 |
inline bool isSameQuarter(time_t d1, time_t d2) |
| 110 |
{ |
| 111 |
// TODO: make faster |
| 112 |
return beginOfQuarter(d1) == beginOfQuarter(d2); |
| 113 |
} |
| 114 |
|
| 115 |
inline bool isSameYear(time_t d1, time_t d2) |
| 116 |
{ |
| 117 |
// TODO: make faster |
| 118 |
return beginOfYear(d1) == beginOfYear(d2); |
| 119 |
} |
| 120 |
|
| 121 |
int secondsOfDay(time_t d); |
| 122 |
|
| 123 |
int hourOfDay(time_t d); |
| 124 |
|
| 125 |
int dayOfMonth(time_t d); |
| 126 |
|
| 127 |
int dayOfYear(time_t d); |
| 128 |
|
| 129 |
int weekOfYear(time_t d, bool beginOnMonday); |
| 130 |
|
| 131 |
int monthOfWeek(time_t d, bool beginOnMonday); |
| 132 |
|
| 133 |
int monthOfYear(time_t d); |
| 134 |
|
| 135 |
int quarterOfYear(time_t d); |
| 136 |
|
| 137 |
int year(time_t d); |
| 138 |
|
| 139 |
int yearOfWeek(time_t d, bool beginOnMonday); |
| 140 |
|
| 141 |
int dayOfWeek(time_t d, bool beginOnMonday); |
| 142 |
|
| 143 |
QString dayOfWeekName(time_t d); |
| 144 |
|
| 145 |
QString time2ISO(time_t t); |
| 146 |
|
| 147 |
QString time2tjp(time_t t); |
| 148 |
|
| 149 |
QString time2user(time_t t, const QString& timeFormat, bool localtime = true); |
| 150 |
|
| 151 |
QString time2time(time_t t); |
| 152 |
|
| 153 |
QString time2date(time_t t); |
| 154 |
|
| 155 |
QString time2weekday(time_t t); |
| 156 |
|
| 157 |
time_t date2time(const QString&); |
| 158 |
|
| 159 |
time_t addTimeToDate(time_t day, time_t t); |
| 160 |
|
| 161 |
QString formatTime(time_t t); |
| 162 |
|
| 163 |
QDate time2qdate(time_t t); |
| 164 |
|
| 165 |
time_t qdate2time(const QDate& d); |
| 166 |
|
| 167 |
|
| 168 |
} // namespace TJ |
| 169 |
|
| 170 |
#endif |
| 171 |
|