Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
legacy.h
Go to the documentation of this file.
1// Copyright 2010-2021:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Toby Schneider <toby@gobysoft.org>
7//
8//
9// This file is part of the Goby Underwater Autonomy Project Libraries
10// ("The Goby Libraries").
11//
12// The Goby Libraries are free software: you can redistribute them and/or modify
13// them under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// The Goby Libraries are distributed in the hope that they will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with Goby. If not, see <http://www.gnu.org/licenses/>.
24
25#ifndef GOBY_TIME_LEGACY_H
26#define GOBY_TIME_LEGACY_H
27
28#include <ctime>
29#include <sys/time.h>
30
31
32#include "goby/time/convert.h"
34#include "goby/util/as.h"
36
38namespace goby
39{
41namespace common
42{
43[[deprecated("use time::convert()")]] inline double
44ptime2unix_double(boost::posix_time::ptime given_time)
45{
46 return time::convert<time::SITime>(given_time).value();
47}
48
49[[deprecated("use time::convert()")]] inline boost::posix_time::ptime
50unix_double2ptime(double given_time)
51{
52 return time::convert<boost::posix_time::ptime>(time::SITime::from_value(given_time));
53}
54
55[[deprecated("use time::convert()")]] inline std::uint64_t
56ptime2unix_microsec(boost::posix_time::ptime given_time)
57{
58 return time::convert<time::MicroTime>(given_time).value();
59}
60
61[[deprecated("use time::convert()")]] inline boost::posix_time::ptime
62unix_microsec2ptime(std::uint64_t given_time)
63{
64 return time::convert<boost::posix_time::ptime>(time::MicroTime::from_value(given_time));
65}
66} // namespace common
67
68namespace util
69{
70template <typename To, typename From>
71[[deprecated("use time::convert()")]] typename boost::enable_if<
72 boost::mpl::and_<boost::is_same<To, double>, boost::is_same<From, boost::posix_time::ptime> >,
73 To>::type
74as(const From& from)
75{
77}
78
79template <typename To, typename From>
80[[deprecated("use time::convert()")]] typename boost::enable_if<
81 boost::mpl::and_<boost::is_same<To, boost::posix_time::ptime>, boost::is_same<From, double> >,
82 To>::type
83as(const From& from)
84{
86}
87
88template <typename To, typename From>
89[[deprecated("use time::convert()")]]
90 typename boost::enable_if<boost::mpl::and_<boost::is_same<To, std::uint64_t>,
91 boost::is_same<From, boost::posix_time::ptime> >,
92 To>::type
93 as(const From& from)
94{
96}
97
98template <typename To, typename From>
99[[deprecated("use time::convert()")]]
100 typename boost::enable_if<boost::mpl::and_<boost::is_same<To, boost::posix_time::ptime>,
101 boost::is_same<From, std::uint64_t> >,
102 To>::type
103 as(const From& from)
104{
106}
107} // namespace util
108
109namespace common
110{
111template <typename ReturnType>
112[[deprecated("use goby::time::SystemClock::now()")]] ReturnType goby_time() {
113 static_assert(sizeof(ReturnType) == 0, "Invalid ReturnType for goby_time<>()");
114}
115
116template <>
117[[deprecated("use goby::time::SystemClock::now<goby::time::MicroTime>().value()")]] inline std::
118 uint64_t goby_time<std::uint64_t>()
119{
120 return goby::time::SystemClock::now<time::MicroTime>().value();
121}
122
123template <>
124[[deprecated("use goby::time::SystemClock::now<goby::time::SITime>().value()")]] inline double
126{
127 return static_cast<double>(goby_time<std::uint64_t>()) / 1.0e6;
128}
129
130template <>
131[[deprecated("use goby::time::SystemClock::now<boost::posix_time::ptime>()")]] inline boost::
132 posix_time::ptime
134{
135 return util::as<boost::posix_time::ptime>(goby_time<std::uint64_t>());
136}
137
138[[deprecated("use goby::time::SystemClock::now<boost::posix_time::ptime>()")]] inline boost::
139 posix_time::ptime
144
146template <>[[deprecated("use goby::time::str()")]] inline std::string goby_time<std::string>()
147{
148 return goby::util::as<std::string>(goby_time<boost::posix_time::ptime>());
149}
150
152[[deprecated("use goby::time::str()")]] inline std::string
153goby_time_as_string(const boost::posix_time::ptime& t = goby_time())
154{
155 return goby::util::as<std::string>(t);
156}
157
159[[deprecated("use goby::time::file_str()")]] inline std::string goby_file_timestamp()
160{
161 using namespace boost::posix_time;
162 return to_iso_string(second_clock::universal_time());
163}
164
166[[deprecated]] inline boost::posix_time::ptime time_t2ptime(std::time_t t)
167{
168 return boost::posix_time::from_time_t(t);
169}
170
172[[deprecated]] inline std::time_t ptime2time_t(boost::posix_time::ptime t)
173{
174 std::tm out = boost::posix_time::to_tm(t);
175 return mktime(&out);
176}
177
178[[deprecated("use convert_from_nmea")]] inline boost::posix_time::ptime
179nmea_time2ptime(const std::string& mt)
180{
181 return time::convert_from_nmea<boost::posix_time::ptime>(mt);
182}
183
184} // namespace common
185} // namespace goby
186
187#endif
boost::posix_time::ptime nmea_time2ptime(const std::string &mt)
Definition legacy.h:179
double ptime2unix_double(boost::posix_time::ptime given_time)
Definition legacy.h:44
std::string goby_time< std::string >()
Returns current UTC time as a human-readable string.
Definition legacy.h:146
ReturnType goby_time()
Definition legacy.h:112
std::time_t ptime2time_t(boost::posix_time::ptime t)
convert from ptime to time_t from time.h (whole seconds since UNIX)
Definition legacy.h:172
double goby_time< double >()
Definition legacy.h:125
std::uint64_t ptime2unix_microsec(boost::posix_time::ptime given_time)
Definition legacy.h:56
boost::posix_time::ptime goby_time< boost::posix_time::ptime >()
Definition legacy.h:133
boost::posix_time::ptime unix_microsec2ptime(std::uint64_t given_time)
Definition legacy.h:62
boost::posix_time::ptime unix_double2ptime(double given_time)
Definition legacy.h:50
std::string goby_file_timestamp()
ISO string representation of goby_time()
Definition legacy.h:159
boost::posix_time::ptime time_t2ptime(std::time_t t)
convert to ptime from time_t from time.h (whole seconds since UNIX)
Definition legacy.h:166
std::uint64_t goby_time< std::uint64_t >()
Definition legacy.h:118
std::string goby_time_as_string(const boost::posix_time::ptime &t=goby_time())
Simple string representation of goby_time()
Definition legacy.h:153
boost::enable_if< boost::mpl::and_< boost::is_same< To, double >, boost::is_same< From, boost::posix_time::ptime > >, To >::type as(const From &from)
Definition legacy.h:74
The global namespace for the Goby project.