Go to the source code of this file.
Data Structures | |
struct | ast_tm |
Functions | |
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) |
ast_tm * | ast_localtime (const struct timeval *timep, struct ast_tm *p_tm, const char *zone) |
timeval | ast_mktime (struct ast_tm *const tmp, const char *zone) |
int | ast_strftime (char *buf, size_t len, const char *format, const struct ast_tm *tm) |
Definition in file localtime.h.
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 | |||
) |
Definition at line 1155 of file localtime.c.
References ast_tzset(), state::ats, AVGSECSPERYEAR, state::goahead, state::goback, state::timecnt, ttinfo::tt_gmtoff, ttinfo::tt_isdst, state::ttis, state::typecnt, state::types, and YEARSPERREPEAT.
Referenced by set_timezone_variables().
01156 { 01157 int i; 01158 int transition1 = -1; 01159 int transition2 = -1; 01160 time_t seconds; 01161 int bounds_exceeded = 0; 01162 time_t t = *timep; 01163 const struct state *sp; 01164 01165 if (NULL == dst_enabled) 01166 return; 01167 *dst_enabled = 0; 01168 01169 if (NULL == dst_start || NULL == dst_end || NULL == gmt_off) 01170 return; 01171 01172 *gmt_off = 0; 01173 01174 sp = ast_tzset(zone); 01175 if (NULL == sp) 01176 return; 01177 01178 /* If the desired time exceeds the bounds of the defined time transitions 01179 * then give give up on determining DST info and simply look for gmt offset 01180 * This requires that I adjust the given time using increments of Gregorian 01181 * repeats to place the time within the defined time transitions in the 01182 * timezone structure. 01183 */ 01184 if ((sp->goback && t < sp->ats[0]) || 01185 (sp->goahead && t > sp->ats[sp->timecnt - 1])) { 01186 time_t tcycles; 01187 int_fast64_t icycles; 01188 01189 if (t < sp->ats[0]) 01190 seconds = sp->ats[0] - t; 01191 else seconds = t - sp->ats[sp->timecnt - 1]; 01192 --seconds; 01193 tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR; 01194 ++tcycles; 01195 icycles = tcycles; 01196 if (tcycles - icycles >= 1 || icycles - tcycles >= 1) 01197 return; 01198 seconds = icycles; 01199 seconds *= YEARSPERREPEAT; 01200 seconds *= AVGSECSPERYEAR; 01201 if (t < sp->ats[0]) 01202 t += seconds; 01203 else 01204 t -= seconds; 01205 01206 if (t < sp->ats[0] || t > sp->ats[sp->timecnt - 1]) 01207 return; /* "cannot happen" */ 01208 01209 bounds_exceeded = 1; 01210 } 01211 01212 if (sp->timecnt == 0 || t < sp->ats[0]) { 01213 /* I have no transition times or I'm before time */ 01214 *dst_enabled = 0; 01215 /* Find where I can get gmtoff */ 01216 i = 0; 01217 while (sp->ttis[i].tt_isdst) 01218 if (++i >= sp->typecnt) { 01219 i = 0; 01220 break; 01221 } 01222 *gmt_off = sp->ttis[i].tt_gmtoff; 01223 return; 01224 } 01225 01226 for (i = 1; i < sp->timecnt; ++i) { 01227 if (t < sp->ats[i]) { 01228 transition1 = sp->types[i - 1]; 01229 transition2 = sp->types[i]; 01230 break; 01231 } 01232 } 01233 /* if I found transition times that do not bounded the given time and these correspond to 01234 or the bounding zones do not reflect a changes in day light savings, then I do not have dst active */ 01235 if (i >= sp->timecnt || 0 > transition1 || 0 > transition2 || 01236 (sp->ttis[transition1].tt_isdst == sp->ttis[transition2].tt_isdst)) { 01237 *dst_enabled = 0; 01238 *gmt_off = sp->ttis[sp->types[sp->timecnt -1]].tt_gmtoff; 01239 } else { 01240 /* I have valid daylight savings information. */ 01241 if(sp->ttis[transition2].tt_isdst) 01242 *gmt_off = sp->ttis[transition1].tt_gmtoff; 01243 else 01244 *gmt_off = sp->ttis[transition2].tt_gmtoff; 01245 01246 /* If I adjusted the time earlier, indicate that the dst is invalid */ 01247 if (!bounds_exceeded) { 01248 *dst_enabled = 1; 01249 /* Determine which of the bounds is the start of daylight savings and which is the end */ 01250 if(sp->ttis[transition2].tt_isdst) { 01251 *dst_start = sp->ats[i]; 01252 *dst_end = sp->ats[i -1]; 01253 } else { 01254 *dst_start = sp->ats[i -1]; 01255 *dst_end = sp->ats[i]; 01256 } 01257 } 01258 } 01259 return; 01260 }
struct ast_tm* ast_localtime | ( | const struct timeval * | timep, | |
struct ast_tm * | p_tm, | |||
const char * | zone | |||
) |
Definition at line 1140 of file localtime.c.
References ast_tzset(), and localsub().
Referenced by acf_strftime(), action_corestatus(), append_date(), ast_check_timing(), ast_log(), ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_ge(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_nl(), ast_say_date_pt(), ast_say_date_th(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_gr(), ast_say_date_with_format_he(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_th(), ast_say_date_with_format_tw(), ast_say_datetime_de(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_ge(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_pt(), ast_say_datetime_ge(), ast_say_datetime_gr(), ast_say_datetime_he(), ast_say_datetime_hu(), ast_say_datetime_nl(), ast_say_datetime_pt(), ast_say_datetime_pt_BR(), ast_say_datetime_th(), ast_say_datetime_tw(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_ge(), ast_say_time_gr(), ast_say_time_he(), ast_say_time_hu(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_th(), ast_say_time_tw(), ast_verbose(), build_device(), build_radius_record(), callerid_genmsg(), cdr_get_tv(), cli_prompt(), do_scheduler(), enc_ie_date(), find_conf_realtime(), get_date(), handle_minivm_show_stats(), handle_show_settings(), handle_time_date_req_message(), httpd_helper_thread(), iax2_datetime(), isodate(), leave_voicemail(), main(), make_email_file(), manager_log(), packdate(), pgsql_log(), phone_call(), phoneprov_callback(), play_message_datetime(), prep_email_sub_vars(), prepare_cb(), rpt_tele_thread(), say_date_generic(), send_date_time(), send_date_time2(), send_date_time3(), sendmail(), set_timezone_variables(), sip_show_registry(), sms_compose2(), sms_handleincoming_proto2(), sqlite_log(), static_callback(), timeout_write(), transmit_notify_request_with_callerid(), vmu_tm(), write_history(), and write_metadata().
01141 { 01142 const struct state *sp = ast_tzset(zone); 01143 memset(tmp, 0, sizeof(*tmp)); 01144 return sp ? localsub(timep, 0L, tmp, sp) : NULL; 01145 }
struct timeval ast_mktime | ( | struct ast_tm *const | tmp, | |
const char * | zone | |||
) |
Definition at line 1755 of file localtime.c.
References ast_tzset(), localsub(), and time1().
Referenced by acf_strptime(), find_conf_realtime(), sms_handleincoming_proto2(), sms_readfile(), and unpackdate().
01756 { 01757 const struct state *sp; 01758 if (!(sp = ast_tzset(zone))) 01759 return WRONG; 01760 return time1(tmp, localsub, 0L, sp); 01761 }
int ast_strftime | ( | char * | buf, | |
size_t | len, | |||
const char * | format, | |||
const struct ast_tm * | tm | |||
) |
Definition at line 1763 of file localtime.c.
References ast_calloc, ast_free, ast_realloc, format, and ast_tm::tm_usec.
Referenced by acf_strftime(), action_corestatus(), append_date(), ast_log(), ast_verbose(), build_radius_record(), cdr_get_tv(), cli_prompt(), dump_datetime(), find_conf_realtime(), get_date(), handle_minivm_show_stats(), handle_show_settings(), httpd_helper_thread(), isodate(), leave_voicemail(), make_email_file(), manager_log(), pgsql_log(), phoneprov_callback(), prep_email_sub_vars(), prepare_cb(), sendmail(), sendpage(), sip_show_registry(), sqlite_log(), static_callback(), timeout_write(), and write_metadata().
01764 { 01765 size_t fmtlen = strlen(tmp) + 1; 01766 char *format = ast_calloc(1, fmtlen), *fptr = format, *newfmt; 01767 int decimals = -1, i, res; 01768 long fraction; 01769 01770 if (!format) 01771 return -1; 01772 for (; *tmp; tmp++) { 01773 if (*tmp == '%') { 01774 switch (tmp[1]) { 01775 case '1': 01776 case '2': 01777 case '3': 01778 case '4': 01779 case '5': 01780 case '6': 01781 if (tmp[2] != 'q') 01782 goto defcase; 01783 decimals = tmp[1] - '0'; 01784 tmp++; 01785 /* Fall through */ 01786 case 'q': /* Milliseconds */ 01787 if (decimals == -1) 01788 decimals = 3; 01789 01790 /* Juggle some memory to fit the item */ 01791 newfmt = ast_realloc(format, fmtlen + decimals); 01792 if (!newfmt) { 01793 ast_free(format); 01794 return -1; 01795 } 01796 fptr = fptr - format + newfmt; 01797 format = newfmt; 01798 fmtlen += decimals; 01799 01800 /* Reduce the fraction of time to the accuracy needed */ 01801 for (i = 6, fraction = tm->tm_usec; i > decimals; i--) 01802 fraction /= 10; 01803 fptr += sprintf(fptr, "%0*ld", decimals, fraction); 01804 01805 /* Reset, in case more than one 'q' specifier exists */ 01806 decimals = -1; 01807 tmp++; 01808 break; 01809 default: 01810 goto defcase; 01811 } 01812 } else 01813 defcase: *fptr++ = *tmp; 01814 } 01815 *fptr = '\0'; 01816 #undef strftime 01817 res = (int)strftime(buf, len, format, (struct tm *)tm); 01818 ast_free(format); 01819 return res; 01820 }