mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-13 13:17:50 +08:00
add copy of tz util to contents service
This commit is contained in:
parent
d2f3446770
commit
6f964e7ee6
@ -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
|
||||
|
@ -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,
|
||||
|
46
jupyter_notebook/services/contents/tz.py
Normal file
46
jupyter_notebook/services/contents/tz.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user