elapsedtimestr#

elapsedtimestr(pasttime, maxdays=5, minseconds=10, shortmonths=True)[source]#

Accepts a datetime object or a string in ISO 8601 format and returns a human-readable string explaining when this time was.

The rules are as follows:

  • If a time is within the last hour, return ‘XX minutes’

  • If a time is within the last 24 hours, return ‘XX hours’

  • If within the last 5 days, return ‘XX days’

  • If in the same year, print the date without the year

  • If in a different year, print the date with the whole year

These can be configured as options.

Examples:

yesterday = sc.datedelta(sc.now(), days=-1)
sc.elapsedtimestr(yesterday)