def _stringToValue_date(self, string): regex = re.match(self._iso8601_date, string) if regex is None: raise ValueError("invalid ISO 8601 date string: \"%s\"" % string) year = regex.group(1) month = regex.group(3) day = regex.group(5) try: if year is not None and month is not None and day is not None: dateTimeObject = datetime.datetime(int(year), int(month), int(day)) elif year is not None and month is not None: dateTimeObject = datetime.datetime(int(year), int(month), 1) elif year is not None: dateTimeObject = datetime.datetime(int(year), 1, 1) else: raise ValueError except ValueError: raise ValueError("invalid ISO 8601 date string: \"%s\"" % string) td = dateTimeObject - self._dateTimeOrigin return NP.int64(td.days*86400 * self._dateTimeResolution)
def _stringToValue_time(self, string): regex = re.match(self._iso8601_time, string) if regex is None: raise ValueError("invalid ISO 8601 time string: \"%s\"" % string) hour = regex.group(1) minute = regex.group(2) second = regex.group(4) subsecond = regex.group(5) timezone = regex.group(6) timezoneOffset = 0 try: if hour is not None and minute is not None and second is not None: if subsecond is None: microsecond = 0 else: microsecond = int(round(float(subsecond) * 1e6)) dateTimeObject = datetime.datetime(1970, 1, 1, int(hour), int(minute), int(second), microsecond) elif hour is not None and minute is not None: if subsecond is not None: raise ValueError dateTimeObject = datetime.datetime(1970, 1, 1, int(hour), int(minute)) if timezone is not None: regex2 = re.match(self._timezone, timezone) if regex2 is not None: sign, hourOffset, minuteOffset = regex2.groups() timezoneOffset = ((int(hourOffset) * 60) + int(minuteOffset)) * 60 * self._dateTimeResolution # microseconds if sign == "-": timezoneOffset *= -1 except ValueError: raise ValueError("invalid ISO 8601 time string: \"%s\"" % string) td = dateTimeObject - self._dateTimeOrigin return NP.int64(td.seconds * self._dateTimeResolution + td.microseconds - timezoneOffset)
def _stringToValue_dateTime(self, string): # accept all of the ISO 8601 standards as well as the variants in which: # the literal "T" is replaced by a space " " # the hyphen delimiters "-" are replaced by slashes "/" # the timezone is not specified regex = re.match(self._iso8601, string) if regex is None: raise ValueError("invalid ISO 8601 dateTime string: \"%s\"" % string) year = regex.group(1) month = regex.group(3) day = regex.group(5) hour = regex.group(7) minute = regex.group(8) second = regex.group(10) subsecond = regex.group(11) timezone = regex.group(12) timezoneOffset = 0 try: if year is not None and month is not None and day is not None and hour is not None and minute is not None: if second is not None: if subsecond is None: microsecond = 0 else: microsecond = int(round(float(subsecond) * 1e6)) dateTimeObject = datetime.datetime(int(year), int(month), int(day), int(hour), int(minute), int(second), microsecond) else: if subsecond is not None: raise ValueError dateTimeObject = datetime.datetime(int(year), int(month), int(day), int(hour), int(minute)) if timezone is not None: regex2 = re.match(self._timezone, timezone) if regex2 is not None: sign, hourOffset, minuteOffset = regex2.groups() timezoneOffset = ((int(hourOffset) * 60) + int(minuteOffset)) * 60 * self._dateTimeResolution # microseconds if sign == "-": timezoneOffset *= -1 elif year is not None and month is not None and day is not None and hour is not None: raise ValueError elif year is not None and month is not None and day is not None: dateTimeObject = datetime.datetime(int(year), int(month), int(day)) elif year is not None and month is not None: dateTimeObject = datetime.datetime(int(year), int(month), 1) elif year is not None: dateTimeObject = datetime.datetime(int(year), 1, 1) else: raise ValueError except ValueError: raise ValueError("invalid ISO 8601 dateTime string: \"%s\"" % string) td = dateTimeObject - self._dateTimeOrigin return NP.int64((td.days*86400 + td.seconds) * self._dateTimeResolution + td.microseconds - timezoneOffset)
def _stringToValue_integer(self, string): return NP.int64(string)
def _stringToValue_dateTimeNumber(self, string): return (NP.int64(string) * self._factor) + self._offset