| libtorrent

# Time

Author: | Arvid Norberg, arvid@libtorrent.org
Version: | 1.0.7

Table of contents

- time_duration
- ptime

This section contains fundamental time types used internally by libtorrent and exposed through various places in the API. The two basic types are `ptime` and `time_duration`. The first represents a point in time and the second the difference between two points in time.

The internal representation of these types is implementation defined and they can only be constructed via one of the construction functions that take a well defined time unit (seconds, minutes, etc.). They can only be turned into well defined time units by the accessor functions (total_microseconds(), etc.).

Note

In a future version of libtorrent, these types will be replaced by the standard timer types from `std::chrono`.

# time_duration

Declared in "libtorrent/ptime.hpp"

libtorrent time_duration type

    struct time_duration
    {
       time_duration& operator-= (time_duration const& c);
       time_duration operator+ (time_duration const& c);
       time_duration& operator+= (time_duration const& c);
       time_duration operator/ (int rhs) const;
       explicit time_duration (boost::int64_t d);
       time_duration operator- (time_duration const& c);
       time_duration& operator*= (int v);
    };

## operator+=() time_duration() operator*=() operator-=() operator+() operator/() operator-()

    time_duration& operator-= (time_duration const& c);
    time_duration operator+ (time_duration const& c);
    time_duration& operator+= (time_duration const& c);
    time_duration operator/ (int rhs) const;
    explicit time_duration (boost::int64_t d);
    time_duration operator- (time_duration const& c);
    time_duration& operator*= (int v);

all operators have the same semantics as a 64 bit signed integer

# ptime

Declared in "libtorrent/ptime.hpp"

This type represents a point in time.

    struct ptime
    {
       ptime& operator-= (time_duration rhs);
       ptime& operator+= (time_duration rhs);
    };

## operator+=() operator-=()

    ptime& operator-= (time_duration rhs);
    ptime& operator+= (time_duration rhs);

these operators have the same semantics as signed 64 bit integers

## is_negative()

Declared in "libtorrent/ptime.hpp"

    inline bool is_negative (time_duration dt);

returns true of the time duration is less than 0

## operator*() operator>=() operator!=() operator>() operator<() operator==() operator+() operator<=() operator-()

Declared in "libtorrent/ptime.hpp"

    inline time_duration operator* (int lhs, time_duration rhs);
    inline bool operator== (time_duration lhs, time_duration rhs);
    inline bool operator<= (time_duration lhs, time_duration rhs);
    inline bool operator== (ptime lhs, ptime rhs);
    inline bool operator>= (time_duration lhs, time_duration rhs);
    inline bool operator< (time_duration lhs, time_duration rhs);
    inline bool operator> (time_duration lhs, time_duration rhs);
    inline bool operator> (ptime lhs, ptime rhs);
    inline ptime operator+ (time_duration lhs, ptime rhs);
    inline ptime operator+ (ptime lhs, time_duration rhs);
    inline time_duration operator* (time_duration lhs, int rhs);
    inline time_duration operator- (ptime lhs, ptime rhs);
    inline bool operator<= (ptime lhs, ptime rhs);
    inline bool operator!= (ptime lhs, ptime rhs);
    inline bool operator< (ptime lhs, ptime rhs);
    inline bool operator>= (ptime lhs, ptime rhs);
    inline ptime operator- (ptime lhs, time_duration rhs);

all operators have the same semantics as signed 64 bit integers

## time_now()

Declared in "libtorrent/time.hpp"

    ptime const& time_now ();

returns the current time, as represented by ptime. The resolution of this timer is about 100 ms.

## time_now_hires()

Declared in "libtorrent/time.hpp"

    ptime time_now_hires ();

returns the current time as represented by ptime. This is more expensive than time_now(), but provides as high resolution as the operating system can provide.

## min_time() max_time()

Declared in "libtorrent/time.hpp"

    ptime max_time ();
    ptime min_time ();

the earliest and latest possible time points representable by ptime.

## microsec() minutes() hours() milliseconds() seconds()

Declared in "libtorrent/time.hpp"

    time_duration microsec (boost::int64_t s);
    time_duration seconds (boost::int64_t s);
    time_duration milliseconds (boost::int64_t s);
    time_duration minutes (boost::int64_t s);
    time_duration hours (boost::int64_t s);

returns a time_duration representing the specified number of seconds, milliseconds microseconds, minutes and hours.

## total_seconds() total_microseconds() total_milliseconds()

Declared in "libtorrent/time.hpp"

    boost::int64_t total_seconds (time_duration td);
    boost::int64_t total_milliseconds (time_duration td);
    boost::int64_t total_microseconds (time_duration td);

returns the number of seconds, milliseconds and microseconds a time_duration represents.