Skip to content

Instantly share code, notes, and snippets.

@diolavr
Created September 28, 2016 11:39
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 diolavr/2bf129e2577558bd147dd4be9adb5819 to your computer and use it in GitHub Desktop.
Save diolavr/2bf129e2577558bd147dd4be9adb5819 to your computer and use it in GitHub Desktop.
sub days_inmonth_inyear {
my ( $x, $y ) = @_;
return 28 + ( ( $x + int( $x / 8 ) ) % 2 ) + 2 % $x + int(
( 1
+ ( 1 - ( $y % 4 + 2 ) % ( $y % 4 + 1 ) )
* ( ( $y % 100 + 2 ) % ( $y % 100 + 1 ) )
+ ( 1 - ( $y % 400 + 2 ) % ( $y % 400 + 1 ) )
) / $x
) + int( 1 / $x ) - int(
( ( 1 - ( $y % 4 + 2 ) % ( $y % 4 + 1 ) )
* ( ( $y % 100 + 2 ) % ( $y % 100 + 1 ) )
+ ( 1 - ( $y % 400 + 2 ) % ( $y % 400 + 1 ) )
) / $x
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment