Re: 32 bits time_t and Y2038 issue

Liste des GroupesRevenir à ca embedded 
Sujet : Re: 32 bits time_t and Y2038 issue
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.arch.embedded
Date : 11. Mar 2025, 17:32:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vqpoi3$226ih$1@dont-email.me>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 11/03/2025 16:22, pozz wrote:
I have an embedded project that is compiled in Atmel Studio 7.0. The target is and ARM MCU, so the toolchain is arm-gnu-toolchain. The installed toolchain version is 6.3.1.508. newlib version is 2.5.0.
 
I /seriously/ dislike Microchip's way of handling toolchains.  They work with old, outdated versions, rename and rebrand them and their documentation to make it look like they wrote them themselves, then add license checks and software locks so that optimisation is disabled unless you pay them vast amounts of money for the software other people wrote and gave away freely.  To my knowledge, they do not break the letter of the license for GCC and other tools and libraries, but they most certainly break the spirit of the licenses in every way imaginable.
Prior to being bought by Microchip, Atmel was bad - but not as bad.
So if for some reason I have no choice but to use a device from Atmel / Microchip, I do so using tools from elsewhere.
As a general rule, the gcc-based toolchains from ARM are the industry standard, and are used as the base by most ARM microcontroller suppliers.  Some include additional library options, others provide the package as-is.  For anything other than a quick demo, my preferred setup is using makefiles for the build along with an ARM gcc toolchain.  That way I can always build my software, from any system, and archive the toolchain.  (One day, I will also try using clang with these packages, but I haven't done so yet.)
Any reasonably modern ARM gcc toolchain will have 64-bit time_t.  I never like changing toolchains on an existing project, but you might make an exception here.
However, writing functions to support time conversions is not difficult.   The trick is not to start at 01.01.1970, but start at a convenient date as early as you will need to handle - 01.01.2025 would seem a logical point.  Use <https://www.unixtimestamp.com/> to get the time_t constant for the start of your epoch.
To turn the current time_t value into a human-readable time and date, first take the current time_t and subtract the epoch start.  Divide by 365 * 24 * 60 * 60 to get the additional years.  Divide the leftovers by 24 * 60 * 60 to get the additional days.  Use a table of days in the months to figure out the month.  Leap year handling is left as an exercise for the reader (hint - 2100, 2200 and 2300 are not leap years, while 2400 is).  Use the website I linked to check your results.
Or you can get the sources for a modern version of newlib, and pull the routines from there.
David

In this build system the type time_t is defined as long, so 32 bits.
 I'm using time_t mainly to show it on a display for the user (as a broken down time) and tag with a timestamp some events (that the user will see as broken down time).
 The time can be received by Internet or by the user, if the device is not connected. In both cases, time_t is finally used.
 As you know, my system will show the Y2038 issue. I don't know if some of my devices will be active in 2038, anyway I'd like to fix this potential issue now.
 One possibility is to use a modern toolchain[1] that most probably uses a new version of newlib that manages 64 bits time_t. However I think I should address several warnings and other problems after upgrading the toolchain.
 Another possibility is to rewrite my own my_mktime(), my_localtime() and so on that accepts and returns my_time_t variables, defined as 64 bits. However I'm not capable in writing such functions. Do you have some implementations? I don't need full functional time functions, for example the timezone can be fixed at build time, I don't need to set it at runtime.
 Any suggestions?
  [1] https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-mingw-w64-i686-arm-none-eabi.zip

Date Sujet#  Auteur
11 Mar 25 * 32 bits time_t and Y2038 issue55pozz
11 Mar 25 `* Re: 32 bits time_t and Y2038 issue54David Brown
11 Mar 25  +* Re: 32 bits time_t and Y2038 issue10pozz
12 Mar 25  i`* Re: 32 bits time_t and Y2038 issue9David Brown
12 Mar 25  i `* Re: 32 bits time_t and Y2038 issue8pozz
12 Mar 25  i  `* Re: 32 bits time_t and Y2038 issue7David Brown
12 Mar 25  i   `* Re: 32 bits time_t and Y2038 issue6pozz
12 Mar 25  i    `* Re: 32 bits time_t and Y2038 issue5David Brown
13 Mar 25  i     `* Re: 32 bits time_t and Y2038 issue4pozz
13 Mar 25  i      `* Re: 32 bits time_t and Y2038 issue3David Brown
14 Mar 25  i       `* Re: 32 bits time_t and Y2038 issue2pozz
14 Mar 25  i        `- Re: 32 bits time_t and Y2038 issue1David Brown
12 Mar 25  +* Re: 32 bits time_t and Y2038 issue4pozz
12 Mar 25  i+- Re: 32 bits time_t and Y2038 issue1David Brown
14 Mar 25  i`* Re: 32 bits time_t and Y2038 issue2Waldek Hebisch
14 Mar 25  i `- Re: 32 bits time_t and Y2038 issue1pozz
15 Mar 25  `* Re: 32 bits time_t and Y2038 issue39Michael Schwingen
15 Mar 25   +* Re: 32 bits time_t and Y2038 issue2Grant Edwards
16 Mar 25   i`- Re: 32 bits time_t and Y2038 issue1Michael Schwingen
18 Mar 25   `* Re: 32 bits time_t and Y2038 issue36pozz
18 Mar 25    +* Re: 32 bits time_t and Y2038 issue34David Brown
18 Mar 25    i+* Re: 32 bits time_t and Y2038 issue7pozz
18 Mar 25    ii`* Re: 32 bits time_t and Y2038 issue6David Brown
21 Mar 25    ii `* Re: 32 bits time_t and Y2038 issue5Michael Schwingen
21 Mar 25    ii  +* Re: 32 bits time_t and Y2038 issue3David Brown
21 Mar 25    ii  i`* Re: 32 bits time_t and Y2038 issue2Michael Schwingen
22 Mar 25    ii  i `- Re: 32 bits time_t and Y2038 issue1David Brown
21 Mar 25    ii  `- Re: 32 bits time_t and Y2038 issue1Waldek Hebisch
18 Mar 25    i`* Re: 32 bits time_t and Y2038 issue26Michael Schwingen
18 Mar 25    i `* Re: 32 bits time_t and Y2038 issue25David Brown
18 Mar 25    i  +* Re: 32 bits time_t and Y2038 issue15Grant Edwards
18 Mar 25    i  i+* Re: 32 bits time_t and Y2038 issue13Hans-Bernhard Bröker
19 Mar 25    i  ii+* Re: 32 bits time_t and Y2038 issue10David Brown
19 Mar 25    i  iii`* Re: 32 bits time_t and Y2038 issue9Grant Edwards
19 Mar 25    i  iii `* Re: 32 bits time_t and Y2038 issue8David Brown
19 Mar 25    i  iii  +* Re: 32 bits time_t and Y2038 issue4Grant Edwards
19 Mar 25    i  iii  i`* Re: 32 bits time_t and Y2038 issue3David Brown
21 Mar 25    i  iii  i `* Re: 32 bits time_t and Y2038 issue2Michael Schwingen
21 Mar 25    i  iii  i  `- Re: 32 bits time_t and Y2038 issue1Grant Edwards
19 Mar 25    i  iii  `* Re: 32 bits time_t and Y2038 issue3Waldek Hebisch
20 Mar 25    i  iii   `* Re: 32 bits time_t and Y2038 issue2David Brown
21 Mar 25    i  iii    `- Re: 32 bits time_t and Y2038 issue1pozz
21 Mar 25    i  ii`* Re: 32 bits time_t and Y2038 issue2Michael Schwingen
21 Mar 25    i  ii `- Re: 32 bits time_t and Y2038 issue1Hans-Bernhard Bröker
19 Mar 25    i  i`- Re: 32 bits time_t and Y2038 issue1David Brown
21 Mar 25    i  `* Re: 32 bits time_t and Y2038 issue9Waldek Hebisch
21 Mar 25    i   `* Re: 32 bits time_t and Y2038 issue8David Brown
21 Mar 25    i    +- Re: 32 bits time_t and Y2038 issue1pozz
22 Mar 25    i    +* Re: 32 bits time_t and Y2038 issue4Hans-Bernhard Bröker
22 Mar 25    i    i`* Re: 32 bits time_t and Y2038 issue3David Brown
22 Mar 25    i    i `* Re: 32 bits time_t and Y2038 issue2Michael Schwingen
22 Mar 25    i    i  `- Re: 32 bits time_t and Y2038 issue1David Brown
22 Mar 25    i    `* Re: 32 bits time_t and Y2038 issue2Waldek Hebisch
22 Mar 25    i     `- Re: 32 bits time_t and Y2038 issue1David Brown
18 Mar 25    `- Re: 32 bits time_t and Y2038 issue1Michael Schwingen

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal