00001 /* 00002 * Copyright (C) 2008,2009 Nokia Corporation. 00003 * 00004 * Contact: Marius Vollmer <marius.vollmer@nokia.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * version 2.1 as published by the Free Software Foundation. 00009 * 00010 * This library is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00018 * 02110-1301 USA 00019 * 00020 */ 00021 00022 #ifndef DURATION_H 00023 #define DURATION_H 00024 00025 #include <QString> 00026 #include <QtCore/QMetaType> 00027 00028 class Duration 00029 { 00030 00031 public: 00032 Duration(); 00033 Duration(quint64 nanoSecs); 00034 Duration(const QString &duration); 00035 00036 int nanoSecs() const; 00037 int seconds() const; 00038 int minutes() const; 00039 int hours() const; 00040 int days() const; 00041 int weeks() const; 00042 int years() const; 00043 QString toString() const; 00044 quint64 toNanoSeconds() const; 00045 bool operator==(const Duration &other) const; 00046 00047 static bool isDuration(const QString &duration); 00048 static const qint64 NANOSECS_PER_MSEC = Q_INT64_C(1000000); 00049 static const qint64 NANOSECS_PER_SEC = 1000*NANOSECS_PER_MSEC; 00050 static const qint64 NANOSECS_PER_MIN = 60*NANOSECS_PER_SEC; 00051 static const qint64 NANOSECS_PER_HOUR = 60*NANOSECS_PER_MIN; 00052 static const qint64 NANOSECS_PER_DAY = 24*NANOSECS_PER_HOUR; 00053 static const qint64 NANOSECS_PER_WEEK = 7*NANOSECS_PER_DAY; 00054 static const qint64 SECS_PER_DAY = Q_INT64_C(86400); 00055 static const qint64 MSECS_PER_DAY = 1000*SECS_PER_DAY; 00056 static const qint64 DAYS_PER_YEAR = 365; 00057 static const qint64 DAYS_PER_WEEK = 7; 00058 00059 private: 00060 quint64 totalNanoSecs_p; 00061 int nanoSecs_p; 00062 int seconds_p; 00063 int minutes_p; 00064 int hours_p; 00065 int days_p; 00066 int weeks_p; 00067 int years_p; 00068 00069 }; 00070 Q_DECLARE_METATYPE(Duration) 00071 #endif