1 // <date_time> -*- C++ -*-
3 // Copyright (C) 2008 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 * This is a Standard C++ Library header.
34 #ifndef _GLIBCXX_DATE_TIME
35 #define _GLIBCXX_DATE_TIME 1
37 #pragma GCC system_header
39 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 # include <c++0x_warning.h>
55 typedef long long tick_type;
56 static const tick_type ticks_per_second = 1000L * 1000 * 1000;
57 static const tick_type seconds_per_tick = 0;
58 static const bool is_subsecond = true;
60 // construct/copy/destroy
61 nanoseconds(long long __ns = 0) : _M_ns(__ns) { }
64 template<typename _RhsDuration>
66 operator+=(const _RhsDuration& __d);
68 template<typename _RhsDuration>
70 operator-=(const _RhsDuration& __d);
73 operator*=(long __multiplier);
76 operator/=(long __divisor);
79 tick_type count() const { return _M_ns; }
82 nanoseconds operator-() const { return nanoseconds(-_M_ns); }
100 typedef nanoseconds::tick_type tick_type;
101 static const tick_type ticks_per_second = nanoseconds::ticks_per_second;
102 static const tick_type seconds_per_tick = 0;
103 static const bool is_subsecond = true;
105 // create/copy/destroy
107 system_time() : _M_sec(0), _M_nsec(0) { }
109 explicit system_time(time_t __s, nanoseconds __ns = 0)
110 : _M_sec(__s), _M_nsec(__ns.count()) { }
113 seconds_since_epoch() const { return _M_sec; }
116 nanoseconds_since_epoch() const
118 return nanoseconds(_M_nsec + _M_sec * ticks_per_second);
121 // comparison functions
124 operator==(const system_time& __rhs) const
126 const tick_type __ns = _M_nsec + _M_sec * ticks_per_second;
127 const tick_type __xns = __rhs._M_nsec + __rhs._M_sec * ticks_per_second;
128 return __ns == __xns;
132 operator!=(const system_time& __rhs) const
134 return !(*this == __rhs);
138 operator<(const system_time& __rhs) const
140 const tick_type __ns = _M_nsec + _M_sec * ticks_per_second;
141 const tick_type __xns = __rhs._M_nsec + __rhs._M_sec * ticks_per_second;
146 operator<=(const system_time& __rhs) const
148 return !(__rhs < *this);
152 operator>(const system_time& __rhs) const
154 return __rhs < *this;
158 operator>=(const system_time& __rhs) const
160 return !(*this < __rhs);
163 // arithmetic functions
165 operator-(const system_time& __rhs) const
167 const tick_type __ns = _M_nsec + _M_sec * ticks_per_second;
168 const tick_type __xns = __rhs._M_nsec + __rhs._M_sec * ticks_per_second;
169 return nanoseconds(__ns - __xns);
172 template<typename _Duration>
174 operator+(const _Duration& __td) const;
176 template<typename _Duration>
178 operator+=(const _Duration& __td);
180 template<typename _Duration>
182 operator-(const _Duration& __td) const;
184 template<typename _Duration>
186 operator-=(const _Duration& __td);
193 // non-member functions
197 template<typename _Duration>
199 operator+(const _Duration& __td, const system_time& __rhs);
201 template<class _LhsDuration, class _RhsDuration>
203 operator==(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
204 template<class _LhsDuration, class _RhsDuration>
206 operator!=(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
208 template<class _LhsDuration, class _RhsDuration>
210 operator<(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
211 template<class _LhsDuration, class _RhsDuration>
213 operator<=(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
214 template<class _LhsDuration, class _RhsDuration>
216 operator>(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
217 template<class _LhsDuration, class _RhsDuration>
219 operator>=(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
221 template<typename _LhsDuration, typename _RhsDuration>
222 struct __finest_duration;
224 template<class _LhsDuration, class _RhsDuration>
225 typename __finest_duration<_LhsDuration, _RhsDuration>::type
226 operator+(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
227 template<class _LhsDuration, class _RhsDuration>
228 typename __finest_duration<_LhsDuration, _RhsDuration>::type
229 operator-(const _LhsDuration& __lhs, const _RhsDuration& __rhs);
231 template<class _Duration>
233 operator*(_Duration __lhs, long __rhs);
234 template<class _Duration>
236 operator*(long __lhs, _Duration __rhs);
238 template<class _Duration>
240 operator/(_Duration __lhs, long __rhs);
243 #endif // __GXX_EXPERIMENTAL_CXX0X__
245 #endif // _GLIBCXX_DATE_TIME