Skip to main content
Version: 12 Dec 2024

ml_time.h

Functions

Name
MLResultMLTimeConvertMLTimeToSystemTime(MLTime ml_time, struct timespec * out_timespec_time)
Converts timestamps from MLTime to system time.
MLResultMLTimeConvertSystemTimeToMLTime(const struct timespec timespec_time, MLTime out_ml_time)
Converts timestamps from system time to MLTime.

Functions Documentation

MLTimeConvertMLTimeToSystemTime

MLResult MLTimeConvertMLTimeToSystemTime(
MLTime ml_time,
struct timespec * out_timespec_time
)

Converts timestamps from MLTime to system time.

Parameters

MLTimeml_timeTimestamp received from elsewhere in the ML system.
struct timespec *out_timespec_timePointer to a converted equivalent timestamp as if received from clock_gettime using CLOCK_MONOTONIC.

Returns

MLResultMLResult_OkSuccessfully converted timestamp.
MLResultMLResult_InvalidParamNULL passed for timespec_time.
MLResultMLResult_UnspecifiedFailureFailed to convert timestamp with unknown error.

Required Permissions:

  • None

See MLTime for more details. System time is equivalent to the systems monotonic clock. This can be used to calculate duration between two MLTime values by converting them both to a timespec and subtracting the subsequent values.

API Level:

  • 20

MLTimeConvertSystemTimeToMLTime

MLResult MLTimeConvertSystemTimeToMLTime(
const struct timespec * timespec_time,
MLTime * out_ml_time
)

Converts timestamps from system time to MLTime.

Parameters

const struct timespec *timespec_timeSystem clock timestamp as received from clock_gettime using CLOCK_MONOTONIC.
MLTime *out_ml_timePointer to system timestamp equivalent in MLTime.

Returns

MLResultMLResult_OkSuccessfully converted timestamp.
MLResultMLResult_InvalidParamNULL passed for ml_time.
MLResultMLResult_UnspecifiedFailureFailed to convert timespec with unknown error.

Required Permissions:

  • None

See MLTime for more details. System time is equivalent to the systems monotonic clock.

API Level:

  • 20

Source code

// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) 2022 Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement,
// located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying
// this distribution may also be found in the top-level NOTICE file
// appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%

#pragma once

#include <time.h>
#include "ml_api.h"
#include "ml_types.h"

ML_EXTERN_C_BEGIN

ML_API MLResult ML_CALL MLTimeConvertMLTimeToSystemTime(MLTime ml_time, struct timespec *out_timespec_time);

ML_API MLResult ML_CALL MLTimeConvertSystemTimeToMLTime(const struct timespec *timespec_time, MLTime *out_ml_time);

ML_EXTERN_C_END