Real Time Clock. get time-str, set time.

Dependencies:   StrLib

Committer:
AkinoriHashimoto
Date:
Wed Nov 25 09:56:26 2015 +0000
Revision:
6:605138b5eef6
Parent:
5:82e566457502
ADJ TimeZone

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:006ab0d7b90f 1 #pragma once
AkinoriHashimoto 0:006ab0d7b90f 2
AkinoriHashimoto 0:006ab0d7b90f 3 #include "mbed.h"
AkinoriHashimoto 0:006ab0d7b90f 4 #include <string>
AkinoriHashimoto 0:006ab0d7b90f 5
AkinoriHashimoto 0:006ab0d7b90f 6 #include "StrLib.h"
AkinoriHashimoto 0:006ab0d7b90f 7
AkinoriHashimoto 0:006ab0d7b90f 8 /** Real Time Clock library
AkinoriHashimoto 5:82e566457502 9 *
AkinoriHashimoto 0:006ab0d7b90f 10 */
AkinoriHashimoto 0:006ab0d7b90f 11 class RealTimeClock
AkinoriHashimoto 0:006ab0d7b90f 12 {
AkinoriHashimoto 0:006ab0d7b90f 13 public:
AkinoriHashimoto 5:82e566457502 14 /** Time Zone */
AkinoriHashimoto 5:82e566457502 15 enum TimeZone {
AkinoriHashimoto 5:82e566457502 16 UTC, GMT, JST, EST, CST, MST, PST
AkinoriHashimoto 5:82e566457502 17 };
AkinoriHashimoto 5:82e566457502 18
AkinoriHashimoto 5:82e566457502 19 RealTimeClock(TimeZone tz= JST);
AkinoriHashimoto 5:82e566457502 20 RealTimeClock(float hour);
AkinoriHashimoto 5:82e566457502 21
AkinoriHashimoto 0:006ab0d7b90f 22 /** @rtnval YY/MM/DD */
AkinoriHashimoto 0:006ab0d7b90f 23 string getYMD8();
AkinoriHashimoto 0:006ab0d7b90f 24
AkinoriHashimoto 0:006ab0d7b90f 25 /** @rtnval YYMMDD */
AkinoriHashimoto 0:006ab0d7b90f 26 string getYMD6();
AkinoriHashimoto 0:006ab0d7b90f 27
AkinoriHashimoto 0:006ab0d7b90f 28 /** @rtnval HH:MM:SS */
AkinoriHashimoto 0:006ab0d7b90f 29 string getHMS8();
AkinoriHashimoto 0:006ab0d7b90f 30
AkinoriHashimoto 0:006ab0d7b90f 31 /** @rtnval HHMMSS */
AkinoriHashimoto 0:006ab0d7b90f 32 string getHMS6();
AkinoriHashimoto 0:006ab0d7b90f 33
AkinoriHashimoto 0:006ab0d7b90f 34 /**
AkinoriHashimoto 4:d1c394cd7b63 35 * @param 'seconds' from 1970/01/01.
AkinoriHashimoto 0:006ab0d7b90f 36 * @rtnval success(true), failure(false)
AkinoriHashimoto 0:006ab0d7b90f 37 */
AkinoriHashimoto 5:82e566457502 38 bool setRealTime(string str);
AkinoriHashimoto 0:006ab0d7b90f 39
AkinoriHashimoto 0:006ab0d7b90f 40 /**
AkinoriHashimoto 0:006ab0d7b90f 41 * @param seconds from 1970/01/01.
AkinoriHashimoto 0:006ab0d7b90f 42 * @rtnval void
AkinoriHashimoto 0:006ab0d7b90f 43 */
AkinoriHashimoto 5:82e566457502 44 bool setRealTime(long now);
AkinoriHashimoto 5:82e566457502 45
AkinoriHashimoto 5:82e566457502 46 void setTimeZone(TimeZone tz);
AkinoriHashimoto 5:82e566457502 47 void setTimeZone(float hour);
AkinoriHashimoto 4:d1c394cd7b63 48
AkinoriHashimoto 4:d1c394cd7b63 49 private:
AkinoriHashimoto 4:d1c394cd7b63 50 time_t secRT; // secondsRealTime. JST; 9hour
AkinoriHashimoto 5:82e566457502 51 int offsetTimeZone; // [s]. internal TimeZone val.
AkinoriHashimoto 4:d1c394cd7b63 52 char buf[14]; // using for strftime()
AkinoriHashimoto 4:d1c394cd7b63 53 string bufTmp; // return value
AkinoriHashimoto 4:d1c394cd7b63 54 void setSecondsRealTime(); // set secRt;
AkinoriHashimoto 0:006ab0d7b90f 55
AkinoriHashimoto 0:006ab0d7b90f 56 };