konsolekalendarepoch.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <iostream>
00020
00021 #include <qdatetime.h>
00022 #include "konsolekalendarepoch.h"
00023
00024 using namespace KCal;
00025 using namespace std;
00026
00027 KonsoleKalendarEpoch::KonsoleKalendarEpoch( )
00028 {
00029 }
00030
00031 KonsoleKalendarEpoch::~KonsoleKalendarEpoch()
00032 {
00033 }
00034
00035
00036
00037
00038
00039 QDateTime KonsoleKalendarEpoch::epoch2QDateTime( uint epoch )
00040 {
00041 QDateTime dt;
00042 dt.setTime_t (epoch,Qt::UTC);
00043 return (dt);
00044 }
00045
00046
00047 uint KonsoleKalendarEpoch::QDateTime2epoch( QDateTime dt )
00048 {
00049
00050
00051
00052
00053 int offset = QDateTime::currentDateTime(Qt::UTC).toTime_t()
00054 - QDateTime::currentDateTime(Qt::LocalTime).toTime_t();
00055 return(dt.toTime_t()-offset);
00056 }
00057
00058 #if defined (TEST)
00059
00060
00061 main()
00062 {
00063 uint epoch;
00064 QDateTime dt;
00065
00066 cout << endl;
00067 cout << "NOTE: Some tests may be off by 1 hour (3600 secs) due to daylight savings time" << endl;
00068 cout << endl;
00069
00070
00071 epoch=0;
00072 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch);
00073 cout << "TEST 1:" << endl;
00074 cout << "epoch=" << epoch << " converts to " << dt.toString(Qt::TextDate) << endl;
00075
00076 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt);
00077 cout << "date=" << dt.toString(Qt::TextDate) << " converts to " << "epoch=" << epoch << endl;
00078
00079
00080 epoch=100000;
00081 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch);
00082 cout << "TEST 2:" << endl;
00083 cout << "epoch=" << epoch << " converts to " << dt.toString(Qt::TextDate) << endl;
00084
00085 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt);
00086 cout << "date=" << dt.toString(Qt::TextDate) << " converts to " << "epoch=" << epoch << endl;
00087
00088
00089 epoch=10000000;
00090 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch);
00091 cout << "TEST 3:" << endl;
00092 cout << "epoch=" << epoch << " converts to " << dt.toString(Qt::TextDate) << endl;
00093
00094 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt);
00095 cout << "date=" << dt.toString(Qt::TextDate) << " converts to " << "epoch=" << epoch << endl;
00096
00097
00098 epoch=1000000000;
00099 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch);
00100 cout << "TEST 4:" << endl;
00101 cout << "epoch=" << epoch << " converts to " << dt.toString(Qt::TextDate) << endl;
00102
00103 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt);
00104 cout << "date=" << dt.toString(Qt::TextDate) << " converts to " << "epoch=" << epoch << endl;
00105
00106
00107 epoch=10000000000;
00108 dt = KonsoleKalendarEpoch::epoch2QDateTime(epoch);
00109 cout << "TEST 5:" << endl;
00110 cout << "epoch=" << epoch << " converts to " << dt.toString(Qt::TextDate) << endl;
00111
00112 epoch = KonsoleKalendarEpoch::QDateTime2epoch(dt);
00113 cout << "date=" << dt.toString(Qt::TextDate) << " converts to " << "epoch=" << epoch << endl;
00114 }
00115 #endif
This file is part of the documentation for konsolekalendar Library Version 3.2.2.