Half-hour TimeZone supported

This commit is contained in:
csnol 2017-10-18 21:42:31 +08:00
parent c25957ee21
commit a89d0b935b
2 changed files with 24 additions and 1 deletions

16
STM32F1/libraries/RTClock/src/RTClock.cpp Normal file → Executable file
View File

@ -79,6 +79,22 @@
//to implement
}
*/
// Usage: 1. localtime = TimeZone(UnixTime, 9, 1) means SAT +09:30 TimeZone;
// 2. localtime = TimeZone(UnixTime, -3, 1) means NST,NFT -03:30 TimeZone;
// 3. TimeZone(UnixTime, 8, 0) same function as TimeZone(UnixTime, 8) -> CCT +08:00
time_t RTClock::TimeZone(time_t t, int TZ, bool HFZ) { // HFZ : Half-hour TimeZone flag
if(HFZ) {
if(TZ > 0 )
return ( t + (TZ * SECS_PER_HOUR) + 1800);
else
return ( t + (TZ * SECS_PER_HOUR) - 1800);
}
else
return ( t + (TZ * SECS_PER_HOUR));
}
//
void RTClock::setTime (tm_t & tmm) {
time_t mktm = makeTime(tmm); // time will be make to mktm

9
STM32F1/libraries/RTClock/src/RTClock.h Normal file → Executable file
View File

@ -15,6 +15,7 @@
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k
#define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
#define HALFTZ 0
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
#warning "Using private time_t definintion"
@ -71,8 +72,14 @@ class RTClock {
uint8_t minute(time_t t) { breakTime(t, tmm); return tmm.minute; }
uint8_t second(time_t t) { breakTime(t, tmm); return tmm.second; }
uint8_t isPM(time_t t) { return (hour(t)>=12); }
// Usage: localtime = TimeZone(UnixTime, 8);
time_t TimeZone(time_t t, int TZ) { return ( t + (TZ * SECS_PER_HOUR)); }
time_t TimeZone(time_t t, int TZ) { return ( t + (TZ * SECS_PER_HOUR)); } // usage: localtime = TimeZone(UnixTime, 8); // Beijing timezone = 8
// Usage: 1. localtime = TimeZone(UnixTime, 9, 1) means SAT +09:30 TimeZone;
// 2. localtime = TimeZone(UnixTime, -3, 1) means NST,NFT -03:30 TimeZone;
// 3. TimeZone(UnixTime, 8, 0) same function as TimeZone(UnixTime, 8) -> CCT +08:00
time_t TimeZone(time_t t, int TZ, bool HFZ); // HFZ : Half-hour TimeZone flag
void createAlarm(voidFuncPtr function, time_t alarm_time_t);
void createAlarm(voidFuncPtr function, struct tm_t & alarm_tm);