1 // Copyright 2010 Jochen Becher
3 // This file is part of MovieSchedule.
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // MovieSchedule is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with MovieSchedule. If not, see <http://www.gnu.org/licenses/>.
18 #include "timeutils.h"
20 TimeUtils::TimeUtils()
24 QTime TimeUtils::FromTimeString(const QString &time)
27 int n = time.length();
31 while (pos < n && time[pos].isDigit()) {
32 hours = 10 * hours + time[pos].digitValue();
36 if (m == 0 || pos >= n || time[pos] != ':') {
41 while (pos < n && time[pos].isDigit()) {
42 minutes = 10 * minutes + time[pos].digitValue();
50 QString s = time.mid(pos);
51 if (s.compare("pm", Qt::CaseInsensitive) == 0) {
55 } else if (s.compare("am", Qt::CaseInsensitive) == 0) {
61 // assume pm as default
66 return QTime(hours, minutes);
69 QString TimeUtils::ToTimeString(const QTime &time)
71 QString s = time.toString(Qt::SystemLocaleShortDate);
75 QString TimeUtils::ToDateString(const QDate &date)
78 if (date == QDate::currentDate()) {
79 date_name = QObject::tr("Today", "DayPainter");
80 } else if (date == QDate::currentDate().addDays(1)) {
81 date_name = QObject::tr("Tomorrow", "DayPainter");
83 date_name = date.toString("dddd");