Skip to content

Commit a89d0b9

Browse files
committed
Half-hour TimeZone supported
1 parent c25957e commit a89d0b9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

STM32F1/libraries/RTClock/src/RTClock.cpp

100644100755
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@
7979
//to implement
8080
}
8181
*/
82+
83+
// Usage: 1. localtime = TimeZone(UnixTime, 9, 1) means SAT +09:30 TimeZone;
84+
// 2. localtime = TimeZone(UnixTime, -3, 1) means NST,NFT -03:30 TimeZone;
85+
// 3. TimeZone(UnixTime, 8, 0) same function as TimeZone(UnixTime, 8) -> CCT +08:00
86+
87+
time_t RTClock::TimeZone(time_t t, int TZ, bool HFZ) { // HFZ : Half-hour TimeZone flag
88+
if(HFZ) {
89+
if(TZ > 0 )
90+
return ( t + (TZ * SECS_PER_HOUR) + 1800);
91+
else
92+
return ( t + (TZ * SECS_PER_HOUR) - 1800);
93+
}
94+
else
95+
return ( t + (TZ * SECS_PER_HOUR));
96+
}
97+
//
8298

8399
void RTClock::setTime (tm_t & tmm) {
84100
time_t mktm = makeTime(tmm); // time will be make to mktm

STM32F1/libraries/RTClock/src/RTClock.h

100644100755
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
1616
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k
1717
#define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
18+
#define HALFTZ 0
1819

1920
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
2021
#warning "Using private time_t definintion"
@@ -71,8 +72,14 @@ class RTClock {
7172
uint8_t minute(time_t t) { breakTime(t, tmm); return tmm.minute; }
7273
uint8_t second(time_t t) { breakTime(t, tmm); return tmm.second; }
7374
uint8_t isPM(time_t t) { return (hour(t)>=12); }
75+
76+
// Usage: localtime = TimeZone(UnixTime, 8);
77+
time_t TimeZone(time_t t, int TZ) { return ( t + (TZ * SECS_PER_HOUR)); }
7478

75-
time_t TimeZone(time_t t, int TZ) { return ( t + (TZ * SECS_PER_HOUR)); } // usage: localtime = TimeZone(UnixTime, 8); // Beijing timezone = 8
79+
// Usage: 1. localtime = TimeZone(UnixTime, 9, 1) means SAT +09:30 TimeZone;
80+
// 2. localtime = TimeZone(UnixTime, -3, 1) means NST,NFT -03:30 TimeZone;
81+
// 3. TimeZone(UnixTime, 8, 0) same function as TimeZone(UnixTime, 8) -> CCT +08:00
82+
time_t TimeZone(time_t t, int TZ, bool HFZ); // HFZ : Half-hour TimeZone flag
7683

7784
void createAlarm(voidFuncPtr function, time_t alarm_time_t);
7885
void createAlarm(voidFuncPtr function, struct tm_t & alarm_tm);

0 commit comments

Comments
 (0)