		/* Copyright 2000-2004 The Apache Software Foundation
		 *
		 * Licensed under the Apache License, Version 2.0 (the "License");
		 * you may not use this file except in compliance with the License.
		 * You may obtain a copy of the License at
		 *
		 *     http://www.apache.org/licenses/LICENSE-2.0
		 *
		 * Unless required by applicable law or agreed to in writing, software
		 * distributed under the License is distributed on an "AS IS" BASIS,
		 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		 * See the License for the specific language governing permissions and
		 * limitations under the License.
		 */
		
		#include "apr_portable.h"
		#include "apr_time.h"
		#include "apr_lib.h"
		#include "apr_private.h"
		/* System Headers required for time library */
		#if APR_HAVE_SYS_TIME_H
		#include <sys/time.h>
		#endif
		#ifdef HAVE_TIME_H
		#include <time.h>
		#endif
		#if APR_HAVE_STRING_H
		#include <string.h>
		#endif
		/* End System Headers */
		
		APR_DECLARE_DATA const char apr_month_snames[12][4] =
		{
		    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
		};
		APR_DECLARE_DATA const char apr_day_snames[7][4] =
		{
		    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
		};
		
		apr_status_t apr_rfc822_date(char *date_str, apr_time_t t)
           1    {
           1        apr_time_exp_t xt;
           1        const char *s;
           1        int real_year;
		
           1        apr_time_exp_gmt(&xt, t);
		
		    /* example: "Sat, 08 Jan 2000 18:31:41 GMT" */
		    /*           12345678901234567890123456789  */
		
           1        s = &apr_day_snames[xt.tm_wday][0];
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = ',';
           1        *date_str++ = ' ';
           1        *date_str++ = xt.tm_mday / 10 + '0';
           1        *date_str++ = xt.tm_mday % 10 + '0';
           1        *date_str++ = ' ';
           1        s = &apr_month_snames[xt.tm_mon][0];
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = ' ';
           1        real_year = 1900 + xt.tm_year;
		    /* This routine isn't y10k ready. */
           1        *date_str++ = real_year / 1000 + '0';
           1        *date_str++ = real_year % 1000 / 100 + '0';
           1        *date_str++ = real_year % 100 / 10 + '0';
           1        *date_str++ = real_year % 10 + '0';
           1        *date_str++ = ' ';
           1        *date_str++ = xt.tm_hour / 10 + '0';
           1        *date_str++ = xt.tm_hour % 10 + '0';
           1        *date_str++ = ':';
           1        *date_str++ = xt.tm_min / 10 + '0';
           1        *date_str++ = xt.tm_min % 10 + '0';
           1        *date_str++ = ':';
           1        *date_str++ = xt.tm_sec / 10 + '0';
           1        *date_str++ = xt.tm_sec % 10 + '0';
           1        *date_str++ = ' ';
           1        *date_str++ = 'G';
           1        *date_str++ = 'M';
           1        *date_str++ = 'T';
           1        *date_str++ = 0;
           1        return APR_SUCCESS;
		}
		
		apr_status_t apr_ctime(char *date_str, apr_time_t t)
           1    {
           1        apr_time_exp_t xt;
           1        const char *s;
           1        int real_year;
		
		    /* example: "Wed Jun 30 21:49:08 1993" */
		    /*           123456789012345678901234  */
		
           1        apr_time_exp_lt(&xt, t);
           1        s = &apr_day_snames[xt.tm_wday][0];
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = ' ';
           1        s = &apr_month_snames[xt.tm_mon][0];
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = *s++;
           1        *date_str++ = ' ';
           1        *date_str++ = xt.tm_mday / 10 + '0';
           1        *date_str++ = xt.tm_mday % 10 + '0';
           1        *date_str++ = ' ';
           1        *date_str++ = xt.tm_hour / 10 + '0';
           1        *date_str++ = xt.tm_hour % 10 + '0';
           1        *date_str++ = ':';
           1        *date_str++ = xt.tm_min / 10 + '0';
           1        *date_str++ = xt.tm_min % 10 + '0';
           1        *date_str++ = ':';
           1        *date_str++ = xt.tm_sec / 10 + '0';
           1        *date_str++ = xt.tm_sec % 10 + '0';
           1        *date_str++ = ' ';
           1        real_year = 1900 + xt.tm_year;
           1        *date_str++ = real_year / 1000 + '0';
           1        *date_str++ = real_year % 1000 / 100 + '0';
           1        *date_str++ = real_year % 100 / 10 + '0';
           1        *date_str++ = real_year % 10 + '0';
           1        *date_str++ = 0;
		
           1        return APR_SUCCESS;
		}
		
		apr_status_t apr_strftime(char *s, apr_size_t *retsize, apr_size_t max, 
		                        const char *format, apr_time_exp_t *xt)
           3    {
           3        struct tm tm;
           3        memset(&tm, 0, sizeof tm);
           3        tm.tm_sec  = xt->tm_sec;
           3        tm.tm_min  = xt->tm_min;
           3        tm.tm_hour = xt->tm_hour;
           3        tm.tm_mday = xt->tm_mday;
           3        tm.tm_mon  = xt->tm_mon;
           3        tm.tm_year = xt->tm_year;
           3        tm.tm_wday = xt->tm_wday;
           3        tm.tm_yday = xt->tm_yday;
           3        tm.tm_isdst = xt->tm_isdst;
		#if defined(HAVE_GMTOFF)
           3        tm.tm_gmtoff = xt->tm_gmtoff;
		#elif defined(HAVE___OFFSET)
		    tm.__tm_gmtoff = xt->tm_gmtoff;
		#endif
           3        (*retsize) = strftime(s, max, format, &tm);
           3        return APR_SUCCESS;
		}
