~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to kalarm/cal/datetime.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  datetime.cpp  -  date/time with start-of-day time for date-only values 
3
 
 *  Program:  kalarm
4
 
 *  Copyright © 2003,2005-2007,2009,2010 by David Jarvie <djarvie@kde.org>
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License along
17
 
 *  with this program; if not, write to the Free Software Foundation, Inc.,
18
 
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 
 */
20
 
#include "datetime.h"
21
 
 
22
 
#include <kglobal.h>
23
 
#include <klocale.h>
24
 
 
25
 
 
26
 
QTime DateTime::mStartOfDay;
27
 
 
28
 
QTime DateTime::effectiveTime() const
29
 
{
30
 
    return mDateTime.isDateOnly() ? mStartOfDay : mDateTime.time();
31
 
}
32
 
 
33
 
QDateTime DateTime::effectiveDateTime() const
34
 
{
35
 
    if (mDateTime.isDateOnly())
36
 
    {
37
 
        QDateTime dt = mDateTime.dateTime();    // preserve Qt::UTC or Qt::LocalTime
38
 
        dt.setTime(mStartOfDay);
39
 
        return dt;
40
 
    }
41
 
    return mDateTime.dateTime();
42
 
}
43
 
 
44
 
KDateTime DateTime::effectiveKDateTime() const
45
 
{
46
 
    if (mDateTime.isDateOnly())
47
 
    {
48
 
        KDateTime dt = mDateTime;
49
 
        dt.setTime(mStartOfDay);
50
 
        return dt;
51
 
    }
52
 
    return mDateTime;
53
 
}
54
 
 
55
 
KDateTime DateTime::calendarKDateTime() const
56
 
{
57
 
    if (mDateTime.isDateOnly())
58
 
    {
59
 
        KDateTime dt = mDateTime;
60
 
        dt.setTime(QTime(0, 0));
61
 
        return dt;
62
 
    }
63
 
    return mDateTime;
64
 
}
65
 
 
66
 
QString DateTime::formatLocale(bool shortFormat) const
67
 
{
68
 
    return KGlobal::locale()->formatDateTime(mDateTime, (shortFormat ? KLocale::ShortDate : KLocale::LongDate));
69
 
}
70
 
 
71
 
bool operator<(const DateTime& dt1, const DateTime& dt2)
72
 
{
73
 
    if (dt1.isDateOnly()  &&  !dt2.isDateOnly())
74
 
    {
75
 
        KDateTime dt = dt1.mDateTime.addDays(1);
76
 
        dt.setTime(DateTime::mStartOfDay);
77
 
        return dt <= dt2.mDateTime;
78
 
    }
79
 
    if (!dt1.isDateOnly()  &&  dt2.isDateOnly())
80
 
    {
81
 
        KDateTime dt = dt2.mDateTime;
82
 
        dt.setTime(DateTime::mStartOfDay);
83
 
        return dt1.mDateTime < dt;
84
 
    }
85
 
    return dt1.mDateTime < dt2.mDateTime;
86
 
}
87
 
 
88
 
// vim: et sw=4: