Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created May 25, 2012 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/2786048 to your computer and use it in GitHub Desktop.
Save shin1x1/2786048 to your computer and use it in GitHub Desktop.
<?php
$func = function($year) {
for ($month = 1 ; $month <= 12 ; $month++) {
echo date('Y-m-t', mktime(0,0,0, $month, 1, $year)).PHP_EOL;
}
};
$expected = <<<EOT
2000-01-31
2000-02-29
2000-03-31
2000-04-30
2000-05-31
2000-06-30
2000-07-31
2000-08-31
2000-09-30
2000-10-31
2000-11-30
2000-12-31
2001-01-31
2001-02-28
2001-03-31
2001-04-30
2001-05-31
2001-06-30
2001-07-31
2001-08-31
2001-09-30
2001-10-31
2001-11-30
2001-12-31
EOT;
ob_start();
$func(2000);
$func(2001);
$actual = ob_get_clean();
assert($expected === $actual);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment