Skip to content

Instantly share code, notes, and snippets.

Avatar

Benyamin Shoham benyaminshoham

View GitHub Profile
@benyaminshoham
benyaminshoham / format_reasonable_interval.php
Created Sep 21, 2016
Human-readable (and reasonable) date-time interval format function in PHP.
View format_reasonable_interval.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"
You can’t perform that action at this time.