Mon Aug 31 12:30:09 2015

Asterisk developer's documentation


localtime.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2010, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  * Tilghman Lesher <tlesher AT digium DOT com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  * \brief Custom localtime functions for multiple timezones
00022  */
00023 
00024 #ifndef _ASTERISK_LOCALTIME_H
00025 #define _ASTERISK_LOCALTIME_H
00026 
00027 #ifdef HAVE_LOCALE_T_IN_LOCALE_H
00028 #include <locale.h>
00029 #elif defined(HAVE_LOCALE_T_IN_XLOCALE_H)
00030 #include <xlocale.h>
00031 #else
00032 typedef void * locale_t;
00033 #endif
00034 
00035 struct ast_tm {
00036    int tm_sec;             /*!< Seconds. [0-60] (1 leap second) */
00037    int tm_min;             /*!< Minutes. [0-59] */
00038    int tm_hour;            /*!< Hours.   [0-23] */
00039    int tm_mday;            /*!< Day.     [1-31] */
00040    int tm_mon;             /*!< Month.   [0-11] */
00041    int tm_year;            /*!< Year - 1900.  */
00042    int tm_wday;            /*!< Day of week. [0-6] */
00043    int tm_yday;            /*!< Days in year.[0-365]  */
00044    int tm_isdst;           /*!< DST.      [-1/0/1]*/
00045    long int tm_gmtoff;     /*!< Seconds east of UTC.  */
00046    char *tm_zone;          /*!< Timezone abbreviation.  */
00047    /* NOTE: do NOT reorder this final item.  The order needs to remain compatible with struct tm */
00048    int tm_usec;        /*!< microseconds */
00049 };
00050 
00051 /*!\brief Timezone-independent version of localtime_r(3).
00052  * \param timep Current time, including microseconds
00053  * \param p_tm Pointer to memory where the broken-out time will be stored
00054  * \param zone Text string of a standard system zoneinfo file.  If NULL, the system localtime will be used.
00055  * \retval p_tm is returned for convenience
00056  */
00057 struct ast_tm *ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone);
00058 
00059 void ast_get_dst_info(const time_t * const timep, int *dst_enabled, time_t *dst_start, time_t *dst_end, int *gmt_off, const char * const zone);
00060 
00061 /*!\brief Timezone-independent version of mktime(3).
00062  * \param tmp Current broken-out time, including microseconds
00063  * \param zone Text string of a standard system zoneinfo file.  If NULL, the system localtime will be used.
00064  * \retval A structure containing both seconds and fractional thereof since January 1st, 1970 UTC
00065  */
00066 struct timeval ast_mktime(struct ast_tm * const tmp, const char *zone);
00067 
00068 /*!\brief Set the thread-local representation of the current locale. */
00069 const char *ast_setlocale(const char *locale);
00070 
00071 /*!\brief Special version of strftime(3) that handles fractions of a second.
00072  * Takes the same arguments as strftime(3), with the addition of %q, which
00073  * specifies microseconds.
00074  * \param buf Address in memory where the resulting string will be stored.
00075  * \param len Size of the chunk of memory buf.
00076  * \param format A string specifying the format of time to be placed into buf.
00077  * \param tm Pointer to the broken out time to be used for the format.
00078  * \param locale Text string specifying the locale to be used for language strings.
00079  * \retval An integer value specifying the number of bytes placed into buf or -1 on error.
00080  */
00081 int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm);
00082 int ast_strftime_locale(char *buf, size_t len, const char *format, const struct ast_tm *tm, const char *locale);
00083 
00084 /*!\brief Special version of strptime(3) which places the answer in the common
00085  * structure ast_tm.  Also, unlike strptime(3), ast_strptime() initializes its
00086  * memory prior to use.
00087  * \param s A string specifying some portion of a date and time.
00088  * \param format The format in which the string, s, is expected.
00089  * \param tm The broken-out time structure into which the parsed data is expected.
00090  * \param locale Text string specifying the locale to be used for language strings.
00091  * \retval A pointer to the first character within s not used to parse the date and time.
00092  */
00093 char *ast_strptime(const char *s, const char *format, struct ast_tm *tm);
00094 char *ast_strptime_locale(const char *s, const char *format, struct ast_tm *tm, const char *locale);
00095 
00096 /*!\brief Wakeup localtime monitor thread
00097  * For use in testing.  Normally, the failsafe monitor thread waits 60 seconds
00098  * between checks to verify whether a timezone file has changed.  This routine
00099  * forces the monitor thread to wakeup immediately and check the timezone files.
00100  */
00101 struct ast_test;
00102 void ast_localtime_wakeup_monitor(struct ast_test *info);
00103 
00104 #endif /* _ASTERISK_LOCALTIME_H */

Generated on 31 Aug 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1