hydroshare: Python strftime can't handle dates before 1900

A user has tried to upload data with a legitimate start date of 1890.

However, when trying to upload it into HydroShare, they were met with the following error:

temporal_coverage_data_dict['start_date'] = start_date.strftime('%Y-%m-%d')
ValueError: year=1890 is before 1900; the datetime strftime() methods require year >= 1900

It looks like there are numerous options to fix this.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 28 (25 by maintainers)

Commits related to this issue

Most upvoted comments

So, perhaps, a function like this would be useful.

def format_datetime(dt, template='{0.year:4d}-{0.month:02d}-{0.day:02d}'):
    return template.format(dt)

I will buy everybody on the team a round of drinks at whatever conference we are all next at if and when HydroShare gets updated to Python 3.

Fwiw, 7/16/18 is pretty clear, but mm/dd/yy can be ambiguous. Europeans and military folks often interpret numeric dates like 7/4/18 as April 7 not July 4. It’s least ambiguous & most general to stick with yyyy-mm-dd or spell out the month abbreviation.

That’s a clever function. It self documents how to do custom formatting while defaulting to a standard format. 👍

I’d argue it is probably a good idea to standardize date format across the board in HydroShare.