DaysInMonth.pm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package Time::DaysInMonth;
  2. use Carp;
  3. require 5.000;
  4. @ISA = qw(Exporter);
  5. @EXPORT = qw(days_in is_leap);
  6. @EXPORT_OK = qw(%mltable);
  7. use strict;
  8. use vars qw($VERSION %mltable);
  9. $VERSION = 99.1117;
  10. CONFIG: {
  11. %mltable = qw(
  12. 1 31
  13. 3 31
  14. 4 30
  15. 5 31
  16. 6 30
  17. 7 31
  18. 8 31
  19. 9 30
  20. 10 31
  21. 11 30
  22. 12 31);
  23. }
  24. sub days_in
  25. {
  26. # Month is 1..12
  27. my ($year, $month) = @_;
  28. return $mltable{$month+0} unless $month == 2;
  29. return 28 unless &is_leap($year);
  30. return 29;
  31. }
  32. sub is_leap
  33. {
  34. my ($year) = @_;
  35. return 0 unless $year % 4 == 0;
  36. return 1 unless $year % 100 == 0;
  37. return 0 unless $year % 400 == 0;
  38. return 1;
  39. }
  40. 1;
  41. __END__
  42. =head1 NAME
  43. Time::DaysInMonth -- simply report the number of days in a month
  44. =head1 SYNOPSIS
  45. use Time::DaysInMonth;
  46. $days = days_in($year, $month_1_to_12);
  47. $leapyear = is_leap($year);
  48. =head1 DESCRIPTION
  49. DaysInMonth is simply a package to report the number of days in
  50. a month. That's all it does. Really!
  51. =head1 AUTHOR
  52. David Muir Sharnoff <[email protected]>
  53. =head1 BUGS
  54. This only deals with the "modern" calendar. Look elsewhere for
  55. historical time and date support.
  56. =head1 LICENSE
  57. Copyright (C) 1996-1999 David Muir Sharnoff. License hereby
  58. granted for anyone to use, modify or redistribute this module at
  59. their own risk. Please feed useful changes back to [email protected].