From 6f964e7ee681c0e88d971b05d97886bb50b05eb2 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 10 Apr 2015 14:30:43 -0700 Subject: [PATCH] add copy of tz util to contents service --- .../services/contents/filecheckpoints.py | 2 +- .../services/contents/filemanager.py | 2 +- jupyter_notebook/services/contents/tz.py | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 jupyter_notebook/services/contents/tz.py diff --git a/jupyter_notebook/services/contents/filecheckpoints.py b/jupyter_notebook/services/contents/filecheckpoints.py index 39f94c6ed..f6dd9b6bc 100644 --- a/jupyter_notebook/services/contents/filecheckpoints.py +++ b/jupyter_notebook/services/contents/filecheckpoints.py @@ -12,7 +12,7 @@ from .checkpoints import ( ) from .fileio import FileManagerMixin -from IPython.utils import tz +from . import tz from ipython_genutils.path import ensure_dir_exists from ipython_genutils.py3compat import getcwd from traitlets import Unicode diff --git a/jupyter_notebook/services/contents/filemanager.py b/jupyter_notebook/services/contents/filemanager.py index ea2f748b6..8de76d84f 100644 --- a/jupyter_notebook/services/contents/filemanager.py +++ b/jupyter_notebook/services/contents/filemanager.py @@ -19,7 +19,7 @@ from IPython import nbformat from ipython_genutils.importstring import import_item from traitlets import Any, Unicode, Bool, TraitError from ipython_genutils.py3compat import getcwd, string_types -from IPython.utils import tz +from . import tz from jupyter_notebook.utils import ( is_hidden, to_api_path, diff --git a/jupyter_notebook/services/contents/tz.py b/jupyter_notebook/services/contents/tz.py new file mode 100644 index 000000000..b315d532d --- /dev/null +++ b/jupyter_notebook/services/contents/tz.py @@ -0,0 +1,46 @@ +# encoding: utf-8 +""" +Timezone utilities + +Just UTC-awareness right now +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2013 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from datetime import tzinfo, timedelta, datetime + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- +# constant for zero offset +ZERO = timedelta(0) + +class tzUTC(tzinfo): + """tzinfo object for UTC (zero offset)""" + + def utcoffset(self, d): + return ZERO + + def dst(self, d): + return ZERO + +UTC = tzUTC() + +def utc_aware(unaware): + """decorator for adding UTC tzinfo to datetime's utcfoo methods""" + def utc_method(*args, **kwargs): + dt = unaware(*args, **kwargs) + return dt.replace(tzinfo=UTC) + return utc_method + +utcfromtimestamp = utc_aware(datetime.utcfromtimestamp) +utcnow = utc_aware(datetime.utcnow)