Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lyokato/cpp-datetimelite
C++ library for parsing datetime formatted string
https://github.com/lyokato/cpp-datetimelite
Last synced: 18 days ago
JSON representation
C++ library for parsing datetime formatted string
- Host: GitHub
- URL: https://github.com/lyokato/cpp-datetimelite
- Owner: lyokato
- License: mit
- Created: 2011-01-23T04:58:46.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2011-01-24T15:34:28.000Z (almost 14 years ago)
- Last Synced: 2024-07-31T22:58:01.247Z (3 months ago)
- Language: C
- Homepage:
- Size: 336 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
=======================================================================
DESCRIPTION
=======================================================================
This library allows you to parse datetime formatted string, easily.=======================================================================
SYNOPSIS
=======================================================================
Two version is here
----------------------------------------------------------------------// 1. datetimelite.h
//
// you can parse many kinds of datetime-formatted-string with
// 'time_from_string' function which returns struct tm.
//
// And if passed string has format that is not supported, it throws
// std::invalid_argument
//
// This has no dependency on boost#include
using namespace datetimelite;
struct std::tm ts = time_from_string("Wed, 09 Feb 1994 22:23:32 GMT"); // HTTP format
struct std::tm ts = time_from_string("Tuesday, 08-Feb-94 14:15:29 GMT"); // old rfc850 HTTP format
struct std::tm ts = time_from_string("Tuesday, 08-Feb-1994 14:15:29 GMT"); // broken rfc850
struct std::tm ts = time_from_string("03/Feb/1994:17:03:55 -0700"); // common log file format
struct std::tm ts = time_from_string("09 Feb 1994 22:23:32 GMT"); // HTTP format no weekday
struct std::tm ts = time_from_string("08-Feb-94 14:15:29 GMT"); // rfc850 no weekday
struct std::tm ts = time_from_string("08-Feb-1994 14:15:29 GMT"); // broken rfc850 no weekdaystruct std::tm ts = time_from_string("1994-02-03 14:15:29 -0100"); // ISO8601
struct std::tm ts = time_from_string("1994-02-03 14:15:29"); // zone is optional
struct std::tm ts = time_from_string("1994-02-03"); // only date
struct std::tm ts = time_from_string("1994-02-03T14:15:29"); // use T separator
struct std::tm ts = time_from_string("19940203T141529Z"); // ISO8601 compact format
struct std::tm ts = time_from_string("19940203"); // only datestruct std::tm ts = time_from_string("08-Feb-94"); // old rfc850 no weekday, no time
struct std::tm ts = time_from_string("08-Feb-1994"); // broken rfc850 no weekday, no time
struct std::tm ts = time_from_string("09 Feb 1994"); // proposed new http format no weekday no time
struct std::tm ts = time_from_string("03/Feb/1994"); // common log file format no weekday, no timetry {
struct std::tm ts = time_from_string("invalid format");
} catch (std::exception& e) {
std::cout << "invalid format: " << e.what() << std::endl;
}// 2. datetimelite2.h
//
// function name 'time_from_string' is same as above,
// but the behavior is different
//
// that returns boost::optional object.
// So, if passed string has invalid-format, it doesn't throw, but
// returns boost::none.
//
// Of cource, this header depends on boost_date_time library#include
#include
#includeboost::optional t = datetimelite2::time_from_string("1994-02-03T14:15:29");
if (t) {
std::cout << boost::posix_time::to_simple_string(*p) << std::endl;
}=======================================================================
TODO
=======================================================================
More tests
ctime(3) format support
ANSI asctime format support
Unix 'ls -l' format support
Windows 'dir' format support=======================================================================
INSTALL
=======================================================================
This is header-only library.
So, copying datetimelite.h or datetimelite2.h into your project directory is the easiest way.or
1. cd build
2. cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Releaseparameters
- BUILD_SHARED_LIBS (ON|OFF)
- CMAKE_BUILD_TYPE (Debug|Release)
- CMAKE_INSTALL_PREFIX (/usr/local)3. make
4. make test
5. make install