KCalUtils

datetimefilters.cpp
1 /*
2  * SPDX-FileCopyrightText: 2015 Daniel Vr├ítil <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "datetimefilters.h"
9 #include "../incidenceformatter.h"
10 
11 #include <grantlee/safestring.h>
12 
13 KDateFilter::KDateFilter()
14  : Grantlee::Filter()
15 {
16 }
17 
18 KDateFilter::~KDateFilter()
19 {
20 }
21 
22 QVariant KDateFilter::doFilter(const QVariant &input, const QVariant &argument, bool autoescape) const
23 {
24  Q_UNUSED(autoescape);
25 
26  QDate date;
27  if (input.type() == QVariant::Date) {
28  date = input.toDate();
29  } else if (input.type() == QVariant::DateTime) {
30  date = input.toDateTime().date();
31  } else {
32  return QString();
33  }
34 
35  const bool shortFmt = (argument.value<Grantlee::SafeString>().get().compare(QLatin1String("short"), Qt::CaseInsensitive) == 0);
36  return Grantlee::SafeString(KCalUtils::IncidenceFormatter::dateToString(date, shortFmt));
37 }
38 
39 bool KDateFilter::isSafe() const
40 {
41  return true;
42 }
43 
44 KTimeFilter::KTimeFilter()
45  : Grantlee::Filter()
46 {
47 }
48 
49 KTimeFilter::~KTimeFilter()
50 {
51 }
52 
53 QVariant KTimeFilter::doFilter(const QVariant &input, const QVariant &argument, bool autoescape) const
54 {
55  Q_UNUSED(autoescape);
56 
57  QTime time;
58  if (input.type() == QVariant::Time) {
59  time = input.toTime();
60  } else if (input.type() == QVariant::DateTime) {
61  time = input.toDateTime().time();
62  } else {
63  return QString();
64  }
65 
66  const bool shortFmt = (argument.value<Grantlee::SafeString>().get().compare(QLatin1String("short"), Qt::CaseInsensitive) == 0);
67 
68  return Grantlee::SafeString(KCalUtils::IncidenceFormatter::timeToString(time, shortFmt));
69 }
70 
71 bool KTimeFilter::isSafe() const
72 {
73  return true;
74 }
75 
76 KDateTimeFilter::KDateTimeFilter()
77  : Grantlee::Filter()
78 {
79 }
80 
81 KDateTimeFilter::~KDateTimeFilter()
82 {
83 }
84 
85 QVariant KDateTimeFilter::doFilter(const QVariant &input, const QVariant &argument, bool autoescape) const
86 {
87  Q_UNUSED(autoescape);
88 
89  if (input.type() != QVariant::DateTime) {
90  return QString();
91  }
92  const QDateTime dt = input.toDateTime();
93 
94  const QStringList arguments = argument.value<Grantlee::SafeString>().get().split(QLatin1Char(','));
95  const bool shortFmt = arguments.contains(QLatin1String("short"), Qt::CaseInsensitive);
96  const bool dateOnly = arguments.contains(QLatin1String("dateonly"), Qt::CaseInsensitive);
97 
98  return Grantlee::SafeString(KCalUtils::IncidenceFormatter::dateTimeToString(dt, dateOnly, shortFmt));
99 }
100 
101 bool KDateTimeFilter::isSafe() const
102 {
103  return true;
104 }
QDateTime toDateTime() const const
QTime toTime() const const
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
T value() const const
QTime time() const const
KCALUTILS_EXPORT QString timeToString(const QTime &time, bool shortfmt=true)
Build a QString time representation of a QTime object.
CaseInsensitive
KCALUTILS_EXPORT QString dateTimeToString(const QDateTime &date, bool dateOnly=false, bool shortfmt=true)
Build a QString date/time representation of a QDateTime object.
QDate toDate() const const
QDate date() const const
QVariant::Type type() const const
KCALUTILS_EXPORT QString dateToString(const QDate &date, bool shortfmt=true)
Build a QString date representation of a QDate object.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 23:17:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.