21#include "pico/stdlib.h"
27#include "hardware/rtc.h"
47 static struct tm
nowTm();
54 static datetime_t nowDatetime();
67 static struct tm
todayAt(const struct tm *hhmmss);
92 static void print(time_t t);
98 static void print(
const struct tm *t);
106 static void print(
const datetime_t *dt);
110 time_t t =
static_cast<time_t
>(timestamp);
112 localtime_r(&t, &tm);
113 return TimeOfDay{
static_cast<uint8_t
>(tm.tm_hour),
static_cast<uint8_t
>(tm.tm_min),
static_cast<uint8_t
>(tm.tm_sec) };
117 uint32_t days = timestamp / 86400;
118 uint8_t weekday = (days + 4) % 7;
119 return static_cast<DaysOfWeek>(1u << weekday);
123 uint32_t days = timestamp / 86400;
124 uint8_t weekday = (days + 4) % 7;
125 return static_cast<Day>(1u << weekday);
Defines a bitmask enum for days of the week.
Day
Enum for days of the week as bitmask flags.
uint8_t DaysOfWeek
Type alias for a set of days (bitmask).
A simple representation of wall-clock time (HH:MM or HH:MM:SS)
Cross-platform time utilities for RP2040 and RP2350.
static DaysOfWeek dayOfWeekBitmask(uint32_t timestamp)
static TimeOfDay toTimeOfDay(uint32_t timestamp)
Print a datetime_t to stdout.
static void printNow()
Print the current time to stdout.
static Day dayOfWeek(uint32_t timestamp)
static struct tm todayAt(const struct tm *hhmmss)
Construct today's date with a specific time-of-day.
static std::string formatIso8601(time_t t)
static struct tm nowTm()
Get the current local time as struct tm.
static time_t now()
Get the current epoch time using platform RTC or AON.
static time_t todayAtTimeT(const struct tm *hhmmss)
Convert a tm with today's date and time to epoch.
static void print(time_t t)
Print a given UNIX timestamp to stdout.
static std::string todayHhMmSsString(const struct tm *hhmmss)
Convert a time-of-day to a string for today.
static std::string getNowHhMmSs()
Get the current time as a datetime_t.
A simple value type representing a time of day (hour, minute, second).