def format_value(self, value): """Format an EDTF date.""" return format_edtf(value, format=self._format, locale=self.locale)
def embargo_date(self): """Embargo date.""" until = self.record_access_dict.get('embargo').get('until') if until: return format_edtf(until, format='long') return until
def test_format_edtf_format(): """Test overriding the format.""" assert format_edtf('2020-11', format='yMd', locale='en') == '11/1/2020' assert format_edtf('2020/2021', format='yM', locale='en') == \ '1/2020 – 12/2021'
def test_format_edtf(edtfstr, locale, format, expected): assert format_edtf(edtfstr, format=format, locale=locale) == expected
def test_format_edtf_default(): """Test the default time being used if not value provided.""" today = datetime.utcnow().date() assert format_edtf(format='short', locale='en') == '{}/{}/{}'.format( today.month, today.day, str(today.year)[2:4])