Index: /trunk/BNC/RTCM3/ephemeris.cpp
===================================================================
--- /trunk/BNC/RTCM3/ephemeris.cpp	(revision 2256)
+++ /trunk/BNC/RTCM3/ephemeris.cpp	(revision 2257)
@@ -256,15 +256,8 @@
   int ww  = ee->GPSWeek;
   int tow = ee->GPSTOW; 
-
-  updatetime(&ww, &tow, ee->tb*1000, 0);
-
-  int tk = ee->tk-3*60*60; 
-  if (tk < 0) {
-    tk += 86400;
-  }
+  updatetime(&ww, &tow, ee->tb*1000, 0);  // Moscow -> GPS
 
   _GPSweek           = ww;
   _GPSweeks          = tow;
-  _gps_utc           = 0.0;
   _E                 = ee->E;
   _tau               = ee->tau;
@@ -281,5 +274,5 @@
   _health            = 0;
   _frequency_number  = ee->frequency_number;
-  _tki               = tk;
+  _tki               = ee->tk-3*60*60; if (_tki < 0) _tki += 86400;
 
   // Initialize status vector
Index: /trunk/BNC/RTCM3/ephemeris.h
===================================================================
--- /trunk/BNC/RTCM3/ephemeris.h	(revision 2256)
+++ /trunk/BNC/RTCM3/ephemeris.h	(revision 2257)
@@ -91,5 +91,5 @@
 class t_ephGlo : public t_eph {
  public:
-  t_ephGlo() { _gps_utc = 0.0; _xv.ReSize(6); }
+  t_ephGlo() { _xv.ReSize(6); }
 
   virtual ~t_ephGlo() {}
@@ -109,5 +109,4 @@
   mutable ColumnVector _xv;  // status vector (position, velocity) at time _tt
 
-  double  _gps_utc;          // GPS - UTC in seconds      
   double  _E;                // [days]   
   double  _tau;              // [s]      
Index: /trunk/BNC/bncapp.cpp
===================================================================
--- /trunk/BNC/bncapp.cpp	(revision 2256)
+++ /trunk/BNC/bncapp.cpp	(revision 2257)
@@ -218,9 +218,9 @@
     wwOld  = (*ee)->GPSWeek;
     towOld = (*ee)->GPSTOW; 
-    updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0);
+    updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0);  // Moscow -> GPS
 
     wwNew  = glonasseph->GPSWeek;
     towNew = glonasseph->GPSTOW; 
-    updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0);
+    updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
   }
 
@@ -481,5 +481,5 @@
   struct converttimeinfo cti;
 
-  updatetime(&ww, &tow, ep->tb*1000, 1);
+  updatetime(&ww, &tow, ep->tb*1000, 1);  // Moscow -> UTC
   converttime(&cti, ww, tow);
 
Index: /trunk/BNC/bnctime.cpp
===================================================================
--- /trunk/BNC/bnctime.cpp	(revision 2256)
+++ /trunk/BNC/bnctime.cpp	(revision 2257)
@@ -6,5 +6,5 @@
 
 #include "bnctime.h"
-#include "RTCM3/timeutils.h"
+#include "timeutils.h"
 
 using namespace std;
