This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About leap years in the nrf5-calendar-example.

Hi all,

I want to implement a calendar that can be used for many years with nRF52840. 

Will leap years be corrected in the nrf5-calendar-example? I looked at the code a bit, but couldn't know if the sample-code corresponded to a leap year.

https://github.com/NordicPlayground/nrf5-calendar-example

If I set the data for a leap year and it works correctly, can I say that it supports all leap years?

Or is there a library to correct leap years?

I think the RTC of nrf52840 is a counter and the calendar (and date and time) is implemented in the library. Is my understanding correct?

Best Regards,

Yukio Oyama

  • Hi Yukio,

    Will leap years be corrected in the nrf5-calendar-example?

    The sample is based on time.h and its function localtime(), so it might be the case. 

    If I set the data for a leap year and it works correctly, can I say that it supports all leap years?

    I would say that is a sane assumption to make. However it might be different for leap seconds.

    To verify both of these you could build and test the sample and cross check with a simple open source sample for localtime() to validate. If you set the date and time to a point in time close to when it should change to something (23:59, the 28th of february 2022), it should go to (00:00, the 1st of march 2022) after a minute. If it goes to Feb. 29th on a non-leap year, it is also could be that this sample is based on a calendar model that assumes that every month has 31 days. In that case you would also need to implement something that checks if the month has 30, 31 or 28 days, and if it is a leap year. 

    Please note that this sample is only a demo-sample and it is hence provided as-is, without any warranty, and redistribution and use of source with or without modifications must meet the conditions written in the project code.

    Or is there a library to correct leap years?

    Unless time.h handles this, there might be some open source code online that handles this. Currently we have no other samples or libraries that explicitly does this.

    I think the RTC of nrf52840 is a counter and the calendar (and date and time) is implemented in the library. Is my understanding correct?

    From our infocenter pages concerning Real-time counter (RTC) we have that the "module provides a generic, low power timer on the low-frequency clock source (LFCLK).". The date and time part of this comes from using this timer as input to the time.h libraries.

    I hope this clarifies things for you!

    Kind regards,
    Andreas

  • Hi Andreas-san,

    Thank you for your advice.

    Do you mean the following?

    "The localtime() in the C standard library supports leap years. the nrf5-calendar-example uses localtime() so leap years are supported."

    "There is no guarantee in the sample code, so I have to try any patterns of dates and times myself to see it. "

    And, where is the RTC counter written as an input to the time.h library?

    According to your advice, I think I have no choice but to check it in real action.

    Thank you.

    BR

    Yukio Oyama

  • Hi Yukio,

    OYAMA YUKIO said:
    "The localtime() in the C standard library supports leap years. the nrf5-calendar-example uses localtime() so leap years are supported."

    I do not know if localtime() supports leap years, so I would recommend you verify this yourself by looking up the documentation for the functions in time.h. If localtime() supports leap years, there is a good chance that the nrf_calendar sample supports it as well.

    OYAMA YUKIO said:
    "There is no guarantee in the sample code, so I have to try any patterns of dates and times myself to see it. "

    Yes, that would be the safest!

    OYAMA YUKIO said:
    And, where is the RTC counter written as an input to the time.h library?

    How the RT Counter is defined and used together with time.h is written in the files nrf_calendar.c and nrf_calendar.h!

    OYAMA YUKIO said:
    According to your advice, I think I have no choice but to check it in real action.

    I can ask the employee who wrote this sample years ago if they know/remember when they return to the office, although this might take longer time than to examine the patterns yourself.

    I hope this is any help!

    Kind regards,
    Andreas

Related