Table of Contents

Date and Time

About this document

This document describes how .NET nanoFramework handles Date & Time and the available option regarding this matter.

UTC and local time

Time (and date) is fundamental for the inner works of .NET nanoFramework. But an application running on top of it can make use of it, or not, thus making relevant the discussion and evaluation of the related features and associated code. Because .NET nanoFramework runs on constrained resources platforms inclusion of features that increase both RAM and FLASH usage has to be considered and evaluated.

DateTime supports the use of Local and UTC times by its DateTime.Kind property. Supporting this requires adding several blocks such as: an API for setting the platform timezone, handling the huge number of available timezones, managing the daylight savings changes, manage conversion to/from the different kinds, etc.

Considering all the above, .NET nanoFramework addresses this matter providing the absolute minimal viable options. There is support for DateTime (obviously) but all DateTime are considered UTC. There is no support for DateTime.Kind.Local, setting timezone or converting to/from the different kinds. If an application requires this, it has to implement it at its own level.

Time source

The time base source is, by default, the SysTick available in the CMSIS RTOS API. This is the source of the time when a DateTime object is instantiated.

Because almost all hardware platforms capable of running .NET nanoFramework include an hardware RTC this peripheral can be used as the source for time objects. Note that for all other internals of .NET nanoFramework the CMSIS RTOS API SysTick keeps being used as the time base.

This option is exposed to the board designer by the NF_FEATURE_RTC configuration option. Setting it to ON when calling CMake brings in the RTC subsystem and all the calls to DateTime make use of the time base provided by this peripheral.

RTC and hardware

Leveraging the RTC hardware peripheral allows several interesting/valuable features:

  • more accurate timekeeping (when compared with a regular timer);
  • possibility for timekeeping in sleep/deep sleep modes;
  • setting alarms to wake-up the system at a future time;