Skip to content
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

Added two new methods to return Date and Time as a struct and get formatted Date Time string with a given format #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

isharasampath
Copy link

Added bellow two methods to return Date and Time information together as a struct and formatted datetime string with a given format.

  • getDateTime

  • getFormattedDateTime

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

Please add the new function names to keywords.txt, using a true tab as a separator between the keyword and the identifier:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywordstxt-format

NTPClient.cpp Outdated Show resolved Hide resolved
NTPClient.h Outdated Show resolved Hide resolved
NTPClient.h Outdated Show resolved Hide resolved
NTPClient.h Outdated Show resolved Hide resolved
@isharasampath
Copy link
Author

Please add the new function names to keywords.txt, using a true tab as a separator between the keyword and the identifier:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywordstxt-format

Added new two methods to the keywords.txt

@per1234 per1234 dismissed their stale review March 20, 2020 08:36

Requested changes made. Thanks!

@isharasampath
Copy link
Author

Thanks for the review and the comments. Do we know when these changes going to merge and will be publicly available ?

@zzuutt
Copy link

zzuutt commented Apr 23, 2020

Hello,
is it possible to add this possiblility ?
in NTPClient.h
/** * Return the date time from the epochtime value as a String with the given format (Ex: %Y/%m/%d %H:%M:%S) */ String getFormattedDateTime(const char* dateTimeFormat, time_t t) const;

in NTPClient.cpp
String NTPClient::getFormattedDateTime(const char* dateTimeFormat, time_t t = 0) const { struct tm * ts; time_t rawTime = t ? t : this->getEpochTime(); ts = localtime(&rawTime); char buf[64]; strftime(buf, sizeof(buf), dateTimeFormat, ts); return String(buf); }

that may be useful

@isharasampath
Copy link
Author

Hello,
is it possible to add this possiblility ?
in NTPClient.h
/** * Return the date time from the epochtime value as a String with the given format (Ex: %Y/%m/%d %H:%M:%S) */ String getFormattedDateTime(const char* dateTimeFormat, time_t t) const;

in NTPClient.cpp
String NTPClient::getFormattedDateTime(const char* dateTimeFormat, time_t t = 0) const { struct tm * ts; time_t rawTime = t ? t : this->getEpochTime(); ts = localtime(&rawTime); char buf[64]; strftime(buf, sizeof(buf), dateTimeFormat, ts); return String(buf); }

that may be useful

I think this is something more of a utility functions which NTPClient not directly involving. Passing epochtime from outside and getting it formatted is not part of a job in NTPClient.

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

Copy link

@MPParsley MPParsley left a comment

Choose a reason for hiding this comment

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

Would be nice if we could have this in.

'class NTPClient' has no member named 'getFormattedDate'; did you mean 'getFormattedTime'?

@isharasampath
Copy link
Author

Would be nice if we could have this in.

'class NTPClient' has no member named 'getFormattedDate'; did you mean 'getFormattedTime'?

getFormattedDateTime method will return the formatted date, time or datetime string according to the given format.

Ex:
datetime patter: %Y/%m/%d %H:%M:%S or %Y-%m-%d %H:%M:%S
date pattern: %Y/%m/%d
time pattern: %H:%M:%S

@per1234 per1234 added topic: code Related to content of the project itself type: enhancement Proposed improvement labels Jan 30, 2022
@nona00
Copy link

nona00 commented May 15, 2022

will this enhancement be merged to main branch?

@iabe2561
Copy link

will this enhancement be merged to main branch?

I'm also waiting for the same

@m4nzm333
Copy link

Not merged yet?

@dawidadach
Copy link

Is there any particular reason why that wasn't merged yet?

@probonopd
Copy link

probonopd commented Apr 15, 2023

Is anything holding back timeClient.getFormattedDateTime()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants