<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account</link><description>Given the info here and here ... 
 1. Does this mean that the nordic example here is wrong, and that line 54 should be time_struct. tm_mon = month - 1; to account for the indexing difference? 
 
 2. My understanding is that mktime() should convert a datetime</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Sep 2020 15:40:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account" /><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/270915?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2020 15:40:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7db48a13-6332-4da6-bcba-22428e592162</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;For extending the CTS with new characteristics, the existing implementation and other services in our SDK can be used for reference. Two examples of services in the SDK that has multiple characteristics are the Device Information Service (DIS) and the Nordic UART Service (NUS). DIS is a Bluetooth SIG specified service that uses 16 bit UUIDs, and NUS is a service specified by us (Nordic Semiconductor). I am most familiar with the NUS implementation, which uses both writing and notifications for its characteristics.&lt;/p&gt;
&lt;p&gt;For more on BLE characteristics and services, and how they tie into the nRF5 SDK, I suggest the following tutorials. They were updated two years ago to work with nRF5 SDK version 15, and should mostly work with the current nRF5 SDK version 17 as there has not been much change in the areas of the SDK that they cover:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial"&gt;Bluetooth low energy Characteristics, a beginner&amp;#39;s tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;Bluetooth low energy Services, a beginner&amp;#39;s tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/269929?ContentTypeID=1</link><pubDate>Wed, 16 Sep 2020 16:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5368264-2bb9-47c1-b32a-4a460d471459</guid><dc:creator>nordev</dc:creator><description>&lt;p&gt;Hi Terje,&lt;/p&gt;
&lt;p&gt;Thank you very much for the response.&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account/269334"]This is specified in the &lt;a href="https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=292957"&gt;Current Time Service specification&lt;/a&gt; from Bluetooth SIG, sections 3.1.2.1 through 3.1.2.4. The same specification also covers the (optional) Local Time Information Characteristic, which handles time zone data.[/quote]
&lt;p&gt;This was a very helpful document. If I want to take advantage of the Local Time Information Characteristic (UUID &lt;span&gt;00002A0F-0000-1000-8000-00805f9b34fb)&lt;/span&gt;, assuming that Nordic has not already done so in the SDK, do you have recommendations for how I should modify the Current Time Service client in the SDK to use the Local Time Information Characteristic?&amp;nbsp;&lt;/p&gt;
[quote userid="8164" url="~/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account/269334"]As long as both the local and the external device operates in the same time zone, this should lead to consistent time tracking.[/quote]
&lt;p&gt;The reason I need the timezone info is that I am building a device that sends data with timestamps back to the phone upon request. The device gets the time in the first place from CTS, but if CTS comes in local time only without timezone info, when the timestamp gets sent back to the phone, which expects it in UTC and converts &amp;quot;back&amp;quot; to local time, it will be wrong. If the phone ever changes time zones, there will also be no way to know exactly when the timestamps stored on the device actually occurred -- they will all be wrong.&lt;/p&gt;
&lt;p&gt;Thanks so much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/269334?ContentTypeID=1</link><pubDate>Mon, 14 Sep 2020 10:12:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee175f30-73a5-4aaa-b027-ef9b0c28ffa2</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I think that some of the confusion here is that for the Current Time Service (CTS), timezone information is part of an optional characteristic that is not implemented by our CTS example. As such, any time received over CTS is of unknown time zone.&lt;/p&gt;
&lt;p&gt;mktime, on the other hand, do handle time zones.&lt;/p&gt;
&lt;p&gt;From what I understand, our libraries assume that the time zones of both the local and the external device are in UTC, for the purpose of storing time data and/or converting using e.g. mktime, as the &amp;quot;real&amp;quot; time zone is not known. As long as both the local and the external device operates in the same time zone, this should lead to consistent time tracking.&lt;/p&gt;
&lt;p&gt;Answer to Question 1: I do not find traces of time zone handling in that structure, nor in other related libraries.&lt;/p&gt;
&lt;p&gt;Answer to Question 2: This is specified in the &lt;a href="https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=292957"&gt;Current Time Service specification&lt;/a&gt; from Bluetooth SIG, sections 3.1.2.1 through 3.1.2.4. The same specification also covers the (optional) Local Time Information Characteristic, which handles time zone data.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/268821?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 20:33:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6d32604-8610-4217-86db-3bf4f79ac646</guid><dc:creator>nordev</dc:creator><description>[quote userid="6207" url="~/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account/268629"]The calendar example does not have the member&amp;nbsp;&lt;span&gt;p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time as far as i can see it.&lt;/span&gt;[/quote]
&lt;p&gt;This is from the official Nordic CTS Example in the SDK, see excerpt here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling the Current Time Service errors.
 *
 * @param[in] p_evt  Event received from the Current Time Service client.
 */
