source: ntrip/trunk/BNC/bncutils.cpp@ 271

Last change on this file since 271 was 271, checked in by mervart, 17 years ago

* empty log message *

File size: 1.7 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncutils
7 *
8 * Purpose: Auxiliary Functions
9 *
10 * Author: L. Mervart
11 *
12 * Created: 30-Aug-2006
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <iostream>
19#include <ctime>
20#include <math.h>
21
22#include <QRegExp>
23#include <QStringList>
24#include <QDateTime>
25
26#include "bncutils.h"
27
28using namespace std;
29
30void expandEnvVar(QString& str) {
31
32 QRegExp rx("(\\$\\{.+\\})");
33
34 if (rx.indexIn(str) != -1) {
35 QStringListIterator it(rx.capturedTexts());
36 if (it.hasNext()) {
37 QString rxStr = it.next();
38 QString envVar = rxStr.mid(2,rxStr.length()-3);
39 str.replace(rxStr, qgetenv(envVar.toAscii()));
40 }
41 }
42
43}
44
45QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
46
47 static const QDate zeroEpoch(1980, 1, 6);
48
49 QDate date(zeroEpoch);
50 QTime time(0,0,0,0);
51
52 int weekDays = int(GPSWeeks) / 86400;
53 date = date.addDays( GPSWeek * 7 + weekDays );
54 time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
55
56 return QDateTime(date,time);
57}
58
59void currentGPSWeeks(int& week, double& sec) {
60
61 QDateTime currDateTime = QDateTime::currentDateTime().toUTC();
62 QDate currDate = currDateTime.date();
63 QTime currTime = currDateTime.time();
64
65 week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
66
67 sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
68 currTime.hour() * 3600.0 +
69 currTime.minute() * 60.0 +
70 currTime.second() +
71 currTime.msec() / 1000.0;
72}
Note: See TracBrowser for help on using the repository browser.