# Timestamp

<a id="timestamp-2"></a>

# Timestamp

```cpp
#include <icy/datetime.h>

class Timestamp
```

[Defined in src/base/include/icy/datetime.h:36](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L36)

A [Timestamp](#timestamp-2) stores a monotonic* time value with (theoretical) microseconds resolution. Timestamps can be compared with each other and simple arithmetics are supported.

[*] Note that [Timestamp](#timestamp-2) values are only monotonic as long as the systems's clock is monotonic as well (and not, e.g. set back).

Timestamps are UTC (Coordinated Universal Time) based and thus independent of the timezone in effect on the system.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Timestamp`](#timestamp-3)  | Creates a timestamp with the current time. |
|  | [`Timestamp`](#timestamp-4)  | Creates a timestamp from the given time value. |
|  | [`Timestamp`](#timestamp-5)  | Copy constructor. |
|  | [`~Timestamp`](#timestamp-6)  | Destroys the timestamp. |
| [`Timestamp`](#timestamp-2) & | [`operator=`](#operator-130)  |  |
| [`Timestamp`](#timestamp-2) & | [`operator=`](#operator-131)  |  |
| `void` | [`swap`](#swap-9)  | Swaps the [Timestamp](#timestamp-2) with another one. |
| `void` | [`update`](#update-3)  | Updates the [Timestamp](#timestamp-2) with the current time. |
| `bool` | [`operator==`](#operator-132) `const` `inline` |  |
| `bool` | [`operator!=`](#operator-133) `const` `inline` |  |
| `bool` | [`operator>`](#operator-134) `const` `inline` |  |
| `bool` | [`operator>=`](#operator-135) `const` `inline` |  |
| `bool` | [`operator<`](#operator-136) `const` `inline` |  |
| `bool` | [`operator<=`](#operator-137) `const` `inline` |  |
| [`Timestamp`](#timestamp-2) | [`operator+`](#operator-138) `const` `inline` |  |
| [`Timestamp`](#timestamp-2) | [`operator-`](#operator-139) `const` `inline` |  |
| [`TimeDiff`](#timediff-1) | [`operator-`](#operator-140) `const` `inline` |  |
| [`Timestamp`](#timestamp-2) & | [`operator+=`](#operator-141) `inline` |  |
| [`Timestamp`](#timestamp-2) & | [`operator-=`](#operator-142) `inline` |  |
| `std::time_t` | [`epochTime`](#epochtime) `const` `inline` | Returns the timestamp expressed in time_t. time_t base time is midnight, January 1, 1970. Resolution is one second. |
| [`UtcTimeVal`](#utctimeval) | [`utcTime`](#utctime-2) `const` `inline` | Returns the timestamp expressed in UTC-based time. UTC base time is midnight, October 15, 1582. Resolution is 100 nanoseconds. |
| [`TimeVal`](#timeval) | [`epochMicroseconds`](#epochmicroseconds) `const` `inline` | Returns the timestamp expressed in microseconds since the Unix epoch, midnight, January 1, 1970. |
| [`TimeDiff`](#timediff-1) | [`elapsed`](#elapsed-1) `const` `inline` | Returns the time elapsed since the time denoted by the timestamp. Equivalent to [Timestamp()](#timestamp-3) - *this. |
| `bool` | [`isElapsed`](#iselapsed) `const` `inline` | Returns true iff the given interval has passed since the time denoted by the timestamp. |

---

<a id="timestamp-3"></a>

### Timestamp

```cpp
Timestamp()
```

[Defined in src/base/include/icy/datetime.h:44](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L44)

Creates a timestamp with the current time.

---

<a id="timestamp-4"></a>

### Timestamp

```cpp
Timestamp(TimeVal tv)
```

[Defined in src/base/include/icy/datetime.h:47](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L47)

Creates a timestamp from the given time value.

---

<a id="timestamp-5"></a>

### Timestamp

```cpp
Timestamp(const Timestamp & other)
```

[Defined in src/base/include/icy/datetime.h:50](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L50)

Copy constructor.

---

<a id="timestamp-6"></a>

### ~Timestamp

```cpp
~Timestamp()
```

[Defined in src/base/include/icy/datetime.h:53](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L53)

Destroys the timestamp.

---

<a id="operator-130"></a>

### operator=

```cpp
Timestamp & operator=(const Timestamp & other)
```

[Defined in src/base/include/icy/datetime.h:55](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L55)

---

<a id="operator-131"></a>

### operator=

```cpp
Timestamp & operator=(TimeVal tv)
```

[Defined in src/base/include/icy/datetime.h:56](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L56)

---

<a id="swap-9"></a>

### swap

```cpp
void swap(Timestamp & timestamp)
```

[Defined in src/base/include/icy/datetime.h:59](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L59)

Swaps the [Timestamp](#timestamp-2) with another one.

---

<a id="update-3"></a>

### update

```cpp
void update()
```

[Defined in src/base/include/icy/datetime.h:62](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L62)

Updates the [Timestamp](#timestamp-2) with the current time.

---

<a id="operator-132"></a>

### operator==

`const` `inline`

```cpp
inline bool operator==(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:64](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L64)

---

<a id="operator-133"></a>

### operator!=

`const` `inline`

```cpp
inline bool operator!=(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:65](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L65)

---

<a id="operator-134"></a>

### operator>

`const` `inline`

```cpp
inline bool operator>(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:66](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L66)

---

<a id="operator-135"></a>

### operator>=

`const` `inline`

```cpp
inline bool operator>=(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:67](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L67)

---

<a id="operator-136"></a>

### operator<

`const` `inline`

```cpp
inline bool operator<(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:68](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L68)

---

<a id="operator-137"></a>

### operator<=

`const` `inline`

```cpp
inline bool operator<=(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:69](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L69)

---

<a id="operator-138"></a>

### operator+

`const` `inline`

```cpp
inline Timestamp operator+(TimeDiff d) const
```

[Defined in src/base/include/icy/datetime.h:71](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L71)

---

<a id="operator-139"></a>

### operator-

`const` `inline`

```cpp
inline Timestamp operator-(TimeDiff d) const
```

[Defined in src/base/include/icy/datetime.h:72](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L72)

---

<a id="operator-140"></a>

### operator-

`const` `inline`

```cpp
inline TimeDiff operator-(const Timestamp & ts) const
```

[Defined in src/base/include/icy/datetime.h:73](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L73)

---

<a id="operator-141"></a>

### operator+=

`inline`

```cpp
inline Timestamp & operator+=(TimeDiff d)
```

[Defined in src/base/include/icy/datetime.h:74](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L74)

---

<a id="operator-142"></a>

### operator-=

`inline`

```cpp
inline Timestamp & operator-=(TimeDiff d)
```

[Defined in src/base/include/icy/datetime.h:75](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L75)

---

<a id="epochtime"></a>

### epochTime

`const` `inline`

```cpp
inline std::time_t epochTime() const
```

[Defined in src/base/include/icy/datetime.h:80](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L80)

Returns the timestamp expressed in time_t. time_t base time is midnight, January 1, 1970. Resolution is one second.

---

<a id="utctime-2"></a>

### utcTime

`const` `inline`

```cpp
inline UtcTimeVal utcTime() const
```

[Defined in src/base/include/icy/datetime.h:85](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L85)

Returns the timestamp expressed in UTC-based time. UTC base time is midnight, October 15, 1582. Resolution is 100 nanoseconds.

---

<a id="epochmicroseconds"></a>

### epochMicroseconds

`const` `inline`

```cpp
inline TimeVal epochMicroseconds() const
```

[Defined in src/base/include/icy/datetime.h:89](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L89)

Returns the timestamp expressed in microseconds since the Unix epoch, midnight, January 1, 1970.

---

<a id="elapsed-1"></a>

### elapsed

`const` `inline`

```cpp
inline TimeDiff elapsed() const
```

[Defined in src/base/include/icy/datetime.h:93](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L93)

Returns the time elapsed since the time denoted by the timestamp. Equivalent to [Timestamp()](#timestamp-3) - *this.

---

<a id="iselapsed"></a>

### isElapsed

`const` `inline`

```cpp
inline bool isElapsed(TimeDiff interval) const
```

[Defined in src/base/include/icy/datetime.h:97](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L97)

Returns true iff the given interval has passed since the time denoted by the timestamp.

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| [`Timestamp`](#timestamp-2) | [`fromEpochTime`](#fromepochtime) `static` | Creates a timestamp from a std::time_t. |
| [`Timestamp`](#timestamp-2) | [`fromUtcTime`](#fromutctime) `static` | Creates a timestamp from a UTC time value. |
| [`TimeVal`](#timeval) | [`resolution`](#resolution-1) `static` `inline` | Returns the resolution in units per second. Since the timestamp has microsecond resolution, the returned value is always 1000000. |

---

<a id="fromepochtime"></a>

### fromEpochTime

`static`

```cpp
static Timestamp fromEpochTime(std::time_t t)
```

[Defined in src/base/include/icy/datetime.h:100](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L100)

Creates a timestamp from a std::time_t.

---

<a id="fromutctime"></a>

### fromUtcTime

`static`

```cpp
static Timestamp fromUtcTime(UtcTimeVal val)
```

[Defined in src/base/include/icy/datetime.h:103](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L103)

Creates a timestamp from a UTC time value.

---

<a id="resolution-1"></a>

### resolution

`static` `inline`

```cpp
static inline TimeVal resolution()
```

[Defined in src/base/include/icy/datetime.h:108](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L108)

Returns the resolution in units per second. Since the timestamp has microsecond resolution, the returned value is always 1000000.

## Public Types

| Name | Description |
|------|-------------|
| [`TimeVal`](#timeval)  | monotonic UTC time value in microsecond resolution |
| [`UtcTimeVal`](#utctimeval)  | monotonic UTC time value in 100 nanosecond resolution |
| [`TimeDiff`](#timediff-1)  | difference between two timestamps in microseconds |

---

<a id="timeval"></a>

### TimeVal

```cpp
using TimeVal = std::int64_t
```

[Defined in src/base/include/icy/datetime.h:39](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L39)

monotonic UTC time value in microsecond resolution

---

<a id="utctimeval"></a>

### UtcTimeVal

```cpp
using UtcTimeVal = std::int64_t
```

[Defined in src/base/include/icy/datetime.h:40](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L40)

monotonic UTC time value in 100 nanosecond resolution

---

<a id="timediff-1"></a>

### TimeDiff

```cpp
using TimeDiff = std::int64_t
```

[Defined in src/base/include/icy/datetime.h:41](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L41)

difference between two timestamps in microseconds

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`TimeVal`](#timeval) | [`_ts`](#_ts)  |  |

---

<a id="_ts"></a>

### _ts

```cpp
TimeVal _ts
```

Type: [`TimeVal`](#timeval)

[Defined in src/base/include/icy/datetime.h:111](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L111)
