Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:82e566457502, committed 2015-11-24
- Comitter:
- AkinoriHashimoto
- Date:
- Tue Nov 24 07:09:30 2015 +0000
- Parent:
- 4:d1c394cd7b63
- Child:
- 6:605138b5eef6
- Commit message:
- Add setTimeZone(),; Adj. to treat Epoch time.
Changed in this revision
| RealTimeClock.cpp | Show annotated file Show diff for this revision Revisions of this file |
| RealTimeClock.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/RealTimeClock.cpp Thu Nov 19 07:56:35 2015 +0000
+++ b/RealTimeClock.cpp Tue Nov 24 07:09:30 2015 +0000
@@ -1,8 +1,18 @@
#include "RealTimeClock.h"
+RealTimeClock::RealTimeClock(TimeZone tz)
+{
+ setTimeZone(tz);
+}
+RealTimeClock::RealTimeClock(float hour)
+{
+ setTimeZone(hour);
+}
+
void RealTimeClock::setSecondsRealTime()
{
secRT = time(NULL);
+ secRT += this->offsetTimeZone;
return;
}
@@ -37,16 +47,17 @@
}
-bool RealTimeClock::setRealTime(string str, bool JPN)
+//bool RealTimeClock::setRealTime(string str, bool JPN)
+bool RealTimeClock::setRealTime(string str)
{
- // now is in range of appropriate time.
- return setRealTime(A2I(str, 10), JPN);
+ // now is in range of appropriate time.
+ return setRealTime(A2I(str, 10));//, JPN);
}
-bool RealTimeClock::setRealTime(long now, bool JPN)
+//bool RealTimeClock::setRealTime(long now, bool JPN)
+bool RealTimeClock::setRealTime(long now)
{
- if(JPN)
- now += 3600* 9; // + JST 9hour.
+// if(JPN) now += 3600* 9; // + JST 9hour.
// 1,427,597,183(ISO 8601形式: 2015/03/29 02:46:23Z)
// 2,147,483,647秒を経過した (2038/01/19 03:14:07)
if(!(1427597183<now && now<2147483600))
@@ -57,4 +68,32 @@
return true;
}
+void RealTimeClock::setTimeZone(TimeZone tz)
+{
+ float hour= 0;
+ if(UTC || GMT)
+ hour= 0;
+ if(JST)
+ hour= +9;
+ if(EST)
+ hour= -5;
+ if(CST)
+ hour= -6;
+ if(MST)
+ hour= -7;
+ if(PST)
+ hour= -8;
+
+ this->setTimeZone(hour);
+
+ return;
+}
+void RealTimeClock::setTimeZone(float hour)
+{
+ this->offsetTimeZone= (int)(hour* 3600);
+
+ return;
+}
+
+
// End of File
\ No newline at end of file
--- a/RealTimeClock.h Thu Nov 19 07:56:35 2015 +0000
+++ b/RealTimeClock.h Tue Nov 24 07:09:30 2015 +0000
@@ -6,11 +6,19 @@
#include "StrLib.h"
/** Real Time Clock library
- *
+ *
*/
class RealTimeClock
{
public:
+ /** Time Zone */
+ enum TimeZone {
+ UTC, GMT, JST, EST, CST, MST, PST
+ };
+
+ RealTimeClock(TimeZone tz= JST);
+ RealTimeClock(float hour);
+
/** @rtnval YY/MM/DD */
string getYMD8();
@@ -27,16 +35,20 @@
* @param 'seconds' from 1970/01/01.
* @rtnval success(true), failure(false)
*/
- bool setRealTime(string str, bool JPN= true);
+ bool setRealTime(string str);
/**
* @param seconds from 1970/01/01.
* @rtnval void
*/
- bool setRealTime(long now, bool JPN= true);
+ bool setRealTime(long now);
+
+ void setTimeZone(TimeZone tz);
+ void setTimeZone(float hour);
private:
time_t secRT; // secondsRealTime. JST; 9hour
+ int offsetTimeZone; // [s]. internal TimeZone val.
char buf[14]; // using for strftime()
string bufTmp; // return value
void setSecondsRealTime(); // set secRt;