home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / Time / DaysInMonth.pm < prev    next >
Encoding:
Perl POD Document  |  1996-03-27  |  1013 b   |  72 lines

  1. package Time::DaysInMonth;
  2.  
  3. use Carp;
  4.  
  5. require 5.000;
  6.  
  7. @ISA = qw(Exporter);
  8. @EXPORT = qw(days_in is_leapyear);
  9. @EXPORT_OK = qw(%mltable);
  10.  
  11. use strict;
  12.  
  13. use vars qw($VERSION %mltable);
  14.  
  15. $VERSION = 96.032702;
  16.  
  17. CONFIG:    {
  18.     %mltable = qw(
  19.          1    31
  20.          3    31
  21.          4    30
  22.          5    31
  23.          6    30
  24.          7    31
  25.          8    31
  26.          9    30
  27.         10    31
  28.         11    30
  29.         12    31);
  30. }
  31.  
  32. sub days_in
  33. {
  34.     # Month is 1..12
  35.     my ($year, $month) = @_;
  36.     return $mltable{$month+0} unless $month == 2;
  37.     return 28 unless &is_leap($year);
  38.     return 29;
  39. }
  40.  
  41. sub is_leap
  42. {
  43.     my ($year) = @_;
  44.     return 0 unless $year % 4 == 0;
  45.     return 1 unless $year % 100 == 0;
  46.     return 0 unless $year % 400 == 0;
  47.     return 1;
  48. }
  49.  
  50. 1;
  51.  
  52. __DATA__
  53.  
  54. =head1 NAME
  55.  
  56. Time::DaysInMonth -- simply report the number of days in a month
  57.  
  58. =head1 SYNOPSIS
  59.     
  60.     use Time::DaysInMonth;
  61.     $days = days_in($year, $month_1_to_12);
  62.     $leapyear = is_leap($year);
  63.  
  64. =head1 DESCRIPTION
  65.  
  66. DaysInMonth is simply a package to report the number of days in
  67. a month.  That's all it does.  Really!
  68.  
  69. =head1 AUTHOR
  70.  
  71. David Muir Sharnoff <muir@idiom.com>
  72.