> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# QSH Time Utility

**Header:** `utils/inc/qshTimeUtil.h`

## Structures

### `qshTimeUtil`

Sensors time utilities.

**Members**

<ParamField path="mOffsetNs" type="std::atomic< std::int64_t >" />

#### Functions

##### `getInstance`

get singleton instance of the timeutil class

```cpp theme={null}
qshTimeUtil & getInstance()
```

**Returns**

qshTimeUtil&

##### `qtimerGetTicks`

reads the current QTimer count value

```cpp theme={null}
uint64_t qtimerGetTicks()
```

**Returns**

uint64\_t QTimer tick-count

##### `qtimerGetFreq`

get QTimer frequency in Hz

```cpp theme={null}
uint64_t qtimerGetFreq()
```

**Returns**

uint64\_t

##### `qtimerGetTimeNs`

get time in nanoseconds since boot-up

```cpp theme={null}
uint64_t qtimerGetTimeNs()
```

**Returns**

uint64\_t nanoseconds

##### `qtimerTicksToNs`

convert the qtimer tick value of nanoseconds

```cpp theme={null}
uint64_t qtimerTicksToNs(uint64_t ticks)
```

**Parameters**

<ParamField path="ticks" type="uint64_t" />

**Returns**

uint64\_t qtimer time in nanoseconds

##### `qtimerNsToElapsedRealtimeNano`

convert qtimer timestamp (in ns) to android system time (in ns)

```cpp theme={null}
int64_t qtimerNsToElapsedRealtimeNano(uint64_t qtimerTS)
```

**Parameters**

<ParamField path="qtimer_ts" type="" />

**Returns**

int64\_t

##### `elapsedRealtimeNanoToQtimerNs`

convert android system time (in ns) to qtimer timestamp (in ns)

```cpp theme={null}
uint64_t elapsedRealtimeNanoToQtimerNs(int64_t androidTS)
```

**Parameters**

<ParamField path="androidTS" type="int64_t" />

**Returns**

uint64\_t

##### `qtimerTicksToElapsedRealtimeNano`

convert qtimer timestamp (in ticks) to android timestamp (in ns)

```cpp theme={null}
int64_t qtimerTicksToElapsedRealtimeNano(uint64_t qtimerTicks)
```

**Parameters**

<ParamField path="qtimer_ticks" type="" />

**Returns**

int64\_t

##### `getElapsedRealtimeNanoOffset`

get offset between sensor time system and Android time system (in ns)

```cpp theme={null}
int64_t getElapsedRealtimeNanoOffset()
```

**Returns**

int64\_t

##### `recalculateOffset`

kick in the logic to recalculate offset for drift

```cpp theme={null}
bool recalculateOffset(bool forceUpdate)
```

**Parameters**

<ParamField path="force_update" type="">
  if true, always update the offset (even if the previous update was more recent than the last update)
</ParamField>

**Returns**

true if offset changed, false otherwise

##### `getOffsetUpdateScheduleNs`

```cpp theme={null}
uint64_t getOffsetUpdateScheduleNs() const
```
