0
  A   7ˆl–Ü4ý(&Ô¾R( *ËŒ¿q°©‹Fÿ�þDðÀ³r3(£�·üÿÔ„ ?Ó_ˆI|¥�+V[(Ä× (     7##---------------------------------------------------------------------------##
##  File:
##	$Id: mhtime.pl,v 2.10 2001/09/17 16:09:35 ehood Exp $
##  Author:
##      Earl Hood       mhonarc@mhonarc.org
##  Description:
##      Time related routines for mhonarc
##---------------------------------------------------------------------------##
##    Copyright (C) 1996-1999	Earl Hood, mhonarc@mhonarc.org
##
##    This program is free software; you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation; either version 2 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program; if not, write to the Free Software
##    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
##    02111-1307, USA
##---------------------------------------------------------------------------##

package mhonarc;

##---------------------------------------------------------------------------##
##      Date variables for date routines
##
my %Month2Num = (
    'jan', 0, 'feb', 1, 'mar', 2, 'apr', 3, 'may', 4, 'jun', 5, 'jul', 6,
    'aug', 7, 'sep', 8, 'oct', 9, 'nov', 10, 'dec', 11,
    'january', 0, 'february', 1, 'march', 2, 'april', 3,
    'may', 4, 'june', 5, 'july', 6, 'august', 7,
    'september', 8, 'october', 9, 'november', 10, 'december', 11,
);
my %WDay2Num = (
    'sun', 0, 'mon', 1, 'tue', 2, 'wed', 3, 'thu', 4, 'fri', 5, 'sat', 6,
    'sunday', 0, 'monday', 1, 'tuesday', 2, 'wednesday', 3, 'thursday', 4,
    'friday', 5, 'saturday', 6,
);

my @wdays = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
my @Wdays = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
	     'Friday', 'Saturday');
my @mons   = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
	      'Sep', 'Oct', 'Nov', 'Dec');
my @Mons   = ('January', 'February', 'March', 'April', 'May', 'June',
	      'July', 'August', 'September', 'October', 'November',
	      'December');

## The following used in parse_date() regexes
my $p_weekdays = 'Mon|Tue|Wed|Thu|Fri|Sat|Sun';
my $p_Weekdays = 'Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday';
my $p_months   = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec';
my $p_Months   = 'January|February|March|April|May|June|July|August'.
		 '|September|October|November|December';
my $p_hrminsec = '\d{1,2}:\d\d:\d\d';
my $p_hrmin    = '\d{1,2}:\d\d';
my $p_day      = '\d{1,2}';
my $p_year     = '\d\d\d\d|\d\d';

##---------------------------------------------------------------------------
##	Set weekday and month names.  This allows localization of
##	names.
##
sub set_date_names {
    my($in_wd, $in_Wd, $in_m, $in_M) = @_;
    @wdays = @$in_wd	if defined($in_wd) && scalar(@$in_wd);
    @Wdays = @$in_Wd	if defined($in_Wd) && scalar(@$in_Wd);
    @mons  = @$in_m 	if defined($in_m)  && scalar(@$in_m);
    @Mons  = @$in_M 	if defined($in_M)  && scalar(@$in_M);
}

##---------------------------------------------------------------------------
##	Get date in date(1)-like format.  $local flag is if local time
##	should be used.
##
sub getdate {
    &time2str('', time, $_[0]);
}

##---------------------------------------------------------------------------
##	Convert a calander time to a string.
##
sub time2str {
    my($fmt, $time, $local) = @_;
    my($date) = "";

    ## Get current date/time
    my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
	    ($local ? localtime($time) : gmtime($time));

    ## If format string blank, use default format
    if ($fmt !~ /\S/) {
	$fmt  = '%a %b %d %H:%M:%S';
	$fmt .= ' GMT'  unless $local;
	$fmt .= ' %Y';
    }

    POSIXMODCHK: {
	last  POSIXMODCH