Index: /trunk/BNS/bnctime.cpp
===================================================================
--- /trunk/BNS/bnctime.cpp	(revision 2257)
+++ /trunk/BNS/bnctime.cpp	(revision 2257)
@@ -0,0 +1,193 @@
+#include <time.h>
+#include <cmath>
+#include <cstdio>
+#include <sstream>
+#include <iomanip>
+
+#include "bnctime.h"
+#include "RTCM3/timeutils.h"
+
+using namespace std;
+
+// Constructor
+//////////////////////////////////////////////////////////////////////////////
+bncTime::bncTime(int gpsw, double gpssec) {
+  this->set(gpsw, gpssec);
+}
+  
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime& bncTime::set(int gpsw, double gpssec) {
+  int  deltad;
+  int  dow = 0;
+  while ( gpssec >= 86400 ) {
+    gpssec-=86400;
+    dow++;
+  }
+  while ( gpssec <  0 ) {
+    gpssec+=86400;
+    dow--;
+  }
+  deltad = gpsw*7 + dow;
+  _mjd = 44244 + deltad;
+  _sec = gpssec;
+  return *this;
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime& bncTime::setmjd(double daysec, int mjd) {
+  _sec = daysec;
+  _mjd = mjd;
+  while ( _sec >= 86400 ) {
+    _sec-=86400;
+    _mjd++;
+  }
+  while ( _sec <  0 ) {
+    _sec+=86400;
+    _mjd--;
+  }
+  return *this;
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+unsigned int bncTime::mjd() const {
+  return _mjd;
+}
+ 
+//
+//////////////////////////////////////////////////////////////////////////////
+double bncTime::daysec() const {
+  return _sec;
+}
+
+//
+//////////////////////////////////////////////////////////////////////////////
+unsigned int bncTime::gpsw() const {
+  double   gsec;
+  long     gpsw;
+  jdgp(_mjd, gsec, gpsw);
+  return (int)gpsw;
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+double bncTime::gpssec() const {
+  double   gsec;
+  long     gpsw;
+  jdgp(_mjd, gsec, gpsw);
+  return gsec + _sec;
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bool bncTime::operator!=(const bncTime &time1) const {
+  if ( ((*this) - time1) != 0 ) return 1;
+  return 0;
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime bncTime::operator+(double sec) const {
+  int     mjd    = this->mjd();
+  double  daysec = this->daysec();
+  daysec+=sec;
+  return bncTime().setmjd(daysec, mjd);
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime bncTime::operator-(double sec) const {
+  return (*this) + (-sec);
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+double bncTime::operator-(const bncTime &time1) const {
+  int mjdDiff = this->_mjd - time1._mjd;
+  if ( mjdDiff != 0 ) {
+    return mjdDiff * 86400.0 + this->_sec - time1._sec;
+  }
+  else {
+    return this->_sec - time1._sec;
+  }
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+void bncTime::civil_time(unsigned int &hour, unsigned int &min, 
+                          double &sec) const {
+  hour = static_cast<unsigned int>(_sec/3600.0);
+  min  = static_cast<unsigned int>((_sec - hour*3600)/60.0);
+  sec  = _sec - min*60 - hour*3600;
+  if (sec==60.0) {
+    min++;
+    sec=0;
+  }
+  if (min==60) {
+    hour++;
+    min=0;
+  }
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+string bncTime::timestr(unsigned numdec, char sep) const {
+  ostringstream str;
+  unsigned int hour, minute;
+  double sec;
+  this->civil_time(hour, minute, sec);
+  unsigned sw;
+  if (numdec == 0) {
+    sw = 2;
+  }
+  else {
+    sw = numdec + 3;
+  }
+  double chk = 0.5;
+  for (unsigned int ii=0; ii<numdec; ii++) chk *= 0.1;
+  if (sec > (60.0-chk)) {
+    sec = 0;
+    minute++;
+    if (minute == 60) {
+      minute = 0;
+      hour++;
+    }
+  }
+  str.setf(ios::fixed);
+  str << setfill('0');
+  str << setw(2)  << hour;
+  if (sep) str << sep;
+  str << setw(2)  << minute;
+  if (sep) str << sep;
+  str << setw(sw) << setprecision(numdec) << sec;
+  return str.str();
+}
+
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime& bncTime::set(int year, int month, int day, 
+                      int hour, int min, double sec) {
+  return set(year, month, day, hour*3600 + min*60 + sec);
+}
+
+// 
+//////////////////////////////////////////////////////////////////////////////
+bncTime& bncTime::set(int year, int month, int day, double daysec) {
+  _sec = daysec;
+  
+  _mjd = (unsigned int)djul(year, month, day);
+  
+  while ( _sec >= 86400 ) {
+    _sec-=86400;
+    _mjd++;
+  }
+  while ( _sec <  0 ) {
+    _sec+=86400;
+    _mjd--;
+  }
+
+  return *this;
+}
Index: /trunk/BNS/bnctime.h
===================================================================
--- /trunk/BNS/bnctime.h	(revision 2257)
+++ /trunk/BNS/bnctime.h	(revision 2257)
@@ -0,0 +1,39 @@
+
+#ifndef BNCTIME_H
+#define BNCTIME_H
+
+#include <string>
+
+class bncTime {
+ public:
+  bncTime() {this->reset();}
+  bncTime(int gpsw, double gpssec);
+
+  bncTime& set(int gpsw, double gpssec);
+  bncTime& set(int year, int month, int day, int hour, int min, double sec);
+  bncTime& set(int year, int month, int day, double daysec);
+
+  unsigned int mjd()    const;
+  double       daysec() const;
+  unsigned int gpsw()   const;
+  double       gpssec() const;
+  void         civil_time (unsigned int& hour, unsigned int& min,
+                           double& sec) const;
+
+  bool   operator!=(const bncTime &time1) const;
+  double operator-(const bncTime &time1) const;
+  bncTime operator-(double sec) const;
+  bncTime operator+(double sec) const;
+
+  std::string timestr(unsigned numdec = 3, char sep = ':') const;  
+
+ private:
+  bncTime&     setmjd(double daysec, int mjd);
+  void        reset() {_mjd = 0; _sec = 0;}
+
+  unsigned int _mjd;
+  double       _sec;
+};
+
+#endif
+
Index: /trunk/BNS/bns.pro
===================================================================
--- /trunk/BNS/bns.pro	(revision 2256)
+++ /trunk/BNS/bns.pro	(revision 2257)
@@ -33,5 +33,5 @@
           bnseph.h    bnsutils.h bnsrinex.h bnssp3.h bnsoutf.h        \
           bnscaster.h RTCM/clock_orbit_rtcm.h bnssettings.h bnsapp.h  \
-          bnscustomtrafo.h RTCM/rtcm3torinex.h
+          bnscustomtrafo.h RTCM/rtcm3torinex.h bnctime.h
 
 HEADERS += newmat/controlw.h newmat/include.h newmat/myexcept.h  \
@@ -42,5 +42,5 @@
           bnseph.cpp  bnsutils.cpp bnsrinex.cpp bnssp3.cpp bnsoutf.cpp \
           bnscaster.cpp bnssettings.cpp bnsapp.cpp bnscustomtrafo.cpp  \
-          RTCM/clock_orbit_rtcm.c RTCM/rtcm3torinex.c
+          RTCM/clock_orbit_rtcm.c RTCM/rtcm3torinex.c bnctime.cpp
 
 SOURCES += newmat/bandmat.cpp newmat/cholesky.cpp newmat/evalue.cpp  \
