• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

KonsoleKalendar

  • sources
  • kde-4.12
  • kdepim
  • console
  • konsolekalendar
konsolekalendarepoch.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * konsolekalendarepoch.cpp *
3  * *
4  * KonsoleKalendar is a command line interface to KDE calendars *
5  * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> *
6  * Copyright (C) 2003-2005 Allen Winter <winter@kde.org> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21  * *
22  * As a special exception, permission is given to link this program *
23  * with any edition of Qt, and distribute the resulting executable, *
24  * without including the source code for Qt in the source distribution. *
25  * *
26  ******************************************************************************/
33 #include "konsolekalendarepoch.h"
34 
35 #include <stdlib.h>
36 #include <iostream>
37 
38 #include <QtCore/QDateTime>
39 using namespace std;
40 
41 KonsoleKalendarEpoch::KonsoleKalendarEpoch()
42 {
43 }
44 
45 KonsoleKalendarEpoch::~KonsoleKalendarEpoch()
46 {
47 }
48 
49 // By "epoch" we mean the number of seconds since 00:00:00 UTC on January 1 1970
50 
51 // Function to convert an epoch value into a QDateTime
52 QDateTime KonsoleKalendarEpoch::epoch2QDateTime( uint epoch )
53 {
54  QDateTime dt;
55  dt.setTime_t( epoch );
56  return dt;
57 }
58 
59 // Function to convert a QDateTime value into an epoch
60 uint KonsoleKalendarEpoch::QDateTime2epoch( const QDateTime &dt )
61 {
62  // THIS FUNCTION CAN BE OFF BY 1 HOUR DUE TO DAYLIGHT SAVINGS TIME.
63  // SORRY QT DOESN'T HANDLE DAYLIGHT SAVINGS TIME.
64 
65  // Compute #seconds to subtract for local timezone difference from UTC.
66  int offset = QDateTime::currentDateTime().toUTC().toTime_t() -
67  QDateTime::currentDateTime().toTime_t();
68  return dt.toTime_t() - offset;
69 }
70 
71 #if defined (TEST)
72 // Pass -DTEST to the compile command to create the test program, e.g:
73 // cc -DTEST -I/usr/local/KDE/include konsolekalendarepoch.cpp
74 // -L/usr/local/KDE/lib -lqt-mt -pthread
75 main()
76 {
77  uint epoch;
78  QDateTime dt;
79 
80  cout << endl;
81  cout << "NOTE: Some tests may be off by 1 hour (3600 secs) "
82  << "due to daylight savings time"
83  << endl << endl;
84 
85  // Test1
86  epoch = 0;
87  dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch );
88  cout << "TEST 1:" << endl;
89  cout << "epoch="
90  << epoch
91  << " converts to "
92  << dt.toString( Qt::TextDate )
93  << endl;
94 
95  epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt );
96  cout << "date="
97  << dt.toString( Qt::TextDate )
98  << " converts to "
99  << "epoch="
100  << epoch
101  << endl;
102 
103  // Test2
104  epoch = 100000;
105  dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch );
106  cout << "TEST 2:" << endl;
107  cout << "epoch="
108  << epoch
109  << " converts to "
110  << dt.toString( Qt::TextDate )
111  << endl;
112 
113  epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt );
114  cout << "date="
115  << dt.toString( Qt::TextDate )
116  << " converts to "
117  << "epoch="
118  << epoch
119  << endl;
120 
121  // Test3
122  epoch = 10000000;
123  dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch );
124  cout << "TEST 3:" << endl;
125  cout << "epoch="
126  << epoch
127  << " converts to "
128  << dt.toString( Qt::TextDate )
129  << endl;
130 
131  epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt );
132  cout << "date="
133  << dt.toString( Qt::TextDate )
134  << " converts to "
135  << "epoch="
136  << epoch
137  << endl;
138 
139  // Test4
140  epoch = 1000000000;
141  dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch );
142  cout << "TEST 4:" << endl;
143  cout << "epoch="
144  << epoch
145  << " converts to "
146  << dt.toString( Qt::TextDate )
147  << endl;
148 
149  epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt );
150  cout << "date="
151  << dt.toString( Qt::TextDate )
152  << " converts to "
153  << "epoch="
154  << epoch
155  << endl;
156 
157  // Test5
158  epoch = 10000000000;
159  dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch );
160  cout << "TEST 5:" << endl;
161  cout << "epoch="
162  << epoch
163  << " converts to "
164  << dt.toString( Qt::TextDate )
165  << endl;
166 
167  epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt );
168  cout << "date="
169  << dt.toString( Qt::TextDate )
170  << " converts to "
171  << "epoch="
172  << epoch
173  << endl;
174 }
175 #endif
KonsoleKalendarEpoch::QDateTime2epoch
static uint QDateTime2epoch(const QDateTime &dt)
Converts QT DateTime to epoch format.
Definition: konsolekalendarepoch.cpp:60
KonsoleKalendarEpoch::KonsoleKalendarEpoch
KonsoleKalendarEpoch()
Constructor.
Definition: konsolekalendarepoch.cpp:41
KonsoleKalendarEpoch::~KonsoleKalendarEpoch
~KonsoleKalendarEpoch()
Destructor.
Definition: konsolekalendarepoch.cpp:45
konsolekalendarepoch.h
Provides the KonsoleKalendarEpoch class definition.
KonsoleKalendarEpoch::epoch2QDateTime
static QDateTime epoch2QDateTime(uint epoch)
Converts epoch time to QDateTime format.
Definition: konsolekalendarepoch.cpp:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KonsoleKalendar

Skip menu "KonsoleKalendar"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal