time_parsers.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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$
  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. inline ptime from_iso_extended_string(const std::string& s) {
  30. if (s.size() == 10) { //assume we just have a date which is 10 chars
  31. gregorian::date d = gregorian::from_simple_string(s);
  32. return ptime( d );
  33. }
  34. return date_time::parse_delimited_time<ptime>(s, 'T');
  35. }
  36. } } //namespace posix_time
  37. #endif