Goby3  3.1.5a
2024.05.23
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"
33 #include "goby/time/system_clock.h"
34 #include "goby/util/as.h"
36 
38 namespace goby
39 {
41 namespace common
42 {
43 [[deprecated("use time::convert()")]] inline double
44 ptime2unix_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
50 unix_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
56 ptime2unix_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
62 unix_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 
68 namespace util
69 {
70 template <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
74 as(const From& from)
75 {
77 }
78 
79 template <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
83 as(const From& from)
84 {
86 }
87 
88 template <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 
98 template <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 
109 namespace common
110 {
111 template <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 
116 template <>
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 
123 template <>
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 
130 template <>
131 [[deprecated("use goby::time::SystemClock::now<boost::posix_time::ptime>()")]] inline boost::
132  posix_time::ptime
133  goby_time<boost::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
140  goby_time()
141 {
142  return goby_time<boost::posix_time::ptime>();
143 }
144 
146 template <>[[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
153 goby_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
179 nmea_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
goby::util::as
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
primitive_types.h
system_clock.h
goby::common::goby_time< double >
double goby_time< double >()
Definition: legacy.h:125
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
as.h
goby::common::ptime2time_t
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
goby::common::unix_microsec2ptime
boost::posix_time::ptime unix_microsec2ptime(std::uint64_t given_time)
Definition: legacy.h:62
goby::common::goby_time_as_string
std::string goby_time_as_string(const boost::posix_time::ptime &t=goby_time())
Simple string representation of goby_time()
Definition: legacy.h:153
goby::common::ptime2unix_microsec
std::uint64_t ptime2unix_microsec(boost::posix_time::ptime given_time)
Definition: legacy.h:56
goby::common::goby_file_timestamp
std::string goby_file_timestamp()
ISO string representation of goby_time()
Definition: legacy.h:159
goby::common::goby_time
ReturnType goby_time()
Definition: legacy.h:112
goby::common::time_t2ptime
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
jwt::json::type
type
Generic JSON types used in JWTs.
Definition: jwt.h:2071
convert.h
goby::common::ptime2unix_double
double ptime2unix_double(boost::posix_time::ptime given_time)
Definition: legacy.h:44
goby::common::nmea_time2ptime
boost::posix_time::ptime nmea_time2ptime(const std::string &mt)
Definition: legacy.h:179
goby::common::unix_double2ptime
boost::posix_time::ptime unix_double2ptime(double given_time)
Definition: legacy.h:50