/******************************************************************************* * c0xtimezone.h * Proposed ISO/IEC C 200X timezone types and functions. * * This source file implements several proposed timezone functions as a * proof of concept; most of the algorithms used are for illustration * purposes only and are not meant for production-quality systems. * * Author * This code was written by David R. Tribble (david@tribble.com), Jul 2004. * It is hereby placed into the public domain, and may be used for all * purposes, both commercial and private. No warranty is provided for this * source code, and the author cannot be held liable for its use in any * way. * * References * * * * See also * c0xcalendar.h * c0xlongtime.h * c0xtimezone.c * * Since * 2004-07-12 */ #ifndef c0x_timezone_h #define c0x_timezone_h 204 /* Identification */ #ifndef NO_H_IDENT static const char c0x_timezone_h_rev[] = "@(#)drt/text/stdc/c0xtimezone.h $Revision: 1.6 $ $Date: 2009/10/10 15:34:12 $"; #endif /* System includes */ #ifndef _stdc_limits_h #include #define _stdc_limits_h 1 #endif /* Local includes */ struct calendar; /******************************************************************************* * Public constants *******************************************************************************/ #define _TZ_ERROR LONG_MIN /* Timezone error */ /******************************************************************************* * Public types *******************************************************************************/ /*------------------------------------------------------------------------------ * struct timezone * Contains information about a compound timezone, which contains one or * more DST-adjusted simple timezones. * * Since * 1.1, 2004-07-12 */ #define _C0X_TIMEZONE_VS 20091008 /* Struct version */ struct timezone { int tz__vers; /* Struct version */ long int tz_offset; /* Offset, msec east of UTC */ struct { char z_name[15+1]; /* Zone+DST name */ int z_dst; /* DST adjustment, sec */ } tz_z[2]; /* DST-adjusted zones */ }; /******************************************************************************* * Public variables *******************************************************************************/ extern const struct timezone _c0x_timezone_utc; /******************************************************************************* * Public functions *******************************************************************************/ /*------------------------------------------------------------------------------ * inittimezone() * Find a supported timezone with a name matching a given string. * * Parameter zone * Pointer to a timezone object, which is filled (initialized) with the * appropriate information for a timezone matching the name 'name'. * * Parameter name * The name or abbreviated name of a timezone. If this is empty ("") or * null, the local timezone is used (as determined by the value of the "TZ" * environment variable). * * If the name is "Z", a timezone with zero offset from UTC and no DST * adjustments is used. * * The timezone name can be of the form "XXX[[s]n[YYY[[s]m]]", * where: * XXX is the abbreviated non-DST timezone name; * s is an optional "+" (west) or "-" (east) character; * n is a number specifying the hours offset from UTC; * YYY is the abbreviated DST timezone name; * s is an optional "+" (west) or "-" (east) character; * m is a number specifying the DST hours offset from UTC. * * The timezone name can also be of the form "N[D]", where N and D are of * the form "[s][h]h[[:]mm[[:]ss]]", and where: * s is an optional "+" (east) or "-" (west) sign character; * hh is the number of hours offset from UTC; * mm is the optional number of minutes offset from UTC; * ss is the optional number of seconds offset from UTC. * * Thus the names "CST6" and "-0600" specify the same timezone, having a * 6 hour offset west of UTC and no DST adjustments. The name "CST6CDT" * specifies a timezone named "CST" having a 6 hour offset west of UTC * and a one-hour DST-adjusted (5 hour offset) name of "CDT". * * Returns * Zero on success, otherwise -1 on error. * * Since * 1.1, 2004-07-12 */ extern int inittimezone(struct timezone *zone, const char *name); /*------------------------------------------------------------------------------ * mktimezonename() * Construct a compound timezone name from a timezone object. * * Parameter buf * Points to a character array that will be filled with at most 'max' * characters, representing the constructed compound timezone name. * This pointer cannot be null. * * Parameter max * Specifies the maximum number of characters, including a terminating null * character, that can be placed into the character array pointed to by * 'buf'. * * Parameter zone * Pointer to a timezone object. * * Returns * The number of characters, not including the terminating null character, * written into the array pointed to by 'buf' on success (which will not be * greater than 'max'), or -1 if an error occurs. */ extern int mktimezonename(char *buf, size_t max, const struct timezone *zone); /*------------------------------------------------------------------------------ * timezonedst() * Determine the DST adjustment to make to a specified calendar date for a * specified timezone. * * Parameter date * Points to a calendar date object. * * Parameter zone * Points to a timezone object. * This can be null, in which case zero is returned. * * Returns * The index of the DST adjustment (.tz_z[i]) to apply, or -1 on error. * * Since * 1.1, 2004-07-12 */ extern int timezonedst(const struct calendar *date, const struct timezone *zone); /*------------------------------------------------------------------------------ * timezoneoffset() * Determine the offset in milliseconds east of UTC of the time represented * by a timezone+DST combination for a given calendar date. * * Parameter date * Points to a calendar date object. * * Parameter zone * Points to a timezone object. * This can be null, in which case zero is returned. * * Returns * The number of milliseconds offset east of UTC of the calendar date * object, or '_TZ_ERROR' on error. * * Since * 1.1, 2004-07-12 */ extern long int timezoneoffset(const struct calendar *date, const struct timezone *zone); #endif /* c0x_timezone_h */ /* End c0xtimezone.h */