1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include "apr_portable.h"
20
#include "apr_private.h"
21
/* System Headers required for time library */
22
#if APR_HAVE_SYS_TIME_H
31
/* End System Headers */
33
APR_DECLARE_DATA const char apr_month_snames[12][4] =
35
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
37
APR_DECLARE_DATA const char apr_day_snames[7][4] =
39
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
42
apr_status_t apr_rfc822_date(char *date_str, apr_time_t t)
48
apr_time_exp_gmt(&xt, t);
50
/* example: "Sat, 08 Jan 2000 18:31:41 GMT" */
51
/* 12345678901234567890123456789 */
53
s = &apr_day_snames[xt.tm_wday][0];
59
*date_str++ = xt.tm_mday / 10 + '0';
60
*date_str++ = xt.tm_mday % 10 + '0';
62
s = &apr_month_snames[xt.tm_mon][0];
67
real_year = 1900 + xt.tm_year;
68
/* This routine isn't y10k ready. */
69
*date_str++ = real_year / 1000 + '0';
70
*date_str++ = real_year % 1000 / 100 + '0';
71
*date_str++ = real_year % 100 / 10 + '0';
72
*date_str++ = real_year % 10 + '0';
74
*date_str++ = xt.tm_hour / 10 + '0';
75
*date_str++ = xt.tm_hour % 10 + '0';
77
*date_str++ = xt.tm_min / 10 + '0';
78
*date_str++ = xt.tm_min % 10 + '0';
80
*date_str++ = xt.tm_sec / 10 + '0';
81
*date_str++ = xt.tm_sec % 10 + '0';
90
apr_status_t apr_ctime(char *date_str, apr_time_t t)
96
/* example: "Wed Jun 30 21:49:08 1993" */
97
/* 123456789012345678901234 */
99
apr_time_exp_lt(&xt, t);
100
s = &apr_day_snames[xt.tm_wday][0];
105
s = &apr_month_snames[xt.tm_mon][0];
110
*date_str++ = xt.tm_mday / 10 + '0';
111
*date_str++ = xt.tm_mday % 10 + '0';
113
*date_str++ = xt.tm_hour / 10 + '0';
114
*date_str++ = xt.tm_hour % 10 + '0';
116
*date_str++ = xt.tm_min / 10 + '0';
117
*date_str++ = xt.tm_min % 10 + '0';
119
*date_str++ = xt.tm_sec / 10 + '0';
120
*date_str++ = xt.tm_sec % 10 + '0';
122
real_year = 1900 + xt.tm_year;
123
*date_str++ = real_year / 1000 + '0';
124
*date_str++ = real_year % 1000 / 100 + '0';
125
*date_str++ = real_year % 100 / 10 + '0';
126
*date_str++ = real_year % 10 + '0';
132
apr_status_t apr_strftime(char *s, apr_size_t *retsize, apr_size_t max,
133
const char *format, apr_time_exp_t *xt)
136
memset(&tm, 0, sizeof tm);
137
tm.tm_sec = xt->tm_sec;
138
tm.tm_min = xt->tm_min;
139
tm.tm_hour = xt->tm_hour;
140
tm.tm_mday = xt->tm_mday;
141
tm.tm_mon = xt->tm_mon;
142
tm.tm_year = xt->tm_year;
143
tm.tm_wday = xt->tm_wday;
144
tm.tm_yday = xt->tm_yday;
145
tm.tm_isdst = xt->tm_isdst;
146
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
147
tm.tm_gmtoff = xt->tm_gmtoff;
148
#elif defined(HAVE_STRUCT_TM___TM_GMTOFF)
149
tm.__tm_gmtoff = xt->tm_gmtoff;
151
(*retsize) = strftime(s, max, format, &tm);