konsolekalendar Library API Documentation

konsolekalendarepoch.cpp

00001 /******************************************************************************* 00002 * konsolekalendarepoch.cpp * 00003 * * 00004 * KonsoleKalendar is a command line interface to KDE calendars * 00005 * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * 00006 * Copyright (C) 2003-2004 Allen Winter <awinterz@users.sourceforge.net> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * As a special exception, permission is given to link this program * 00023 * with any edition of Qt, and distribute the resulting executable, * 00024 * without including the source code for Qt in the source distribution. * 00025 * * 00026 ******************************************************************************/ 00027 00028 #include <stdlib.h> 00029 #include <iostream> 00030 00031 #include <qdatetime.h> 00032 #include "konsolekalendarepoch.h" 00033 00034 using namespace KCal; 00035 using namespace std; 00036 00037 KonsoleKalendarEpoch::KonsoleKalendarEpoch( ) 00038 { 00039 } 00040 00041 KonsoleKalendarEpoch::~KonsoleKalendarEpoch() 00042 { 00043 } 00044 00045 // By "epoch" we mean the number of seconds since 00:00:00 UTC on January 1 1970 00046 00047 // Function to convert an epoch value into a QDateTime 00048 QDateTime KonsoleKalendarEpoch::epoch2QDateTime( uint epoch ) 00049 { 00050 QDateTime dt; 00051 dt.setTime_t (epoch,Qt::UTC); 00052 return (dt); 00053 } 00054 00055 // Function to convert a QDateTime value into an epoch 00056 uint KonsoleKalendarEpoch::QDateTime2epoch( QDateTime dt ) 00057 { 00058 // THIS FUNCTION CAN BE OFF BY 1 HOUR DUE TO DAYLIGHT SAVINGS TIME. 00059 // SORRY QT DOESN'T HANDLE DAYLIGHT SAVINGS TIME. 00060 00061 // Compute #seconds to subtract for local timezone difference from UTC. 00062 int offset = QDateTime::currentDateTime(Qt::UTC).toTime_t() 00063 - QDateTime::currentDateTime(Qt::LocalTime).toTime_t(); 00064 return(dt.toTime_t()-offset); 00065 } 00066 00067 #if defined (TEST) 00068 // Pass -DTEST to the compile command to create the test program, e.g: 00069 // cc -DTEST -I/usr/local/KDE/include konsolekalendarepoch.cpp 00070 // -L/usr/local/KDE/lib -lqt-mt -pthread 00071 main() 00072 { 00073 uint epoch; 00074 QDateTime dt; 00075 00076 cout << endl; 00077 cout << "NOTE: Some tests may be off by 1 hour (3600 secs) " 00078 << "due to daylight savings time" 00079 << endl << endl; 00080 00081 // Test1 00082 epoch=0; 00083 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch); 00084 cout << "TEST 1:" << endl; 00085 cout << "epoch=" 00086 << epoch 00087 << " converts to " 00088 << dt.toString(Qt::TextDate) 00089 << endl; 00090 00091 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt); 00092 cout << "date=" 00093 << dt.toString(Qt::TextDate) 00094 << " converts to " 00095 << "epoch=" 00096 << epoch 00097 << endl; 00098 00099 // Test2 00100 epoch=100000; 00101 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch); 00102 cout << "TEST 2:" << endl; 00103 cout << "epoch=" 00104 << epoch 00105 << " converts to " 00106 << dt.toString(Qt::TextDate) 00107 << endl; 00108 00109 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt); 00110 cout << "date=" 00111 << dt.toString(Qt::TextDate) 00112 << " converts to " 00113 << "epoch=" 00114 << epoch 00115 << endl; 00116 00117 // Test3 00118 epoch=10000000; 00119 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch); 00120 cout << "TEST 3:" << endl; 00121 cout << "epoch=" 00122 << epoch 00123 << " converts to " 00124 << dt.toString(Qt::TextDate) 00125 << endl; 00126 00127 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt); 00128 cout << "date=" 00129 << dt.toString(Qt::TextDate) 00130 << " converts to " 00131 << "epoch=" 00132 << epoch 00133 << endl; 00134 00135 // Test4 00136 epoch=1000000000; 00137 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch); 00138 cout << "TEST 4:" << endl; 00139 cout << "epoch=" 00140 << epoch 00141 << " converts to " 00142 << dt.toString(Qt::TextDate) 00143 << endl; 00144 00145 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt); 00146 cout << "date=" 00147 << dt.toString(Qt::TextDate) 00148 << " converts to " 00149 << "epoch=" 00150 << epoch 00151 << endl; 00152 00153 // Test5 00154 epoch=10000000000; 00155 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch); 00156 cout << "TEST 5:" << endl; 00157 cout << "epoch=" 00158 << epoch 00159 << " converts to " 00160 << dt.toString(Qt::TextDate) 00161 << endl; 00162 00163 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt); 00164 cout << "date=" 00165 << dt.toString(Qt::TextDate) 00166 << " converts to " 00167 << "epoch=" 00168 << epoch 00169 << endl; 00170 } 00171 #endif
KDE Logo
This file is part of the documentation for konsolekalendar Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:34 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003