Esempio n. 1
0
def parse_sampling_time(object_):
    """Parse an object into a sampling time.
    
    Parameters
    ----------
    object_ : datetime.datetime, model.Sample
        The object to be parsed into a Time object, representing the sampling
        time.
    """
    # Parse from datetime-like object
    try:
        time = Time.from_datetime(object_)
    except AttributeError:
        time = None
    else:
        return time
    # Parse from model.Sample
    try:
        sample_date = object_.sample_date
        sample_time = object_.sample_time
        default_date = datetime.date(1, 1, 1)
        default_time = datetime.time(0, 0, 0)
        if sample_date and sample_time:
            timestamp = datetime.datetime.combine(sample_date, sample_time)
        elif sample_date:
            timestamp = datetime.datetime.combine(sample_date, default_time)
        elif sample_time:
            timestamp = datetime.datetime.combine(default_date, sample_time)
        else:
            # Sample object has no date or time
            return None
        time = Time.from_datetime(timestamp)
    except AttributeError:
        time = None
    else:
        return time
    return time
Esempio n. 2
0
def parse_sample_time(row, datetime_col):
    datetime = row[datetime_col]
    return Time.from_datetime(datetime)