Module datetime

Module datetime 

Source
Expand description

§DateTime Module

This module defines a DateTime struct and helper functions for representing, validating, and working with calendar date and time values in embedded systems.

§Features

  • Stores year, month, day, hour, minute, second
  • Built-in validation for all fields (including leap years and month lengths)
  • Setter and getter methods that enforce validity
  • Utility functions for leap year detection, days in a month, and weekday calculation

§Year Range

The default supported range is year >= 1970, which covers the widest set of popular RTC chips. For example:

  • DS1307, DS3231: 2000-2099

Drivers are responsible for checking and enforcing the exact year range of the underlying hardware. The DateTime type itself only enforces the lower bound (1970) to remain reusable in contexts outside RTCs.

§Weekday Format

  • This module uses 1=Sunday to 7=Saturday
  • Drivers must handle conversion if required

Structs§

DateTime
Date and time representation used across RTC drivers.

Enums§

DateTimeError
Errors that can occur when working with DateTime
Weekday
Day of the week (1 = Sunday .. 7 = Saturday)

Functions§

calculate_weekday
Calculate the day of the week using Zeller’s congruence algorithm Returns 1=Sunday, 2=Monday, …, 7=Saturday
days_in_month
Get the number of days in a month
is_leap_year
Check if a year is a leap year