iso3307.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#include "squid.h"
10#include "time/gadgets.h"
11
12#include <cctype>
13#include <cstring>
14
15#define ASCII_DIGIT(c) ((c)-48)
16
17time_t
18Time::ParseIso3307(const char *buf)
19{
20 /* buf is an ISO 3307 style time: YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx */
21 struct tm tms;
22 time_t t;
23 while (*buf == ' ' || *buf == '\t')
24 buf++;
25 if ((int) strlen(buf) < 14)
26 return 0;
27 memset(&tms, '\0', sizeof(struct tm));
28 tms.tm_year = (ASCII_DIGIT(buf[0]) * 1000) + (ASCII_DIGIT(buf[1]) * 100) +
29 (ASCII_DIGIT(buf[2]) * 10) + ASCII_DIGIT(buf[3]) - 1900;
30 tms.tm_mon = (ASCII_DIGIT(buf[4]) * 10) + ASCII_DIGIT(buf[5]) - 1;
31 tms.tm_mday = (ASCII_DIGIT(buf[6]) * 10) + ASCII_DIGIT(buf[7]);
32 tms.tm_hour = (ASCII_DIGIT(buf[8]) * 10) + ASCII_DIGIT(buf[9]);
33 tms.tm_min = (ASCII_DIGIT(buf[10]) * 10) + ASCII_DIGIT(buf[11]);
34 tms.tm_sec = (ASCII_DIGIT(buf[12]) * 10) + ASCII_DIGIT(buf[13]);
35#if HAVE_TIMEGM
36 t = timegm(&tms);
37#elif HAVE_MKTIME
38 t = mktime(&tms);
39#else
40 t = (time_t) 0;
41#endif
42 return t;
43}
44
#define ASCII_DIGIT(c)
Definition: iso3307.cc:15
time_t ParseIso3307(const char *)
Convert from ISO 3307 style time: YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx.
Definition: iso3307.cc:18

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors