Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KAlarm
Commits
e0954456
Commit
e0954456
authored
Oct 01, 2017
by
David Jarvie
Browse files
Fix conversion between QDateTime and KDateTime
parent
0a8f6a6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/kaevent.cpp
View file @
e0954456
...
...
@@ -5492,7 +5492,7 @@ bool KAEventPrivate::convertStartOfDay(const Event::Ptr &event)
const
KDateTime
oldDt
=
q2k
(
event
->
dtStart
());
const
int
adjustment
=
oldDt
.
time
().
secsTo
(
midnight
);
if
(
adjustment
)
{
event
->
setDtStart
(
Q
DateTime
(
oldDt
.
date
(),
midnight
,
specToZone
(
oldDt
.
timeSpec
())));
event
->
setDtStart
(
ktoq
(
K
DateTime
(
oldDt
.
date
(),
midnight
,
oldDt
.
timeSpec
())));
int
deferralOffset
=
0
;
AlarmMap
alarmMap
;
readAlarms
(
event
,
&
alarmMap
);
...
...
src/utils.cpp
View file @
e0954456
...
...
@@ -2,6 +2,7 @@
This file is part of the kalarmcal library.
Copyright (c) 2017 Daniel Vrátil <dvratil@kde.org>
Copyright (c) 2017 David Jarvie <djarvie@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
...
...
@@ -25,6 +26,25 @@
#include
<KSystemTimeZones>
#include
<QDebug>
KDateTime
::
Spec
KAlarmCal
::
kTimeSpec
(
const
QDateTime
&
dt
)
{
if
(
dt
.
isValid
())
{
switch
(
dt
.
timeSpec
())
{
case
Qt
::
LocalTime
:
return
KDateTime
::
LocalZone
;
case
Qt
::
UTC
:
return
KDateTime
::
UTC
;
case
Qt
::
OffsetFromUTC
:
return
KDateTime
::
Spec
(
KDateTime
::
OffsetFromUTC
,
dt
.
offsetFromUtc
());
case
Qt
::
TimeZone
:
return
KSystemTimeZones
::
zone
(
QString
::
fromLatin1
(
dt
.
timeZone
().
id
()));
default:
break
;
}
}
return
KDateTime
::
Invalid
;
}
KDateTime
::
Spec
KAlarmCal
::
zoneToSpec
(
const
QTimeZone
&
zone
)
{
if
(
!
zone
.
isValid
())
...
...
@@ -137,19 +157,36 @@ QTimeZone KAlarmCal::specToZone(const KDateTime::Spec &spec)
QDateTime
KAlarmCal
::
k2q
(
const
KDateTime
&
kdt
)
{
if
(
kdt
.
isValid
())
{
return
QDateTime
(
kdt
.
date
(),
kdt
.
time
(),
specToZone
(
kdt
.
timeSpec
()));
}
else
{
return
QDateTime
();
switch
(
kdt
.
timeType
())
{
case
KDateTime
::
LocalZone
:
case
KDateTime
::
ClockTime
:
return
QDateTime
(
kdt
.
date
(),
kdt
.
time
(),
Qt
::
LocalTime
);
case
KDateTime
::
UTC
:
return
QDateTime
(
kdt
.
date
(),
kdt
.
time
(),
Qt
::
UTC
);
case
KDateTime
::
OffsetFromUTC
:
return
QDateTime
(
kdt
.
date
(),
kdt
.
time
(),
Qt
::
OffsetFromUTC
,
kdt
.
timeSpec
().
utcOffset
());
case
KDateTime
::
TimeZone
:
{
auto
tz
=
QTimeZone
(
kdt
.
timeZone
().
name
().
toUtf8
());
if
(
!
tz
.
isValid
())
{
tz
=
resolveCustomTZ
(
kdt
.
timeZone
());
qDebug
()
<<
"Resolved"
<<
kdt
.
timeZone
().
name
()
<<
"to"
<<
tz
.
id
();
}
return
QDateTime
(
kdt
.
date
(),
kdt
.
time
(),
tz
);
}
case
KDateTime
::
Invalid
:
default:
break
;
}
}
return
QDateTime
();
}
KDateTime
KAlarmCal
::
q2k
(
const
QDateTime
&
qdt
,
bool
allDay
)
{
if
(
qdt
.
isValid
())
{
KDateTime
kdt
(
qdt
.
date
(),
qdt
.
time
(),
zoneTo
Spec
(
qdt
.
timeZone
()
));
KDateTime
kdt
(
qdt
.
date
(),
qdt
.
time
(),
kTime
Spec
(
qdt
));
kdt
.
setDateOnly
(
allDay
&&
qdt
.
time
()
==
QTime
(
0
,
0
,
0
));
return
kdt
;
}
else
{
return
KDateTime
();
}
return
KDateTime
();
}
src/utils.h
View file @
e0954456
...
...
@@ -2,6 +2,7 @@
This file is part of the kalarmcal library.
Copyright (c) 2017 Daniel Vrátil <dvratil@kde.org>
Copyright (c) 2017 David Jarvie <djarvie@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
...
...
@@ -30,14 +31,19 @@
namespace
KAlarmCal
{
/** Get the KDateTime::Spec for a QDateTime */
KALARMCAL_EXPORT
KDateTime
::
Spec
kTimeSpec
(
const
QDateTime
&
dt
);
/** Convert a QTimeZone to a KDateTime::Spec */
KALARMCAL_EXPORT
KDateTime
::
Spec
zoneToSpec
(
const
QTimeZone
&
zone
);
/** Convert a QTimeZone to a KDateTime::Spec */
KALARMCAL_EXPORT
QTimeZone
specToZone
(
const
KDateTime
::
Spec
&
spec
);
/** Convert KDateTime to QDateTime, correctly preserv
es
timespec */
/** Convert KDateTime to QDateTime, correctly preserv
ing
timespec */
KALARMCAL_EXPORT
QDateTime
k2q
(
const
KDateTime
&
kdt
);
/** Convert QDateTime to KDateTime, correctly preserving timespec */
KALARMCAL_EXPORT
KDateTime
q2k
(
const
QDateTime
&
qdt
,
bool
isAllDay
=
false
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment