Skip to content

Add function getYears, getMonths, getDays #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions NTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ int NTPClient::getMinutes() const {
int NTPClient::getSeconds() const {
return (this->getEpochTime() % 60);
}
int NTPClient::getYears() const {
time_t rawtime = this->getEpochTime();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use two spaces for indentation instead of four.

struct tm* ti;
ti = localtime(&rawtime);
int year = ti->tm_year + 1900;
return year;
}
int NTPClient::getMonths() const {
time_t rawtime = this->getEpochTime();
struct tm* ti;
ti = localtime(&rawtime);
int month = (ti->tm_mon + 1) < 10 ? 0 + (ti->tm_mon + 1) : (ti->tm_mon + 1);
return month;
}
int NTPClient::getDays() const {
time_t rawtime = this->getEpochTime();
struct tm* ti;
ti = localtime(&rawtime);
int day = (ti->tm_mday) < 10 ? 0 + (ti->tm_mday) : (ti->tm_mday);
return day;
}

String NTPClient::getFormattedTime() const {
unsigned long rawTime = this->getEpochTime();
Expand Down
3 changes: 3 additions & 0 deletions NTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class NTPClient {
int getHours() const;
int getMinutes() const;
int getSeconds() const;
int getYears() const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use two spaces for indentation instead of tab.

int getMonths() const;
int getDays() const;

/**
* Changes the time offset. Useful for changing timezones dynamically
Expand Down