예제 #1
0
def earliest_date(sender, *args, **kwargs):
    """Find and assign the earliest date to a HEP paper."""
    dates = []

    if 'preprint_date' in sender:
        dates.append(sender['preprint_date'])

    if 'thesis' in sender:
        for thesis_key in sender['thesis']:
            if 'date' in thesis_key:
                dates.append(thesis_key['date'])
            if 'defense_date' in thesis_key:
                dates.append(thesis_key['defense_date'])

    if 'publication_info' in sender:
        for publication_info_key in sender['publication_info']:
            if 'year' in publication_info_key:
                dates.append(publication_info_key['year'])

    # Sort dates and pick the first one.
    dates.sort()

    if dates:
        sender['earliest_date'] = \
            inspire_dojson_utils.create_valid_date(dates[0])
def test_create_valid_date():
    """Test date validator used in dojson conversions."""
    assert create_valid_date(1877) == '1877-01-01'
    assert create_valid_date("1877") == '1877-01-01'
    assert create_valid_date("1877-02") == '1877-02-01'
    assert create_valid_date("1877-02-03") == '1877-02-03'
    assert create_valid_date(1977) == '1977-01-01'
    assert create_valid_date("1977") == '1977-01-01'
    assert create_valid_date("1977-06-02") == '1977-06-02'