# Time Service

- [API reference](https://docs.qualcomm.com/doc/80-41102-2/topic/_doxygen_rst_file__doxygen_sources_taf_time_interface_h.html#file-taf-time-interface-h)

[HAL APIs](https://docs.qualcomm.com/doc/80-41102-2/topic/_doxygen_rst_file__doxygen_sources_include_vhal_tafHalTime_h.html#file-tafhaltime-h)

The Time Service provides APIs that allow customer applications to set the system time and get the system, network, and GNSS time.

## IPC interfaces binding

The functions of this API are provided by the **tafTimeSvc** service.

The following example illustrates how to bind to the Time service.

bindings:
      {
          clientExe.clientComponent.taf_time -> tafTimeSvc.taf_time
      }
    Copy to clipboard

## Get the time

When trying to get the time information of a given time source, the application shall first get the time reference by calling [taf\_time\_GetTimeRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a165af4dd934c1130ccf2cfb515bd567a.html#Documentationa00734_1a165af4dd934c1130ccf2cfb515bd567a), then call [taf\_time\_GetTime()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1ab2796fa50afd9effe072bd49381143fa.html#Documentationa00734_1ab2796fa50afd9effe072bd49381143fa) to fetch the related time information. With the reference object, [taf\_time\_GetRefSystemTime()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a9fe56ca650202ae8986df6ae163a0568.html#Documentationa00734_1a9fe56ca650202ae8986df6ae163a0568) and [taf\_time\_GetRefGptpTime()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a413c598f4a07d7c17092206f2f968455.html#Documentationa00734_1a413c598f4a07d7c17092206f2f968455) are two APIs to get the system time and GPTP time fetched from [taf\_time\_GetTime()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1ab2796fa50afd9effe072bd49381143fa.html#Documentationa00734_1ab2796fa50afd9effe072bd49381143fa). When the reference is not needed, call [taf\_time\_ReleaseTimeRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a5623bb3a8b0dc9ed98e063af26a4569b.html#Documentationa00734_1a5623bb3a8b0dc9ed98e063af26a4569b) to release the time reference.

The following example illustrates how to get the time information.

le_result_t result;
    taf_time_TimeSpec_t timeVal;
    taf_time_TimeSourceRef_t timeSrcRef;
    
    // Get the reference for a time source.
    timeSrcRef = taf_time_GetTimeRef(TAF_TIME_SRC_NAME_NETWORK);
    if (timeSrcRef == NULL);
    {
       return LE_FAULT;
    }
    
    // Get the network time with reference.
    result = taf_time_GetTime(timeSrcRef, &timeVal);
    if (result != LE_OK)
    {
       return result;
    }
    LE_INFO("Reference network time is %"PRIu64".%"PRIu64, time.sec, timeVal.nanosec);
    
    // Get reference system time.
    result = taf_time_GetRefSystemTime(timeSrcRef, &timeVal);
    if (result == LE_OK)
    {
       LE_INFO("Reference system time is %"PRIu64".%"PRIu64, timeVal.sec, timeVal.nanosec);
    }
    
    // Get reference gptp time.
    result = taf_time_GetRefGptpTime(timeSrcRef, &timeVal);
    if (result == LE_OK)
    {
        LE_INFO("Reference gptp time is %"PRIu64".%"PRIu64, timeVal.sec, timeVal.nanosec);
    }
    
    // Release the memory for this reference.
    result = taf_time_ReleaseTimeRef(timeSrcRef);
    if (result == LE_OK)
    {
        LE_INFO("The reference was successfully removed\n");
    }
    Copy to clipboard

## Set the system time

- [taf\_time\_SetTrustTime()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a3fb59c895e226c960fa3589bbd526324.html#Documentationa00734_1a3fb59c895e226c960fa3589bbd526324) — Sets system time in the format of seconds and nanosconds. This parameter ‘validity’ is used to indicate it is a trust time or not.

static le_mem_PoolRef_t NewTimePool = NULL;
       taf_time_TimeSpec_t *newTime;
       NewTimePool = le_mem_CreatePool("NewTimePool", sizeof(taf_time_TimeSpec_t));
       newTime = (taf_time_TimeSpec_t*) le_mem_ForceAlloc(NewTimePool);
    
       newTime->sec = 1667788990;
       newTime->nanosec = 10000;
    
       bool validity = true; // or false.
       uint8_t sourceId = TAF_TIME_SRC_NAME_EX_APP;
       taf_time_SourceRef_t srcRef;
    
       srcRef = taf_time_GetSourceRef(sourceId);
       if(taf_time_SetTrustTime(srcRef, newTime, validity) == LE_OK)
     {
        // Process your code.
     }

     @section taf_time_GetRtcTimeReqAsync Get the RTC time asynchronously
    
     With the callback function given in taf_time_GetRtcTimeReqAsync(), the application gets
     the RTC time asynchronously. When the RTC time is available, the time service will notify
     the client through the registered callback function.
    .
     The following example illustrates how to register a callback function and get the
     time from RTC device asynchronously.
    
     @code
    
      static void getRTCTimeAsync(const taf_time_TimeSpec_t* timeVal,
        le_result_t responseState, void* contextPtr)
    {
        LE_INFO("responseState: %d", responseState);
        LE_INFO("Received async vhal RTC time is %"PRIu64".%"PRIu64, timeVal->sec, timeVal->nanosec);
    }
    
     //Register the async callback function
     void* TestGetRTCAsync(void* ctxPtr)
    {
        le_result_t res = taf_time_GetRtcTimeReqAsync(getRTCTimeAsync, (void*)ctxPtr);
    
        if (res == LE_UNSUPPORTED)
        {
            LE_INFO("RTC Async get time API (work with VHAL) received: Unsupported");
        }
        return NULL;
    }
    Copy to clipboard

## Get the source reference

To get the reference of a source the following APIs can be used.

- [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a) — Gets the source reference.

When trying to get the reference for a source, the application shall call [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a).

The following example illustrates how to get the source reference.

uint8_t sourceId = TAF_TIME_SRC_NAME_SYSTEM;
     taf_time_SourceRef_t srcRef;
    
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    Copy to clipboard

## Get the offset from Universal Time

When trying to get the time zone information of a given time source, the application shall first get the source reference by calling [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a), then call [taf\_time\_GetTimeZone()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa3c9ae1ec218d75c9702bb2b7e3aa240.html#Documentationa00734_1aa3c9ae1ec218d75c9702bb2b7e3aa240) to fetch the Offset from Universal time i.e. the difference between local time and Universal time, in increments of 15 minutes (signed value).

The following example illustrates how to get the source information.

uint8_t sourceId = TAF_TIME_SRC_NAME_NETWORK;
    taf_time_SourceRef_t srcRef;
    
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    int8_t timeZone = 0;
    le_result_t res = taf_time_GetTimeZone(srcRef, &timeZone);
    LE_ASSERT(res == LE_OK);
    LE_INFO("Time zone is:  %d", timeZone);
    Copy to clipboard

## Get the daylight saving adjustment

When trying to get the daylight saving adjustment for a given time source, the application shall first get the source reference by calling [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a), then call [taf\_time\_GetTimeDayAdj()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1adaf630e3a3eedc9bc7fc4cd012e7445e.html#Documentationa00734_1adaf630e3a3eedc9bc7fc4cd012e7445e) to fetch the daylight saving adjustment in hours.

The following example illustrates how to get the source information.

uint8_t sourceId = TAF_TIME_SRC_NAME_NETWORK;
    taf_time_SourceRef_t srcRef;
    
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    uint8_t dayltSavAdj;
    le_result_t res = taf_time_GetTimeDayAdj(srcRef, &dayltSavAdj);
    LE_ASSERT(res == LE_OK);
    LE_INFO("Day Light Saving is: %d", dayltSavAdj);
    Copy to clipboard

## Get the number of failed loops and the polling interval time for a source

When trying to get the number of failed loops and the polling interval time for a source, the application shall first get the source reference by calling [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a), then call [taf\_time\_GetFailedLoops()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1ac1e7df5e06afe301f6dd395a6ccd36c2.html#Documentationa00734_1ac1e7df5e06afe301f6dd395a6ccd36c2) to fetch the details.

The following example illustrates how to get the source information.

uint8_t sourceId = TAF_TIME_SRC_NAME_RTC;
    taf_time_SourceRef_t srcRef;
    int32_t failedLoops =0;
    int64_t loopIntervalSec = 0;
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    le_result_t res = taf_time_GetFailedLoops(srcRef, &failedLoops, &loopIntervalSec);
    LE_ASSERT(res == LE_OK);
    LE_INFO("The number of failed loops are %d. Loop interval is %ld",
    failedLoops, loopIntervalSec);
    Copy to clipboard

## Get the availability of a source

When trying to get the availability of a source, the application shall first get the source reference by calling [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a), then call [taf\_time\_IsAvailable()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1ae998bfd2944075bd9c392fdeee6e6f24.html#Documentationa00734_1ae998bfd2944075bd9c392fdeee6e6f24) to fetch the availability.

The following example illustrates how to get the source information.

uint8_t sourceId = TAF_TIME_SRC_NAME_RTC;
    taf_time_SourceRef_t srcRef;
    bool isAvailable;
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    isAvailable = taf_time_IsAvailable(srcRef);
    if (isAvailable)
    {
        LE_INFO("Time source is Available!");
    }
    else
    {
        LE_INFO("Time source is NOT Available!");
    }
    Copy to clipboard

## Get the source ID of time source to which system time is synced

When trying to get the latest time source to which system is synced, call [taf\_time\_GetSystemTimeSourceID()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1ab8102d4d2ab00ef0f7e6c80bd54e6578.html#Documentationa00734_1ab8102d4d2ab00ef0f7e6c80bd54e6578) to fetch the source ID.

The following example illustrates how to get the source information.

taf_time_TimeSources_t systemTimeSrc;
    le_result_t res = taf_time_GetSystemTimeSourceID(&systemTimeSrc);
    LE_ASSERT(res == LE_OK);
    LE_INFO("The lastest system time is set by %s", SourceNameIndexToStr(systemTimeSrc));
    Copy to clipboard

## Get the validity of a source

When trying to get the validity of a source, the application shall first get the source reference by calling [taf\_time\_GetSourceRef()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa83495433c08fbc50e230c71ab9a952a.html#Documentationa00734_1aa83495433c08fbc50e230c71ab9a952a), then call [taf\_time\_IsSourceValid()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a5934792722ab32852a451906573e8fe8.html#Documentationa00734_1a5934792722ab32852a451906573e8fe8) to fetch the validity.

The following example illustrates how to get the source information.

uint8_t sourceId = TAF_TIME_SRC_NAME_NETWORK;
    taf_time_SourceRef_t srcRef;
    bool status;
    srcRef = taf_time_GetSourceRef(sourceId);
    LE_ASSERT(srcRef != NULL);
    status = taf_time_IsSourceValid(srcRef);
    if (status)
    {
        LE_INFO("Time source is valid!");
    }
    else
    {
        LE_INFO("Time source is NOT valid!");
    }
    Copy to clipboard

## Time change notification

With the reference object, [taf\_time\_AddTimeValueChangeHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a182aa3cdf49864e7af0ab5cb0bf9346f.html#Documentationa00734_1a182aa3cdf49864e7af0ab5cb0bf9346f) is for the application to register an event handler for the time source. When the time source gets changed, the time service will notify the client through that registered event handler.

**NOTE:** This functionality does not support RTC and external time sources.

When the notification is not needed, [taf\_time\_RemoveTimeValueChangeHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a6a9b7ba60d004be720ea486a8a2341e9.html#Documentationa00734_1a6a9b7ba60d004be720ea486a8a2341e9) is to de-register the event handler to release.

The following example illustrates how to register and get the time information,

// Event handler for receiving notification from time service
    void TimeValueChangeHandler
    (
        taf_time_TimeSourceRef_t timeSrcRef,
        taf_time_TimeSpec_t* timeVal,
        void* contextPtr
    )
    {
        le_result_t result;
        taf_time_TimeSpec_t sysTime;
        taf_time_TimeSpec_t gptpTime;
        LE_INFO("Received network time from notification is %"PRIu64".%"PRIu64,
                                    timeSrcRef, timeVal->sec, timeVal->nanosec);
    
        // Get reference system time information.
        result = taf_time_GetRefSystemTime(timeSrcRef, &systemTime);
        if (result == LE_OK)
        {
            LE_INFO("Reference system time is %"PRIu64".%"PRIu64, sysTime.sec, sysTime.nanosec);
        }
    
        // Get reference gptp time information.
        result = taf_time_GetRefGptpTime(timeSrcRef, &gptpTime);
        if (result == LE_OK)
        {
            LE_INFO("Reference gptp time is %"PRIu64".%"PRIu64, time.sec, time.nanosec);
        }
    
        // Release the memory for this reference.
        result = taf_time_ReleaseTimeRef(timeSrcRef);
        if (result == LE_OK)
        {
               LE_INFO("The reference was successfully removed\n");
        }
    
        return;
    }
    
    static taf_time_TimeValueChangeHandlerRef_t TimeValueChangeHandlerRef = NULL;
    // Thread to register the handler
    void* TimeValueChangeHandlerTestThread
    (
        void* contextPtr 
    )
    {
        // Connect to service.
        taf_time_ConnectService();
    
        // Register event handler
        TimeValueChangeHandlerRef = taf_time_AddTimeValueChangeHandler(TAF_TIME_SRC_NAME_NETWORK,
                  (taf_time_TimeValueChangeHandlerFunc_t)TimeValueChangeHandler, NULL);
        if(TimeValueChangeHandlerRef != NULL)
        {
             LE_INFO("The event handler was successfully registered\n");
        }
    
        le_event_RunLoop();
        return NULL;
    }
    
    //Creates a thread to register the handler and receive notification.
    le_thread_Ref_t threadRef = le_thread_Create("TimeSrcChangeTh",
                               TimeValueChangeHandlerTestThread, NULL);
    // De-register the hanlder when not need.
    taf_time_RemoveTimeValueChangeHandler(TimeValueChangeHandlerRef);
    Copy to clipboard

To receive the time source change notification, the following APIs should be used.

- [taf\_time\_AddTimeSourceChangeHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a03f92849abbaa637c023f55cce66f33b.html#Documentationa00734_1a03f92849abbaa637c023f55cce66f33b) — Adds the time source changed handler.
- [taf\_time\_RemoveTimeSourceChangeHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a3370d5f1a05038efdc1b6cab247b3567.html#Documentationa00734_1a3370d5f1a05038efdc1b6cab247b3567) — Removes the registered time source changed handler.

// Time source change indication handler.
     void TimeSourceChangeHandler
     (
          taf_time_TimeSources_t PreTimeSource,
          taf_time_TimeSources_t NewTimeSource
     )
     {
          LE_INFO("Old time source: %d, New time source: %d\n",PreTimeSource, NewTimeSource);
     }
    
     // Add handler for time source change.
     taf_time_TimeSourceChangeHandlerRef_t TimeSourceChangeHandlerRef =
     taf_time_AddTimeSourceChangeHandler
     (
          (taf_time_TimeSourceChangeHandlerFunc_t)TimeSourceChangeHandler, NULL
     );
    
    // Time source change in some cases.
    Copy to clipboard

## Time source status notification

With the reference object, [taf\_time\_AddTimeSourceStatusHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1aa53ff59afa09623b2a10689eed210359.html#Documentationa00734_1aa53ff59afa09623b2a10689eed210359) is for the application to register an event handler for change in availability and/or validity of a time source. When the time source status gets changed, the time service will notify the client through that registered event handler.

When the notification is not needed, [taf\_time\_RemoveTimeSourceStatusHandler()](https://docs.qualcomm.com/doc/80-41102-2/topic/function_a00734_1a062f9bdd851837c481ef5937d85a8c81.html#Documentationa00734_1a062f9bdd851837c481ef5937d85a8c81) is to de-register the event handler to remove it.

The following example illustrates how to register and get the time status information,

// Source status change handler function
     void TimeSourceStatusHandler
     (
         bool isAvailable,
         void* contextPtr
     )
     {
         LE_INFO("Time source status is: %d", Available);
     }
    
    // Register the source status change handler
    
    static taf_time_TimeSourceStatusHandlerRef_t TimeSourceStatusHandlerRef = NULL;
    void* TimeSourceStatusHandlerTestThread
    (
      void* contextPtr 
    )
    {
        uint8_t sourceid = 0;
        taf_time_SourceRef_t sourceRef = NULL;
        sourceRef = taf_time_GetSourceRef(sourceid);
        LE_ASSERT(sourceRef != NULL);
        TimeSourceStatusHandlerRef = taf_time_AddTimeSourceStatusHandler(sourceRef,
            (taf_time_TimeSourceStatusHandlerFunc_t)TimeSourceStatusHandler, NULL);
        LE_ASSERT(TimeSourceStatusHandlerRef != NULL);
    }
    Copy to clipboard

Last Published: Jun 09, 2026

[Previous Topic
Thermal Management Service](https://docs.qualcomm.com/bundle/publicresource/80-41102-2/topics/page_c_taftherm.md) [Next Topic
Version Information Service](https://docs.qualcomm.com/bundle/publicresource/80-41102-2/topics/page_c_tafVerInfo.md)