return time stamp of YYYYMMDDHHMMSS */
| 284 | |
| 285 | /* return time stamp of YYYYMMDDHHMMSS */ |
| 286 | int ms_extract_time(str *time_str, int *time_val) |
| 287 | { |
| 288 | struct tm stm; |
| 289 | int i; |
| 290 | |
| 291 | if(time_str==NULL || time_str->s==NULL |
| 292 | || time_str->len<=0 || time_val==NULL) |
| 293 | { |
| 294 | LM_ERR("bad parameters\n"); |
| 295 | return -1; |
| 296 | } |
| 297 | |
| 298 | memset(&stm, 0, sizeof(struct tm)); |
| 299 | for(i=0; i<time_str->len; i++) |
| 300 | { |
| 301 | if(time_str->s[i]<'0' || time_str->s[i]>'9') |
| 302 | { |
| 303 | LM_ERR("bad time [%.*s]\n", time_str->len, time_str->s); |
| 304 | return -1; |
| 305 | } |
| 306 | switch(i) |
| 307 | { |
| 308 | case 0: |
| 309 | if(time_str->s[i]<'2') |
| 310 | { |
| 311 | LM_ERR("bad year in time [%.*s]\n", |
| 312 | time_str->len, time_str->s); |
| 313 | return -1; |
| 314 | } |
| 315 | stm.tm_year += 1000*(time_str->s[i]-'0') - 1900; |
| 316 | break; |
| 317 | case 1: |
| 318 | stm.tm_year += 100*(time_str->s[i]-'0'); |
| 319 | break; |
| 320 | case 2: |
| 321 | stm.tm_year += 10*(time_str->s[i]-'0'); |
| 322 | break; |
| 323 | case 3: |
| 324 | stm.tm_year += (time_str->s[i]-'0'); |
| 325 | break; |
| 326 | case 4: |
| 327 | if(time_str->s[i]>'1') |
| 328 | { |
| 329 | LM_ERR("bad month in time[%.*s]\n", |
| 330 | time_str->len, time_str->s); |
| 331 | return -1; |
| 332 | } |
| 333 | stm.tm_mon += 10*(time_str->s[i]-'0') - 1; |
| 334 | break; |
| 335 | case 5: |
| 336 | if((time_str->s[i-1]=='0' && time_str->s[i]=='0') |
| 337 | || (time_str->s[i-1]=='1' && time_str->s[i]>'2')) |
| 338 | { |
| 339 | LM_ERR("bad month in time[%.*s]\n", |
| 340 | time_str->len, time_str->s); |
| 341 | return -1; |
| 342 | } |
| 343 | stm.tm_mon += (time_str->s[i]-'0'); |