Skip to content

Instantly share code, notes, and snippets.

@croisillon
Last active December 3, 2025 06:32
Show Gist options
  • Select an option

  • Save croisillon/2bf129e2577558bd147dd4be9adb5819 to your computer and use it in GitHub Desktop.

Select an option

Save croisillon/2bf129e2577558bd147dd4be9adb5819 to your computer and use it in GitHub Desktop.
Number of days in the month of the year
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