Skip to content

Instantly share code, notes, and snippets.

View benyaminshoham's full-sized avatar

Benyamin Shoham benyaminshoham

View GitHub Profile
@benyaminshoham
benyaminshoham / format_reasonable_interval.php
Created September 21, 2016 08:44
Human-readable (and reasonable) date-time interval format function in PHP.
/**
* Human-readable and reasonable date-time interval formatter
* ----------------------------------------------------------
* Author: Benyamin shoham
* -----------------------
* Format an interval to show existing components in a Human Readable fashion
* If the interval doesn't have a time component (years, months, etc)
* That component won't be displayed.
* You can decide how many components will be displayed (e.g. "1 year 2 months" = 2 components)
* You can select a delimiter to format the interval (e.g. "1 year aaaand 2 months"