Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/jwst_time_util.py
Дата изменения: Fri Apr 8 12:46:11 2016
Дата индексирования: Mon Apr 11 03:43:35 2016
Кодировка:

Поисковые слова: rings
#
#MODULE jwst_time_util
#
#*******************************************************************
"""

**PURPOSE** --
A module for dealing with JWST times and related things.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Initial implementation 12/10/08
replace tabs with spaces for Python 3 compatibility 2/13/12 drc & ar
strip whitespace off of input strings. drc 3/13/12
support input unicode. drc 3/13/12
modified for Python 3.2 compatibility. ar 4/26/12
remove global setting of TZ environment variable drc 4/2/13
"""
#*******************************************************************
# Force Python 2.7 to work as much like Python 3.0 as possible....
# This also makes this module incompatible with Python 2.5 and earlier.
from __future__ import print_function, division, absolute_import, unicode_literals

# Constants
MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec']

__version__ = "4/2/13"

import time_util
import os
import datetime
import time
import re

try:
import mx.DateTime
HAS_MX = True
except ImportError:
HAS_MX = False

global old_tz
old_tz = None


def tz_set(tz='UTC'):
"""Manipulate the timezone without affecting with other things outside of this
module.
"""
import os
if 'TZ' in os.environ.keys():
old_tz = os.environ['TZ']
os.environ['TZ'] = tz
time.tzset()


def tz_unset():
"""Put the TZ environment variable back the way it was.
"""
if old_tz:
os.environ['TZ'] = old_tz
else:
del os.environ['TZ']


class jwst_time(time_util.spss_time):
"""A class for dealing with times in JWST PPS."""
ordinal_format = "%Y-%jT%H:%M:%SZ"
calendar_format = "%Y-%m-%dT%H:%M:%SZ"
SHORT_YEAR_PATTERN = re.compile('(\d\d)(.*)')
LONG_YEAR_PATTERN = re.compile('(\d\d\d\d)(.*)')
DOY_PATTERN = re.compile('.(\d\d\d)(.*)')
DD_PATTERN1 = re.compile('.(\d\d)(.*)')
SEC_PATTERN1 = re.compile('.(\d\d$)')
UTC_PATTERN = re.compile('.(\d\d)(z$)')
SEC_PATTERN3 = re.compile('.(\d\d\.\d*)(.*)')
TZ_PATTERN = re.compile('(.*)([+|-])(\d\d$)')
TZ_PATTERN2 = re.compile('(.*)([+|-])(\d\d):(\d\d$)')

def __init__(self, t=None):
"""The jwst_time constructor.

Arguments:

t -- If a number, it is assumed to be seconds since 1970. If
a string, it is assumed to be a character time in one of the
approved formats. The default will set the time to the current
system time.

NOTE: In a departure from the way spss_time handles floats and ints,
jwst_time interprets these numbers as seconds since the 1/1/1970, not as
SOGS seconds (seconds since 1/1/1980).

**Raises** -- TypeError - Raised when the input is something
other than an int, float, string, or another jwst_time.
"""
JWSTTimeError = """jwst_time constructor requires an
int, float, string, another jwst_time, or a list of [