diff options
Diffstat (limited to 'resumejson_converter/utils/templates.py')
-rw-r--r-- | resumejson_converter/utils/templates.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/resumejson_converter/utils/templates.py b/resumejson_converter/utils/templates.py new file mode 100644 index 0000000..b22b4b2 --- /dev/null +++ b/resumejson_converter/utils/templates.py @@ -0,0 +1,25 @@ + + +def td_format(td_object): + """ + based on https://stackoverflow.com/a/13756038 + """ + seconds = int(td_object.total_seconds()) + periods = [ + ('an', 60*60*24*365), + ('mois', 60*60*24*30), + ('semaine', 60*60*24*7), + ('jour', 60*60*24), + ('heure', 60*60), + ('minute', 60), + ('seconde', 1) + ] + + strings = [] + for period_name, period_seconds in periods: + if seconds > period_seconds: + period_value, seconds = divmod(seconds, period_seconds) + has_s = 's' if period_value > 1 and period_name != "mois" else '' + strings.append("%s %s%s" % (period_value, period_name, has_s)) + + return ", ".join(strings) |