2017-01-07 22:11:45 +01:00
|
|
|
/*
|
2019-08-19 22:15:56 +02:00
|
|
|
* Copyright 2014-2019 Max Kellermann <max.kellermann@gmail.com>
|
2017-01-07 22:11:45 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-05-08 15:47:58 +02:00
|
|
|
#include "Parser.hxx"
|
2019-08-19 22:21:22 +02:00
|
|
|
#include "Convert.hxx"
|
2017-01-07 22:11:45 +01:00
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
std::chrono::system_clock::time_point
|
|
|
|
ParseTimePoint(const char *s, const char *format)
|
|
|
|
{
|
|
|
|
assert(s != nullptr);
|
|
|
|
assert(format != nullptr);
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2017-01-07 22:11:45 +01:00
|
|
|
/* TODO: emulate strptime()? */
|
2017-02-20 21:44:01 +01:00
|
|
|
(void)s;
|
|
|
|
(void)format;
|
2017-01-07 22:11:45 +01:00
|
|
|
throw std::runtime_error("Time parsing not implemented on Windows");
|
|
|
|
#else
|
2019-08-19 22:09:38 +02:00
|
|
|
struct tm tm{};
|
2017-01-07 22:11:45 +01:00
|
|
|
const char *end = strptime(s, format, &tm);
|
|
|
|
if (end == nullptr || *end != 0)
|
|
|
|
throw std::runtime_error("Failed to parse time stamp");
|
|
|
|
|
2019-08-19 22:21:22 +02:00
|
|
|
return TimeGm(tm);
|
2017-12-12 10:22:20 +01:00
|
|
|
#endif /* !_WIN32 */
|
2017-01-07 22:11:45 +01:00
|
|
|
}
|