Skip to content

Commit

Permalink
Add Day of Week
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Feb 20, 2021
1 parent 66809c2 commit 5adbd23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ SOFTWARE. */
// Use SPIFFS Editor
//
#ifndef SPIFFSEDIT
// #define SPIFFSEDIT
#define SPIFFSEDIT
#endif
//
//////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 15 additions & 1 deletion src/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ SOFTWARE. */

#include "ntp.h"

static const int __attribute__((unused)) SECS_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
static const char __attribute__((unused)) * DAY_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
static const char __attribute__((unused)) * DAY_OF_WEEK_SHORT[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

void setClock()
{
Ticker blinker;
Log.notice(F("Entering blocking loop to get NTP time."));
blinker.attach_ms(NTPBLINK, ntpBlinker);
unsigned long startSecs = millis() / 1000;
int cycle = 0;
while (time(nullptr) < EPOCH_1_1_2019)
while (time(nullptr) < SECS_1_1_2019)
{
configTime(THISTZ, TIMESERVER);
if ((millis() / 1000) - startSecs > 9)
Expand Down Expand Up @@ -126,6 +130,16 @@ int getWday()
return wday;
}

String getDayofWeek()
{
return DAY_OF_WEEK[getWday()];
}

String getShortDayofWeek()
{
return DAY_OF_WEEK_SHORT[getWday()];
}

int getHour()
{
// tm_hour = hours since midnight (0-23)
Expand Down
7 changes: 2 additions & 5 deletions src/ntp.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ SOFTWARE. */
#include <Ticker.h>
#include <ArduinoLog.h>


void setClock();
String getDTS();
int getYear(); // tm_year
int getMonth(); // tm_mon
int getDate(); // tm_mday
int getWday(); // tm_wday
String getDayofWeek();
String getShortDayofWeek();
int getHour(); // tm_hour
int getMinute(); // tm_min
int getSecond(); // tm_sec
int getYDay(); // tm_yday
void ntpBlinker();

static const int __attribute__((unused)) EPOCH_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
static const char __attribute__((unused)) * DAYS_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
static const char __attribute__((unused)) * DAYS_OF_WEEK_3[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

#endif // _NTP_H

0 comments on commit 5adbd23

Please sign in to comment.