add copy of tz util to contents service

This commit is contained in:
Min RK 2015-04-10 14:30:43 -07:00
parent d2f3446770
commit 6f964e7ee6
3 changed files with 48 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)