add day/year/month access for scripts so we can script a date display

This commit is contained in:
Tester23
2023-10-30 08:44:09 +01:00
parent a787c5821c
commit 5d617ca90c
3 changed files with 59 additions and 1 deletions

View File

@@ -252,6 +252,15 @@ float getHour(const char *s) {
float getSecond(const char *s) {
return NTP_GetSecond();
}
float getYear(const char *s) {
return NTP_GetYear();
}
float getMonth(const char *s) {
return NTP_GetMonth();
}
float getMDay(const char *s) {
return NTP_GetMDay();
}
const constant_t g_constants[] = {
//cnstdetail:{"name":"MQTTOn",
@@ -375,11 +384,21 @@ const constant_t g_constants[] = {
//cnstdetail:"descr":"Current second from NTP",
//cnstdetail:"requires":""}
{ "$second", &getSecond },
////cnstdetail:{"name":"$mday",
////cnstdetail:"title":"$mday",
////cnstdetail:"descr":"Current mday from NTP",
////cnstdetail:"requires":""}
{ "$mday", &getMDay },
////cnstdetail:{"name":"$month",
////cnstdetail:"title":"$month",
////cnstdetail:"descr":"Current month from NTP",
////cnstdetail:"requires":""}
//{ "$month", &getMonth },
{ "$month", &getMonth },
////cnstdetail:{"name":"$year",
////cnstdetail:"title":"$year",
////cnstdetail:"descr":"Current Year from NTP",
////cnstdetail:"requires":""}
{ "$year", &getYear },
//cnstdetail:{"name":"$NTPOn",
//cnstdetail:"title":"$NTPOn",
//cnstdetail:"descr":"Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0.",

View File

@@ -165,6 +165,42 @@ int NTP_GetSecond() {
return ltm->tm_sec;
}
int NTP_GetMDay() {
struct tm *ltm;
// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);
if (ltm == 0) {
return 0;
}
return ltm->tm_mday;
}
int NTP_GetMonth() {
struct tm *ltm;
// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);
if (ltm == 0) {
return 0;
}
return ltm->tm_mon+1;
}
int NTP_GetYear() {
struct tm *ltm;
// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);
if (ltm == 0) {
return 0;
}
return ltm->tm_year+1900;
}
#if WINDOWS
bool b_ntp_simulatedTime = false;
void NTP_SetSimulatedTime(unsigned int timeNow) {

View File

@@ -15,6 +15,9 @@ int NTP_GetWeekDay();
int NTP_GetHour();
int NTP_GetMinute();
int NTP_GetSecond();
int NTP_GetMDay();
int NTP_GetMonth();
int NTP_GetYear();
// for Simulator only, on Windows, for unit testing
void NTP_SetSimulatedTime(unsigned int timeNow);
// drv_ntp_events.c