|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T U
Length: 2516 (0x9d4) Types: TextFile Names: »UTC2rfc.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Lib/format/UTC2rfc.c«
/* UTC2rfc.c - Converts a UTC struct into an RFC string */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/format/RCS/UTC2rfc.c,v 5.0 90/09/20 16:04:40 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Lib/format/RCS/UTC2rfc.c,v 5.0 90/09/20 16:04:40 pp Exp Locker: pp $ * * $Log: UTC2rfc.c,v $ * Revision 5.0 90/09/20 16:04:40 pp * rcsforce : 5.0 public release * */ #include "util.h" #include <isode/cmd_srch.h> #include <sys/time.h> #define UYEAR(x) ((x) >= 100 ? (x) - 1900 : (x)) #define YEAR(x) ((x) >= 100 ? (x) : (x) + 1900) #define dysize(x) (((x) % 4) ? 365 : (((x) % 100) ? 366 : \ (((x) % 400) ? 365 : 366))) static char *Day [] = { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri" }; extern int dmsize[]; extern CMD_TABLE tbl_month[]; extern time_t time (); extern int abs (); static int makewkday (); /* --------------------- Begin Routines -------------------------------- */ /* This routine produces a RFC 822 standard time string like: "Tue, 16 Aug 88 10:23:21 BST" from a UTC structure. */ int UTC2rfc (utc, buffer) UTC utc; char *buffer; { char zone[10]; int wday; *buffer = '\0'; if (utc == NULLUTC) { PP_LOG (LLOG_EXCEPTIONS, ("NULL UTC time")); return NOTOK; } if (utc -> ut_mon <= 0 || utc -> ut_mon > 12) { PP_LOG (LLOG_EXCEPTIONS, ("Lib/UTC2rfc zero UTC specified")); return NOTOK; } if (utc -> ut_flags & UT_ZONE) (void) sprintf (zone, "%c%02d%02d", utc -> ut_zone < 0 ? '-' : '+', abs(utc -> ut_zone / 60), abs(utc -> ut_zone % 60)); else (void) strcpy (zone, "+0000"); wday = makewkday (utc); if (wday < 0 || wday > 6) { PP_LOG (LLOG_EXCEPTIONS, ("Bad weekday calculated %d", wday)); return NOTOK; } (void) sprintf (buffer, "%s, %d %s %d %02d:%02d:%02d %s", Day [wday], utc -> ut_mday, rcmd_srch (utc -> ut_mon - 1, tbl_month), utc -> ut_year, utc -> ut_hour, utc -> ut_min, utc -> ut_sec, zone); PP_DBG (("Lib/UTC2rfc returns (%s)", buffer)); return OK; } static int makewkday (ut) UTC ut; { int year; int mon; int d; mon = ut -> ut_mon; year = YEAR (ut -> ut_year); d = 4 + year + (year+3)/4; if (year > 1800) { d -= (year - 1701)/100; d += (year - 1601)/400; } if (year > 1752) d += 3; if (dysize (year) == 366 && ut -> ut_mon >= 3) d ++; while (--mon) d += dmsize[mon - 1]; d += ut -> ut_mday; return (d % 7); }