[#uuid_clock]
== <boost/uuid/uuid_clock.hpp>

:idprefix: uuid_clock_

=== Synopsis

[source,c++]
----
namespace boost {
namespace uuids {

class uuid_clock
{
public:

    using rep = std::int64_t;
    using period = std::ratio<1, 10000000>; // 100ns
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<uuid_clock, duration>;

    static constexpr bool is_steady = false;

    static time_point now() noexcept;

    template<class Duration>
      static time_point from_sys(
        std::chrono::time_point<std::chrono::system_clock, Duration> const& tp ) noexcept;

    static std::chrono::time_point<std::chrono::system_clock, duration>
      to_sys( time_point const& tp ) noexcept;

    static time_point from_timestamp( std::uint64_t timestamp ) noexcept;
    static std::uint64_t to_timestamp( time_point const& tp ) noexcept;
};


}} // namespace boost::uuids
----

The class `uuid_clock` is a `<chrono>`-compatible clock with an epoch of 00:00:00.00, 15 October 1582, and a resolution of 100 ns.
These values are specified in https://www.rfc-editor.org/rfc/rfc4122.html#section-4.1.4[RFC 4122 Section 4.1.4].

=== now

```
static time_point now() noexcept;
```

Returns: :: The current system time (`std::chrono::system_clock::now()`, converted to `uuid_clock::time_point`.)

=== from_sys

```
template<class Duration>
  static time_point from_sys(
    std::chrono::time_point<std::chrono::system_clock, Duration> const& tp ) noexcept;
```

Returns: :: The `uuid_clock::time_point` corresponding to `tp`.

=== to_sys

```
static std::chrono::time_point<std::chrono::system_clock, duration>
  to_sys( time_point const& tp ) noexcept;
```

Returns: :: The `std::chrono::system_clock::time_point` corresponding to `tp`.

Example: ::
+
```
#include <boost/uuid/time_generator_v1.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_clock.hpp>
#include <chrono>

using namespace boost::uuids;

int main()
{
    time_generator_v1 gen;

    uuid u = gen(); // generates a version 1 time-based UUID

    // note that stream output of std::chrono::system_clock::time_point requires C++20

    std::cout << uuid_clock::to_sys( u.time_point_v1() ) << std::endl;
}
```

=== from_timestamp

```
static time_point from_timestamp( std::uint64_t timestamp ) noexcept;
```

Returns: :: The `uuid_clock::time_point` corresponding to `timestamp` 100 nanosecond intervals since the `uuid_clock` epoch.

=== to_timestamp

```
static std::uint64_t to_timestamp( time_point const& tp ) noexcept;
```

Returns: :: The number of 100 nanosecond intervals since the `uuid_clock` epoch corresponding to `tp`.

Example: ::
+
```
using namespace boost::uuids;

uuid u = time_generator_v1()();

assert( u.timestamp_v1() == uuid_clock::to_timestamp( u.time_point_v1() ) );
```
