Skip to content

Instantly share code, notes, and snippets.

@lyudmil-mitev
lyudmil-mitev / humanize_time.py
Created July 4, 2011 15:26
Humanize time intervals. humanize_time(173, "hours") --> [(1, 'week'), (5, 'hours')]
#!/usr/bin/env python
INTERVALS = [1, 60, 3600, 86400, 604800, 2419200, 29030400]
NAMES = [('second', 'seconds'),
('minute', 'minutes'),
('hour', 'hours'),
('day', 'days'),
('week', 'weeks'),
('month', 'months'),
('year', 'years')]