Example #1
0
def format_phone_table(co, phone_table):
    now = DateTime.now()
    lastweek = now - DateTime.TimeDelta(24 * 7)
    table = []
    for i, entry in enumerate(sorted(phone_table)):
        ssys = entry['ssys']
        ssys_s = '{0: <8}'.format(text_type(co.AuthoritativeSystem(ssys)))
        status = entry['status']
        if status:
            status_s = '{0: <24}'.format(text_type(co.human2constant(status)))
        else:
            status_s = '{0: <24}'.format(text_type('invalid affiliation'))
        number = entry['number']
        if number:
            num_s = '{0: >18}'.format(text_type(number))
            mod_date = entry['date']
            if mod_date and mod_date > lastweek:
                date_s = '  (changed {} days ago)'.format(
                    int((now - mod_date).days))
            else:
                date_s = '   date is OK'
        else:
            num_s = '{0: >18}'.format(None)
            date_s = '         None'
        if i == 0:
            k0, k1, k2, k3 = 'ssys0', 'status0', 'number0', 'date_str0'
        else:
            k0, k1, k2, k3 = 'ssysn', 'statusn', 'numbern', 'date_strn'
        table.append({k0: ssys_s, k1: status_s, k2: num_s, k3: date_s})
    return table
def Time(hour, minute, second):
    # mx DateTimeDeltas roll over when provided with an hour greater than
    # 23, a minute greater than 59, and so on.  That is not acceptable for our
    # purposes.
    if hour < 0 or hour > 23:
        raise DataError("hour must be between 0 and 23")
    if minute < 0 or minute > 59:
        raise DataError("minute must be between 0 and 59")
    if second < 0 or second > 59:
        raise DataError("second must be between 0 and 59")

    try:
        theTime = mxDT.TimeDelta(hour, minute, second)
    except mxDT.Error, e:
        raise DataError(str(e))
Example #3
0
def any_valid_phones(phone_table, fresh_account):
    """Return True if a phone table contains any entry with a
    status (phone number comes from a valid affiliation) and
    a non-recent date (one week or more)
    """
    now = DateTime.now()
    last_week = now - DateTime.TimeDelta(24 * 7)
    for phone in phone_table:
        if phone['status'] and phone['number']:
            if fresh_account:
                return True

            date = phone['date']
            if not date or date < last_week:
                return True
    return False
Example #4
0
#       National Radio Astronomy Observatory
#       P. O. Box 2
#       Green Bank, WV 24944-0002 USA

# $Id: TimeAgent.py,v 1.4 2007/06/21 14:20:47 mclark Exp $

from mx import DateTime
import math
#import slalib
from pyslalib import slalib
import datetime
import pytz

UTC = pytz.timezone('UTC')
EST = pytz.timezone('US/Eastern')
LATE_BUFFER = DateTime.TimeDelta(0, 10, 0)
GBT_LOCATION = ('-79:50:23.423', '38:25:59.266', 855.0)
"""
Contains utility methods for translating time representations.
Though internally these functions use mx.DateTime classes, all
dates and times passed to and from use the built-in module datetime.
These functions are built around mx.DateTime with a little help
from slalib for LST stuff.  The core time frame is UTC which can
be represented by either DateTime (absolute or date + time) or
DateTimeDelta (relative or dateless).  LST is always taken to be 
relative, i.e., represented by a DateTimeDelta object.  Relative
times are translated into an absolute time for "today." Translations
to and from TimeStamp (MJD and seconds since midnight as the Ygor
system represents time) are also available.
"""
Example #5
0
def round_datetime(d):
    d += DateTime.TimeDelta(seconds=0.5)
    return DateTime.DateTime(d.year, d.month, d.day, d.hour, d.minute,
                             int(floor(d.second)))
Example #6
0
def estimate_transfer_time(size, bandwidth):
    bandwidthMBs = float(bandwidth) / 8
    seconds = size / bandwidthMBs
    return round_datetime_delta(DateTime.TimeDelta(seconds=seconds))
Example #7
0
def Time(hour, minute, second):
    return DateTime.TimeDelta(hour, minute, second)