def getMinMaxValues(self):
        """Return min and max value strings"""
        if self.minValue is None or self.maxValue is None:  # if not already computed
            fmt = self.getTimeFormat()
            if self.getDateType() == time_util.DateTypes.IntegerTimestamps:
                self.minValue = self.getRawMinValue()
                self.maxValue = self.getRawMaxValue()
            else:  # strings or qdate(time) values
                # need to find min max by looking at all the unique values
                # because QGIS doesn't get sorting right
                uniques = self.getUniques(self.fromTimeAttribute)

                def vals_to_dt(vals, fmt):
                    res = []
                    for val in vals:
                        try:
                            dt = time_util.timeval_to_datetime(val, fmt)
                            res.append(dt)
                            # info("{} converted to {}".format(val, dt))
                        except Exception as e:
                            error(traceback.format_exc(e))
                            warn(
                                QCoreApplication.translate(
                                    'TimeManager',
                                    "Unparseable value {0} in layer {1} ignored. Cause {2}"
                                ).format(val, self.layer.name(), e))
                    return res

                unique_vals = vals_to_dt(uniques, fmt)
                if len(unique_vals) == 0:
                    raise Exception(
                        QCoreApplication.translate(
                            'TimeManager',
                            "Could not parse any dates while trying to get time extents."
                            "None of the values (for example {0}) matches the format {1}"
                        ).format(uniques[-1], fmt))
                minValue = time_util.datetime_to_str(min(unique_vals), fmt)
                if self.fromTimeAttribute == self.toTimeAttribute:
                    maxValue = time_util.datetime_to_str(max(unique_vals), fmt)
                else:
                    unique_vals = self.getUniques(self.toTimeAttribute)
                    unique_vals = vals_to_dt(unique_vals, fmt)
                    maxValue = time_util.datetime_to_str(max(unique_vals), fmt)

                if type(minValue) in [QDate, QDateTime]:
                    minValue = time_util.datetime_to_str(
                        time_util.QDateTime_to_datetime(minValue), fmt)
                    maxValue = time_util.datetime_to_str(
                        time_util.QDateTime_to_datetime(maxValue), fmt)
                self.minValue = minValue
                self.maxValue = maxValue
        return self.minValue, self.maxValue
Exemple #2
0
 def updateTimePositionFromTextBox(self, date):
     if not self.propagateGuiChanges:
         return
     if time_util.is_archaelogical():
         bcdate = bcdate_util.BCDate.from_str(date, strict_zeros=False)
         bcdate.setDigits(bcdate_util.getGlobalDigitSetting())
         self.getTimeLayerManager().setCurrentTimePosition(bcdate)
     else:
         self.getTimeLayerManager().setCurrentTimePosition(
             time_util.QDateTime_to_datetime(date))