time_parsers.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef POSIXTIME_PARSERS_HPP___
  2. #define POSIXTIME_PARSERS_HPP___
  3. /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
  4. * Use, modification and distribution is subject to the
  5. * Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland
  8. * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $
  9. */
  10. #include "boost/date_time/gregorian/gregorian.hpp"
  11. #include "boost/date_time/time_parsing.hpp"
  12. #include "boost/date_time/posix_time/posix_time_types.hpp"
  13. namespace boost {
  14. namespace posix_time {
  15. //! Creates a time_duration object from a delimited string
  16. /*! Expected format for string is "[-]h[h][:mm][:ss][.fff]".
  17. * A negative duration will be created if the first character in
  18. * string is a '-', all other '-' will be treated as delimiters.
  19. * Accepted delimiters are "-:,.". */
  20. inline time_duration duration_from_string(const std::string& s) {
  21. return date_time::parse_delimited_time_duration<time_duration>(s);
  22. }
  23. inline ptime time_from_string(const std::string& s) {
  24. return date_time::parse_delimited_time<ptime>(s, ' ');
  25. }
  26. inline ptime from_iso_string(const std::string& s) {
  27. return date_time::parse_iso_time<ptime>(s, 'T');
  28. }
  29. } } //namespace posix_time
  30. #endif