Skip to content
Snippets Groups Projects
Commit 2aa698f3 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

lazy load grain

parent 3c6aa12d
No related branches found
No related tags found
No related merge requests found
......@@ -8,8 +8,6 @@ __copyright__ = "Copyright (C) 2015 University of Wisconsin SSEC. All rights res
UNIX_EPOCH = datetime(1970, 1, 1)
CDS_EPOCH = datetime(1958, 1, 1)
_grain = Grain()
def unixtime(dt):
"""
......@@ -29,7 +27,7 @@ def timecode_parts_to_iet(days, ms, us, epoch):
"""
Convert components to a IET based on arbitrary epoch.
"""
return int(_grain.utc2tai(
return int(_get_grain().utc2tai(
epoch + timedelta(days=float(days),
milliseconds=float(ms),
microseconds=float(us)),
......@@ -58,5 +56,19 @@ def dt_to_cds(dt):
return (d.days, int(d.seconds * 1e3), d.microseconds)
dt_to_iet = _grain.utc2iet
iet_to_dt = _grain.iet2utc
_grain = None
def _get_grain():
global _grain
if _grain is None:
_grain = Grain()
return _grain
def dt_to_iet(*args, **kwargs):
return _get_grain().utc2iet(*args, **kwargs)
def iet_to_dt(*args, **kwargs):
return _get_grain().iet2utc(*args, **kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment