amiga-tz/library/time_local.c

122 lines
3.0 KiB
C

/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include "time_local.h"
#include "time_header.h"
const struct lc_time_T C_time_locale = {
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}, {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
}, {
"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"
}, {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
},
/* X_fmt */
"%H:%M:%S",
/*
** x_fmt
** C99 requires this format.
** Using just numbers (as here) makes Quakers happier;
** it's also compatible with SVR4.
*/
"%m/%d/%y",
/*
** c_fmt
** C99 requires this format.
** Previously this code used "%D %X", but we now conform to C99.
** Note that
** "%a %b %d %H:%M:%S %Y"
** is used by Solaris 2.3.
*/
"%a %b %e %T %Y",
/* am */
"AM",
/* pm */
"PM",
/* date_fmt */
"%a %b %e %H:%M:%S %Z %Y"
};
struct lc_time_T* openlc(locale_t locale)
{
int i, j;
struct lc_time_T *l = (struct lc_time_T*)AllocMem(
sizeof(struct lc_time_T),
MEMF_ANY | MEMF_CLEAR
);
struct Locale *loc = locale;
if (!loc) {
loc = OpenLocale(NULL);
}
l->X_fmt = loc->loc_TimeFormat;
l->x_fmt = loc->loc_ShortDateFormat;
l->c_fmt = loc->loc_DateTimeFormat;
l->am = GetLocaleStr(loc, AM_STR);
l->pm = GetLocaleStr(loc, PM_STR);
l->date_fmt = "%a %b %e %H:%M:%S %Z %Y";
j = 0;
for(i = 1; i < 8; i++) {
l->weekday[j++] = GetLocaleStr(loc, i);
}
j = 0;
for(i = 8; i < 15; i++) {
l->wday[j++] = GetLocaleStr(loc, i);
}
j = 0;
for(i = 15; i < 27; i++) {
l->month[j++] = GetLocaleStr(loc, i);
}
j = 0;
for(i = 27; i < 39; i++) {
l->mon[j++] = GetLocaleStr(loc, i);
}
l->locale = loc;
return l;
}
void closelc(struct lc_time_T *lc)
{
if (lc->locale) {
CloseLocale(lc->locale);
}
FreeMem(lc, sizeof(struct lc_time_T));
}