### Stamp Class Usage Example (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Provides a simple example demonstrating how to create a Stamp object, get its Unix time and string representation, convert it to a Datime structure, modify the Datime, and update the Stamp object from the modified Datime. ```CPP Stamp S (2023, 5, 8, 16, 26, 0); Serial.println (S.Getunix ()); Serial.println (S.Tostring ()); Datime D = S.Get (); Serial.println (D.Year); Serial.println (D.MONTH); Serial.println (D.Day); D.YEAR = 2022;// changed the year S.Set (D);// updated Stamp Serial.println (S.Tostring ()); ``` -------------------------------- ### StampSync Class Interface (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Documents the StampSync class, similar to Stampticker in using millis() after synchronization, but operates without an explicit ticker function. Provides methods for checking sync status and getting Unix time/milliseconds. ```CPP // Install the current unix, additionally milliseconds of synchronization StampSync (uint32_t unix, uint16_t ms = 0); // Install the current unix, additionally milliseconds of synchronization VOID update (uint32_t unix, uint16_t ms = 0); Bool Synced ();// Time synchronized uint32_t getunix ();// Get the current unix uint16_t ms ();// Get milliseconds of the current second; ``` -------------------------------- ### Simple StampKeeper Usage without Tick Source: https://github.com/gyverlibs/stamp/blob/main/README.md Initializes StampKeeper, sets the timezone, and performs a manual synchronization. Demonstrates how to get the current time string using `toString()` without relying on the `tick()` method for updates, showing that time progresses based on the initial sync time. ```C++ StampKeeper t; void setup() { Serial.begin(115200); setStampZone(3); // часовой пояс t.sync(1738237474); } void loop() { Serial.println(t.toString()); delay(2000); } ``` -------------------------------- ### Setting and Getting Timezone (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Functions to manage the global time zone used by the Stamp library. `setstampzone` sets the time zone in hours or minutes. `Getstampzone` retrieves the currently set global time zone. ```C++ VOID setstampzone (int Zone); int Getstampzone (); ``` -------------------------------- ### Datime Class Constructors (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Provides various constructors for initializing a Datime object, including a default constructor, one from a string, one from a Unix timestamp, and constructors from individual date/time components or packed values. ```C++ Datime() {} Datime(const char* str); Datime(uint32_t unix); Datime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); Datime(uint16_t yh, uint16_t mm, uint16_t ds); ``` -------------------------------- ### Advancing Datime to Next Unit (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Provides methods to advance the Datime object to the beginning of the next time unit (second, minute, hour, day, month). Includes a utility to update internal day/weekday values after manual date changes. ```C++ // ============= NEXT ============= // следующая секунда void nextSecond(); // следующая минута (xx:xx:00) void nextMinute(); // следующий час (xx:00:00) void nextHour(); // следующий день (00:00:00) void nextDay(); // следующий месяц (1 число 00:00:00) void nextMonth(); // обновить weekDay и yearDay исхо ``` -------------------------------- ### Datime Class Interface (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Provides the interface for the `Datime` class, including constructors for various initializations, methods for setting date/time components, functions for parsing strings in different formats, methods to export time as seconds or Unix time, functions to convert date/time to strings, methods to add time units, functions to advance time to the next unit, a method to update derived date components, and preprocessor definitions to select the time transformation algorithm. ```C++ // ============ Design =============== Datime; Datime (UNIX);// Unix Time Datime (year, month, day);// year, month, day Datime (Hour, Minute, Second);// hour, minute, second Datime (year, month, day, hor, minute, second); Datime (Consta Char* str);// Line of the type yyyy-mm-ddthh: mm: ss // ============= Installation ===================== VOID SET (UNIX);// Unix Time VOID SET (Year, Month, Day);// year, month, day VOID SET (Hour, Minute, Second);// hour, minute, second VOID SET (year, Month, Day, Hour, Minute, Second); // ============== Parsing ==================== Bool Parsedate (Consta Char* S);// from the line of the type yyyy-mm-dd Bool Parsetime (Consta Char* S);// from the line of the species hh: mm: ss Bool Parse (Const Char* S);// from the line of the type YYYY-MM-DD or hh: mm: ss or yyyy-mm-ddthh: mm: ss Bool Parsehttp (Consta Char* S);// from the line of species , dd yyyy hh: mm: ss // ============== EXPORT ======================== uint32_t toseconds ();// Bring time per second (excluding the date) uint32_t getunix ();// Bend into unix seconds // ============= In the line ====================== // Bring the date in the format "DD.mm.yyy" Char* DATETOChar (Char* BUF); String Datetostring (); // Bring the time in the format "hh: mm: ss" Char* Timetochar (Char* Buf); String Timetosting (); // Determine in DD.mm.yyyy hh: mm: ss, div - division Char* toChar (char* buf, char div = ''); String Tostring (Char Div = ''); // ============= add =================== VOID AddSeconds (Uint32_T S);// Add seconds VOID Addminutes (Uint32_T M);// Add minutes VOID Addhours (Uint32_T H);// Add a watch VOID Adddays (Uint32_T D);// Add days VOID NEXTSECOND ();// Next second VOID NEXTMINUTE ();// The next michicks (XX: XX: 00) VOID NEXTHOUR ();// Next hour (XX: 00: 00) VOID NEXTDAY ();// The next day (00:00:00) VOID NEXTMONTH ();// Next month (1st number 00:00:00) VOID updatedys ();// update Weekday and Yearday based on the current date (after manual change) // ============== Engorithm ====================== // The time transformation algorithm is set before connecting the library // for research and just so that it was #define unix_alg unix_alg_0 // ~ 402us and ~ 94b flash (avr) #define unix_alg unix_alg_1 // ~ 298us and ~ 138b flash (avr) #define unix_alg unix_alg_2 // ~ 216us and ~ 584b flash (avr) #define unix_alg unix_alg_3 // ~ 297us and ~ 178b flash (avr) #define unix_alg unix_alg_time_t // ~ 246us and ~ 842b flash (avr) ``` -------------------------------- ### Converting Datime to String (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Offers methods to format the date and time into standard string representations (dd.mm.yyyy, hh:mm:ss, or combined) using either character buffers for efficiency or Arduino String objects for convenience. ```C++ // ========== TO STRING ========== // вывести дату в формате "dd.mm.yyyy" [11]. Вернёт указатель на конец строки char* dateToChar(char* buf); // вывести дату в формате "dd.mm.yyyy" String dateToString(); // вывести время в формате "hh:mm:ss" [9]. Вернёт указатель на конец строки char* timeToChar(char* buf); // вывести время в формате "hh:mm:ss" String timeToString(); // вывести в формате "dd.mm.yyyy hh:mm:ss" [20]. Вернёт указатель на конец строки char* toChar(char* buf, char div = ' '); // вывести в формате "dd.mm.yyyy hh:mm:ss" String toString(char div = ' '); ``` -------------------------------- ### Comparing and Validating Datime (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Provides utility methods for comparing the current Datime object with others, checking for leap years, validating the date and time components, checking if the date is 01.01.2000 (Y2K), and calculating the day index within the year. ```C++ // =========== COMPARE =========== // сравнивается с Datime, uint32_t, DaySeconds // одинаковое время bool equals(const Datime& dt); // високосный ли год bool isLeap(); // дата и время корректны bool valid(); // дата 01.01.2000 bool isY2K(); // день года как индекс массива от 0 до 365 независимо от високосного года. 29 февраля имеет индекс 59 uint16_t dayIndex(); ``` -------------------------------- ### Basic StampKeeper Usage with Callbacks and Tick Source: https://github.com/gyverlibs/stamp/blob/main/README.md Initializes the StampKeeper object, sets the timezone, and registers callback functions for second ticks and synchronization events. Demonstrates how to use the `tick()` method to periodically update and display time/date information, access time components via `Datime` or direct methods, and compare time with different formats. The `tick()` method returns true once per second when synchronized. ```C++ StampKeeper rtc; // GyverNTP, GyverDS3231, Settings.rtc void setup() { Serial.begin(115200); // часовой пояс, установить до всех действий с объектами setStampZone(3); // обработчик секунды (вызывается из тикера) rtc.onSecond([]() { Serial.println("new second!"); }); // обработчик синхронизации (вызывается из sync) rtc.onSync([](uint32_t unix) { Serial.println("sync: "); Serial.print(unix); }); // синхронизация вручную для примера // rtc.sync(1738237474); } void loop() { // тикер вернёт true каждую секунду в 0 мс секунды, если время синхронизировано if (rtc.tick()) { // вывод даты и времени строкой Serial.print(rtc.toString()); // rtc.timeToString(), rtc.dateToString() Serial.print(':'); Serial.println(rtc.ms()); // + миллисекунды текущей секунды. Внутри tick всегда равно 0 // вывод в Datime Datime dt = rtc; // или Datime dt(rtc) dt.year; dt.second; dt.hour; dt.weekDay; dt.yearDay; // ... и прочие методы и переменные Datime // чтение напрямую, медленнее чем вывод в Datime rtc.second(); rtc.minute(); rtc.year(); // ... и прочие методы StampConvert // сравнение rtc == DaySeconds(12, 35, 0); // сравнение с DaySeconds (время равно 12:35:00) rtc == 1738237474; // сравнение с unix rtc == Datime(2025, 1, 30, 14, 14, 30); // сравнение с Datime } if (rtc.newSecond()) { // новую секунду можно поймать и здесь } } ``` -------------------------------- ### Stamputils Utility Functions (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Documents a collection of static utility functions for date and time calculations, including conversions between time components, checking for leap years, calculating days in months/years, and converting dates to various formats (weekday, days from 2000, Unix time). ```CPP // Time per second uint32_t Stamputils :: Timetoseconds (Uint8_t Hours, Uint8_t Minutes, Uint8_T Seconds); // leap year Bool Stamputils :: isleap (uint16_t year); // days in the month without accounting for the year (February 28) uint8_t Stamputils :: Daysinmonth (Uint8_t Month); // days in the month taking into account the leap year uint8_t Stamputils :: Daysinmonth (Uint8_t Month, Uint16_t Year); // Days of the year to the month (Jan 0, Feb 31, March 59/60 ...) uint16_t Stamputils :: Daystomonth (Uint8_t Month, Uint16_t Year); // Date on the day of the current year (starting with 1) uint16_t Stamputils :: DateToyearday (Uint8_t Day, Uint8_t Month, Uint16_t Year); // Date on the day of the week (PN 1 .. Sun 7) uint8_t Stamputils :: DateTeWeekday (Uint8_t Day, Uint8_t Month, Uint16_T Year); // Date in the number of days from 01.01.2000 (starting with 0) uint16_t Stamputils :: DateTodays2000 (Uint8_t Day, Uint8_t Month, Uint16_T Year); // Date in UNIX time, zone in minutes uint32_t Stamputils :: DateTouNix (Uint8_t Day, Uint8_t Month, Uint16_t Year, Uint8_t Hour, Uint8_t Minute, Uint8_T Seconds, Int16_T Zone = 0); ``` -------------------------------- ### Parsing Strings into Datime (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Includes methods for parsing date and time information from strings in various common formats (yyyy-mm-dd, hh:mm:ss, combined, and HTTP format) and updating the Datime object accordingly. Returns a boolean indicating parsing success. ```C++ // ========== PARSE ========== // yyyy-mm-dd bool parseDate(const char* s); // hh:mm:ss bool parseTime(const char* s); // hh:mm:ss или yyyy-mm-dd или yyyy-mm-ddThh:mm:ss bool parse(const char* s); // , dd yyyy hh:mm:ss bool parseHTTP(const char* s); ``` -------------------------------- ### Stamp Class Interface (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Documents the constructors, setters, parsers, export methods, and string conversion functions for the basic Stamp class, which stores time as a uint32_t Unix timestamp. ```CPP // ============ Design =============== Stamp; Stamp (uint32_t unix);// from UNIX Stamp (Datime & DT);// from Datime Stamp (year, month, day);// year, month, day Stamp (Hour, Minute, Second);// hour, minute, second Stamp (const char* str);// from the line of the type YYYY-MM-DD or hh: mm: ss or yyyy-mm-ddthh: mm: ss Stamp (year, month, day, hor, minute, second); // =========== Institute ================= VOID SET (Datime & DT);// Install from Datime VOID SET (Year, Month, Day);// year, month, day VOID SET (Hour, Minute, Second);// hour, minute, second VOID SET (year, Month, Day, Hour, Minute, Second); Bool Parse (Const Char* S);// from the line of the type YYYY-MM-DD or hh: mm: ss or yyyy-mm-ddthh: mm: ss Bool Parsehttp (Consta Char* S);// from the line of species , dd yyyy hh: mm: ss // ============== EXPORT ======================== Datime Get ();// Export to Datime format Void Get (Datime & DT);// Export to the Datime type variable uint32_t toseconds ();// Get seconds uint32_t Tominutes ();// Get minutes uint32_t tohours ();// Get a clock uint32_t Todays ();// Get a day // ============= In a line ====================== // Bring the date in the format "DD.mm.yyy" Char* DATETOChar (Char* BUF); String Datetostring (); // Bring the time in the format "hh: mm: ss" Char* Timetochar (Char* Buf); String Timetosting (); // Determine in DD.mm.yyyy hh: mm: ss, div - division Char* toChar (char* buf, char div = ''); String Tostring (Char Div = ''); ``` -------------------------------- ### Stampticker Class Interface (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Documents the Stampticker class, which uses millis() for timekeeping after synchronization, provides a ticker function for updates, and supports attaching a handler for second-interval events. ```CPP // Install the current unix, additionally milliseconds of synchronization Stampticker (uint32_t unix, uint16_t ms = 0); // Install the current unix, additionally milliseconds of synchronization VOID update (uint32_t unix, uint16_t ms = 0); VOID Attach (F);// Connect the function-processor of the operation (type VOID F ()) VOID Detach ();// Disconnect the function-cutter Bool Ready ();// Returns True every second Bool Synced ();// Time synchronized uint16_t ms ();// Get milliseconds of the current second uint32_t calcunix ();// Calculate and get the current unix // ticker, call in LOOP.Unix updates once a second.Will return True every second taking into account MS synchronization Bool Tick (); ``` -------------------------------- ### Exporting Datime Values (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Provides methods to convert the current Datime value into different numerical representations, specifically the number of seconds elapsed since the beginning of the current day and the total number of seconds since the Unix epoch (Unix timestamp). ```C++ // =========== EXPORT ============ // вывести в секунды с начала текущих суток uint32_t daySeconds(); // вывести в unix-секунды uint32_t getUnix(); ``` -------------------------------- ### Setting Datime Values (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Documents the overloaded 'set' methods used to update the date and time stored in the Datime object. Allows setting from individual components, packed values, or a Unix timestamp based on the global timezone. ```C++ // ============= SET ============= // установить время (год, месяц, день, час, минута, секунда) void set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); // установить время (год, месяц, день) или (час, минута, секунда) void set(uint16_t yh, uint16_t mm, uint16_t ds); // установить из unix времени и глобального часового пояса setStampZone void set(uint32_t unix); ``` -------------------------------- ### Datime Class Members (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Defines the member variables of the Datime class used to store local date and time components, including year, month, day, hour, minute, second, weekday, and year day. Specifies the valid ranges for each component. ```C++ uint16_t year; // год uint8_t month; // месяц (1.. 12) uint8_t day; // день месяца (1.. 28-31) uint8_t hour; // час (0.. 23) uint8_t minute; // минута (0.. 59) uint8_t second; // секунда (0.. 59) uint8_t weekDay; // день недели (1 пн.. 7 вс) ISO 8601 uint16_t yearDay; // день года (1.. 365-366) ``` -------------------------------- ### Datime Structure Members (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README_EN.md Defines the structure or class members used by the `Datime` object to store date and time components. Includes year, month, day, hour, minute, second, weekday, and yearday, along with their expected ranges. ```C++ uint16_t year;// year uint8_t months;// month (1 .. 12) uint8_t day;// Day of the month (1 .. 28-31) Uint8_t Hour;// hour (0 .. 23) uint8_t minute;// minute (0 .. 59) uint8_t second;// second (0 .. 59) uint8_t Weekday;// Day of the week (1 Mon .. 7 Sun) ISO 8601 uint16_t soarday;// Day of the year (1 .. 365-366) // The indicated ranges are true for all other functions of the library! ``` -------------------------------- ### Adding Time to Datime (C++) Source: https://github.com/gyverlibs/stamp/blob/main/README.md Documents methods for adding specific durations (seconds, minutes, hours, days) to the current time stored in the Datime object. These operations are performed directly for speed, without intermediate conversion to Unix time. ```C++ // ============= ADD ============= // добавить секунды void addSeconds(uint32_t s); // добавить минуты void addMinutes(uint32_t m); // добавить часы void addHours(uint32_t h); // добавить дни void addDays(uint32_t d); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.