def conv(value):
     zero_fill = ctx['zero_fill']
     seconds = int(value[0:-scale - 1]) if scale > 0 else int(value)
     # construct datetime object to get utcoffset
     dt = ZERO_EPOCH + timedelta(seconds=seconds)
     offset = tzinfo.utcoffset(dt)
     if offset.days < 0:
         ts = (int(value[0:-scale - 1]) +
               (offset.seconds - 86400)) * 1000000000
     else:
         ts = (int(value[0:-scale - 1]) + offset.seconds) * 1000000000
     if scale > 0:
         ts += (-1 if value[0] == u'-' else 1) * int(value[-scale:] +
                                                     zero_fill)
     return numpy.datetime64(ts, 'ns')
Exemplo n.º 2
0
 def _derive_offset_timestamp(self, value, is_utc=False):
     """
     Derives TZ offset and timestamp from the datatime object
     """
     tzinfo = value.tzinfo
     if tzinfo is None:
         # If no tzinfo is attached, use local timezone.
         tzinfo = self._get_session_tz() if not is_utc else pytz.UTC
         t = pytz.utc.localize(value, is_dst=False).astimezone(tzinfo)
     else:
         # if tzinfo is attached, just covert to epoch time
         # as the server expects it in UTC anyway
         t = value
     offset = tzinfo.utcoffset(
         t.replace(tzinfo=None)).total_seconds() / 60 + 1440
     return offset, t