How to use the arctic.date.datetime_to_ms function in arctic

To help you get started, we’ve selected a few arctic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github man-group / arctic / tests / unit / date / test_datetime_to_ms_roundtrip.py View on Github external
def assert_roundtrip(tz):
    ts = datetime.datetime(1982, 7, 1, 16, 5)

    ts1 = ts.replace(tzinfo=tz)
    ts2 = ms_to_datetime(datetime_to_ms(ts1.astimezone(mktz("UTC"))), tz)

    assert(ts2.hour == ts1.hour)
    assert ts2 == ts1
github man-group / arctic / tests / unit / date / test_datetime_to_ms_roundtrip.py View on Github external
def test_datetime_roundtrip_est_tz():
    pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz('EST'))
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2.replace(tzinfo=mktz()) == pdt

    pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz('EST'))
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2.replace(tzinfo=mktz()) == pdt
github man-group / arctic / tests / unit / date / test_datetime_to_ms_roundtrip.py View on Github external
def test_datetime_roundtrip_local_no_tz():
    pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000)
    pdt2 = ms_to_datetime(datetime_to_ms(pdt)).replace(tzinfo=None)
    assert pdt2 == pdt

    pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000)
    pdt2 = ms_to_datetime(datetime_to_ms(pdt)).replace(tzinfo=None)
    assert pdt2 == pdt
github man-group / arctic / tests / unit / date / test_datetime_to_ms_roundtrip.py View on Github external
def test_datetime_roundtrip_local_tz():
    pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz())
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2 == pdt

    pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz())
    pdt2 = ms_to_datetime(datetime_to_ms(pdt))
    assert pdt2 == pdt
github man-group / arctic / arctic / tickstore / tickstore.py View on Github external
def _to_ms(date):
        if isinstance(date, dt):
            if not date.tzinfo:
                logger.warning('WARNING: treating naive datetime as UTC in write path')
            return datetime_to_ms(date)
        return date
github man-group / arctic / arctic / store / version_store.py View on Github external
raise NoDataFoundException('No snapshot %s in library %s' % (snapshot, self._arctic_lib.get_name()))

        versions = []
        snapshots = {ss.get('_id'): ss.get('name') for ss in self._snapshots.find()}
        for symbol in symbols:
            query['symbol'] = symbol
            seen_symbols = set()
            for version in self._versions.find(query, projection=['symbol', 'version', 'parent', 'metadata.deleted'], sort=[('version', -1)]):
                if latest_only and version['symbol'] in seen_symbols:
                    continue
                seen_symbols.add(version['symbol'])
                meta = version.get('metadata')
                versions.append({'symbol': version['symbol'], 'version': version['version'],
                                 'deleted': meta.get('deleted', False) if meta else False,
                                 # We return offset-aware datetimes in Local Time.
                                 'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)),
                                 'snapshots': [snapshots[s] for s in version.get('parent', []) if s in snapshots]})
        return versions
github man-group / arctic / arctic / tickstore / tickstore.py View on Github external
def _prepend_image(self, document, im, rtn_length, column_dtypes, column_set, columns):
        image = im[IMAGE]
        first_dt = im[IMAGE_TIME]
        if not first_dt.tzinfo:
            first_dt = first_dt.replace(tzinfo=mktz('UTC'))
        document[INDEX] = np.insert(document[INDEX], 0, np.uint64(datetime_to_ms(first_dt)))
        for field in image:
            if field == INDEX:
                continue
            if columns and field not in columns:
                continue
            if field not in document or document[field] is None:
                col_dtype = np.dtype(str if isinstance(image[field], string_types) else 'f8')
                document[field] = self._empty(rtn_length, dtype=col_dtype)
                column_dtypes[field] = col_dtype
                column_set.add(field)
            val = image[field]
            document[field] = np.insert(document[field], 0, document[field].dtype.type(val))
        # Now insert rows for fields in document that are not in the image
        for field in set(document).difference(set(image)):
            if field == INDEX:
                continue