static void current_time_print(ble_cts_c_evt_t * p_evt)
{
    NRF_LOG_INFO(&amp;quot;\r\nCurrent Time:&amp;quot;);
    NRF_LOG_INFO(&amp;quot;\r\nDate:&amp;quot;);

    NRF_LOG_INFO(&amp;quot;\tDay of week   %s&amp;quot;, (uint32_t)day_of_week[p_evt-&amp;gt;
                                                         params.
                                                         current_time.
                                                         exact_time_256.
                                                         day_date_time.
                                                         day_of_week]);

    if (p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time.day == 0)
    {
        NRF_LOG_INFO(&amp;quot;\tDay of month  Unknown&amp;quot;);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;\tDay of month  %i&amp;quot;,
                       p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time.day);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/65357/mktime-in-nordic-calendar-example-is-not-taking-local-time-into-account/268629"]I am not an expert in thsi example [/quote]
&lt;p&gt;I really appreciate all your help and the time you spent looking into this for me, but would it be possible in this case to reassign this ticket to someone who is an expert in the time-handling aspects of the SDK?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As far as I can tell, mktime() assumes your input is in local time and should take your timezone into account. For example, it is evident from&amp;nbsp;&lt;a href="https://stackoverflow.com/questions/530519/stdmktime-and-timezone-info"&gt;this post on Stackoverflow&lt;/a&gt;&amp;nbsp;that in the default C implementation, it should not be possible to interpret the input to mktime() as being from UTC (i.e., strip it of its timezone info) if timezone info is included.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you check this nordic sample function&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/nrf5-calendar-example/blob/master/nrf_calendar.c#L50"&gt;here&lt;/a&gt;, you can see that it doesn&amp;#39;t take timezone into account; by separating out all the hour, min, etc. variables, the timezone info gets stripped. Ok fine, I can rewrite it to put timezone info back. But in order to rewrite it, I need to know how nordic encodes timezone info when a timestamp comes in over CTS.--&amp;gt;&amp;nbsp;&lt;strong&gt;Question 1: where is timezone info encoded in the this structure?&amp;nbsp;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;also: I have printed out the timestamp from this structure when I receive it from CTS, and it is accurate in local time. For example, if it is 14:00 where I am, it shows me 14:00, not whatever time it is in UTC. However, I notice that all of the &amp;quot;adjust reasons&amp;quot; are 0, including &amp;quot;change_of_timezone&amp;quot;, so maybe this is part of the problem. But there isn&amp;#39;t a lot of documentation on what &amp;quot;adjust reasons&amp;quot; mean (see &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fble_sdk_app_cts_c.html"&gt;nordic documentation page here&lt;/a&gt;). --&amp;gt;&amp;nbsp;&lt;strong&gt;Question 2: under what conditions are each of the 4 &amp;quot;adjust reasons&amp;quot; set to 0 or 1?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/268629?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 06:20:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f071a030-7514-470e-a793-803e8523cca8</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Sorry for the delayed response nordev. This is just a demo project from Nordic and not an official example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1) It looks like it is the interpretation logic that the timer_struct.tm_month takes the same indexing as the month.&amp;nbsp;Seems like this does not match what we expect for the tm_month to store.&lt;/p&gt;
&lt;p&gt;2)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The calendar example does not have the member&amp;nbsp;&lt;span&gt;p_evt-&amp;gt;params.current_time.exact_time_256.day_date_time.date_time as far as i can see it. I am not an expert in thsi example but I think with the given workarounds in the other threads you mentioned, this is being used by many others. I guess the issue here is about the interpretation of data we get rather than the contents.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: mktime() in nordic calendar example is not taking local time into account?</title><link>https://devzone.nordicsemi.com/thread/267474?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 13:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc28e010-7523-419d-96eb-a1e605163e10</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hmm,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am a bit unsure about the indexing issue here, i need to study the library. I will come back to you tomorrow, sorry for the delay in response.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>