Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AceTimeConverter.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2006-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Erik Adolfsson / sterad
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #ifndef __DOUF_ACE_TIME_CONVERTER_H
25 #define __DOUF_ACE_TIME_CONVERTER_H
26 
27 #include <ace/Time_Value.h>
30 
31 //disable warnings in boost
32 #if defined _MSC_VER
33  #pragma warning (push)
34  #pragma warning (disable : 4127)
35 #endif
36 
37 #include <boost/date_time/posix_time/posix_time.hpp>
38 
39 //and enable the warnings again
40 #if defined _MSC_VER
41  #pragma warning (pop)
42 #endif
43 
44 namespace Safir
45 {
46 namespace Time
47 {
48 
53  {
54  public:
55 
62  static ACE_Time_Value ToAceTime(const Safir::Dob::Typesystem::Si64::Second time);
63 
70  static ACE_Time_Value ToAceTime(const boost::posix_time::time_duration & duration);
71 
78  static ACE_Time_Value ToAceTime(const boost::posix_time::ptime & time);
79 
86  static Safir::Dob::Typesystem::Si64::Second ToDouble(const ACE_Time_Value & time);
87 
94  static boost::posix_time::ptime ToPtime(const ACE_Time_Value & utcTime);
95 
96  };
97 
98  inline ACE_Time_Value AceTimeConverter::ToAceTime(const boost::posix_time::time_duration & duration)
99  {
100  if (boost::posix_time::time_duration::num_fractional_digits() == 6)
101  {
102  return ACE_Time_Value(static_cast<time_t>(duration.total_seconds()),
103  static_cast<suseconds_t>(duration.fractional_seconds()));
104  }
105  else
106  {
107  return ACE_Time_Value(static_cast<time_t>(duration.total_seconds()),
108  static_cast<suseconds_t>(duration.fractional_seconds()
109  * pow(1.0, boost::posix_time::time_duration::num_fractional_digits() -6)));
110  }
111  }
112 
114  {
115  return ACE_Time_Value(static_cast<suseconds_t>(time),
116  static_cast<suseconds_t>((time - Safir::Dob::Typesystem::Int64(time)) * pow (10.0,6)));
117  }
118 
119  inline ACE_Time_Value AceTimeConverter::ToAceTime(const boost::posix_time::ptime & time)
120  {
121  return ToAceTime(TimeProvider::ToDouble(time));
122  }
123 
125  {
126  return time.sec() + (time.usec() / pow (10.0,6));
127  }
128 
129  inline boost::posix_time::ptime AceTimeConverter::ToPtime(const ACE_Time_Value & time)
130  {
131  return TimeProvider::ToPtime(ToDouble(time));
132  }
133 
134 
135 }; // namespace Time
136 }; // namespace Safir
137 
138 #endif //__DOUF_ACE_TIME_CONVERTER_H
static boost::posix_time::ptime ToPtime(const Safir::Dob::Typesystem::Si64::Second utcTime)
Get specified UTC time in boost::posix_time::ptime representation.
static ACE_Time_Value ToAceTime(const Safir::Dob::Typesystem::Si64::Second time)
Get specified time in ACE Time representation.
Definition: AceTimeConverter.h:113
static Safir::Dob::Typesystem::Si64::Second ToDouble(const boost::posix_time::ptime &utcTime)
Convert specified UTC time to a Double.
DotsC_Int64 Int64
64 bit integer type.
Definition: Defs.h:70
Float64 Second
64 bit representation of Second.
Definition: Defs.h:198
static boost::posix_time::ptime ToPtime(const ACE_Time_Value &utcTime)
Get specified ACE time in boost::posix_time::ptime representation.
Definition: AceTimeConverter.h:129
The AceTimeConverter class provides functions to convert to/from ACE time.
Definition: AceTimeConverter.h:52
static Safir::Dob::Typesystem::Si64::Second ToDouble(const ACE_Time_Value &time)
Convert specified ACE time to a Double.
Definition: AceTimeConverter.h:124