Created
December 7, 2018 00:05
-
-
Save oropesa/07ac6f0532cb4f376b1ec03f0c38034a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In: . Out: 2018 | |
* In: 2018. Out: 2018 | |
* In: 2013. Out: 2013-18 | |
* In: 1998. Out: 1998-2018 | |
* | |
* @param string $year | |
* @return string | |
*/ | |
function get_website_year_start( $year ) { | |
switch( true ) { | |
case empty( $year ): //no year | |
case intval( $year ) == intval( date( 'Y' ) ): //same year | |
$html = date( 'Y' ); | |
break; | |
case substr( strval( $year ), 0, 2 ) === substr( strval( date( 'Y' ) ), 0, 2 ): //same century | |
$html = $year . '-' . substr( strval( date( 'Y' ) ), 2, 2 ); | |
break; | |
//diff years | |
default: | |
$html = $year . '-' . date( 'Y' ); | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment