Index: trunk/BNC/src/pppRun.cpp
===================================================================
--- trunk/BNC/src/pppRun.cpp	(revision 11196)
+++ trunk/BNC/src/pppRun.cpp	(revision 11221)
@@ -500,4 +500,39 @@
 
 //
+// Real-time input (incl. raw file replay): true if the correction epoch is
+// more than MAX_EPOCH_OFFSET from the current time, e.g. an erroneously
+// encoded GLONASS epoch hours ahead (not used, as in the combination and the
+// SSR QC). It would make the satellites unusable (age check of the
+// corrections), discard observation epochs (correction wait time) and
+// extrapolate the yaw angle over hours until the next correction. Biases
+// (pastOk) are only rejected for a future epoch: their epoch may legitimately
+// be hours old (Galileo HAS). A warning at most once per hour.
+////////////////////////////////////////////////////////////////////////////
+bool t_pppRun::badEpoch(const bncTime& epoTime, const string& staID,
+                        const char* type, bool pastOk) {
+  const double MAX_EPOCH_OFFSET = 900.0; // [s]
+  if (!_opt->_realTime) {
+    return false;
+  }
+  int    currentWeek = 0;
+  double currentSec  = 0.0;
+  currentGPSWeeks(currentWeek, currentSec);
+  bncTime currentTime(currentWeek, currentSec);
+  double offset = epoTime - currentTime;
+  if (fabs(offset) <= MAX_EPOCH_OFFSET || (pastOk && offset < 0.0)) {
+    return false;
+  }
+  if (!_badEpochWarned.valid() || currentTime - _badEpochWarned >= 3600.0) {
+    _badEpochWarned = currentTime;
+    emit newLogRecord(t_logRecord::message(t_logRecord::warning, QByteArray(_opt->_roverName.c_str()) + ": PPP: " +
+                    QByteArray(staID.c_str()) + " " + type + " correction epoch " +
+                    QByteArray(epoTime.datestr().c_str()) + " " + epoTime.timestr().c_str() +
+                    QString(" is %1 s from the current time, not used").arg(offset, 0, 'f', 0).toLatin1() +
+                    " (further ones not reported within the next hour)"), true);
+  }
+  return true;
+}
+
+//
 ////////////////////////////////////////////////////////////////////////////
 void t_pppRun::slotNewTec(t_vTec vTec) {
@@ -521,4 +556,7 @@
     }
   }
+  if (badEpoch(vTec._time, vTec._staID, "VTEC")) {
+    return;
+  }
   _pppClient->putTec(&vTec);
 }
@@ -553,5 +591,10 @@
   vector<t_orbCorr*> corrections;
   for (int ii = 0; ii < orbCorr.size(); ii++) {
-    corrections.push_back(new t_orbCorr(orbCorr[ii]));
+    if (!badEpoch(orbCorr[ii]._time, orbCorr[ii]._staID, "orbit")) {
+      corrections.push_back(new t_orbCorr(orbCorr[ii]));
+    }
+  }
+  if (corrections.empty()) {
+    return;
   }
 
@@ -577,6 +620,11 @@
   vector<t_clkCorr*> corrections;
   for (int ii = 0; ii < clkCorr.size(); ii++) {
-    corrections.push_back(new t_clkCorr(clkCorr[ii]));
-    _lastClkCorrTime = clkCorr[ii]._time;
+    if (!badEpoch(clkCorr[ii]._time, clkCorr[ii]._staID, "clock")) {
+      corrections.push_back(new t_clkCorr(clkCorr[ii]));
+      _lastClkCorrTime = clkCorr[ii]._time;
+    }
+  }
+  if (corrections.empty()) {
+    return;
   }
   _pppClient->putClkCorrections(corrections);
@@ -611,5 +659,10 @@
   vector<t_satCodeBias*> biases;
   for (int ii = 0; ii < codeBiases.size(); ii++) {
-    biases.push_back(new t_satCodeBias(codeBiases[ii]));
+    if (!badEpoch(codeBiases[ii]._time, codeBiases[ii]._staID, "code bias", true)) {
+      biases.push_back(new t_satCodeBias(codeBiases[ii]));
+    }
+  }
+  if (biases.empty()) {
+    return;
   }
 
@@ -672,5 +725,10 @@
   vector<t_satPhaseBias*> biases;
   for (int ii = 0; ii < phaseBiases.size(); ii++) {
-    biases.push_back(new t_satPhaseBias(phaseBiases[ii]));
+    if (!badEpoch(phaseBiases[ii]._time, phaseBiases[ii]._staID, "phase bias", true)) {
+      biases.push_back(new t_satPhaseBias(phaseBiases[ii]));
+    }
+  }
+  if (biases.empty()) {
+    return;
   }
 
