def get_literature_earliest_date(data): """Returns earliest date. If earliest date is missing month or day it's set as 1 as DB does not accept date without day or month Returns: str: earliest date represented in a string """ date_paths = [ "preprint_date", "thesis_info.date", "thesis_info.defense_date", "publication_info.year", "legacy_creation_date", "imprints.date", ] dates = [ str(el) for el in chain.from_iterable( force_list(get_value(data, path)) for path in date_paths) ] if dates: result = earliest_date(dates, full_date=True) if result: return result return None
def get_literature_earliest_date(data): """Returns earliest date. Returns: str: earliest date represented in a string """ date_paths = [ "preprint_date", "thesis_info.date", "thesis_info.defense_date", "publication_info.year", "legacy_creation_date", "imprints.date", ] dates = [ str(el) for el in chain.from_iterable( force_list(get_value(data, path)) for path in date_paths) ] if dates: result = earliest_date(dates) if result: return result return None
def legacy_creation_date(self, key, value): if 'legacy_creation_date' in self and self['legacy_creation_date']: return self['legacy_creation_date'] x_values = force_list(value.get('x')) if x_values: return earliest_date(x_values)
def populate_earliest_date(record): """Populate the ``earliest_date`` field of Literature records.""" date_paths = [ 'preprint_date', 'thesis_info.date', 'thesis_info.defense_date', 'publication_info.year', 'legacy_creation_date', 'imprints.date', ] dates = [ str(el) for el in chain.from_iterable( [force_list(get_value(record, path)) for path in date_paths]) ] if dates: result = earliest_date(dates) if result: record['earliest_date'] = result
def populate_earliest_date(sender, json, *args, **kwargs): """Populate the ``earliest_date`` field of Literature records.""" if not is_hep(json): return date_paths = [ 'preprint_date', 'thesis_info.date', 'thesis_info.defense_date', 'publication_info.year', 'legacy_creation_date', 'imprints.date', ] dates = [str(el) for el in chain.from_iterable( [force_list(get_value(json, path)) for path in date_paths])] if dates: result = earliest_date(dates) if result: json['earliest_date'] = result
def populate_earliest_date(record): """Populate the ``earliest_date`` field of Literature records.""" date_paths = [ 'preprint_date', 'thesis_info.date', 'thesis_info.defense_date', 'publication_info.year', 'legacy_creation_date', 'imprints.date', ] dates = [ str(el) for el in chain.from_iterable( [force_list(get_value(record, path)) for path in date_paths] ) ] if dates: result = earliest_date(dates) if result: record['earliest_date'] = result
def populate_earliest_date(sender, json, *args, **kwargs): """Populate the ``earliest_date`` field of Literature records.""" if 'hep.json' not in json.get('$schema'): return date_paths = [ 'preprint_date', 'thesis_info.date', 'thesis_info.defense_date', 'publication_info.year', 'legacy_creation_date', 'imprints.date', ] dates = [ str(el) for el in chain.from_iterable( [force_list(get_value(json, path)) for path in date_paths]) ] if dates: result = earliest_date(dates) if result: json['earliest_date'] = result
def test_earliest_date(): expected = '1686-06-30' result = earliest_date(['1686-06', '1686-06-30']) assert expected == result
def test_earliest_date_missing_month_and_day_without_full_date(): assert earliest_date(["2000"]) == "2000"
def test_earliest_date_missing_month_and_day_with_full_date(): assert earliest_date(["2000"], full_date=True) == "2000-01-01"