5
5
#include " Watchdog.h"
6
6
#endif
7
7
8
- unsigned long ArduinoCellular::getTime ( ) {
8
+ Time ArduinoCellular::getTimeStruct ( bool localTime ) {
9
9
int year = 1970 ;
10
10
int month = 1 ;
11
11
int day = 1 ;
@@ -14,9 +14,17 @@ unsigned long ArduinoCellular::getTime() {
14
14
int second = 0 ;
15
15
float tz;
16
16
if (syncNTPServer () == 0 ) {
17
- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
17
+ if (localTime) {
18
+ modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
19
+ } else {
20
+ modem.getNetworkUTCTime (&year, &month, &day, &hour, &minute, &second, &tz);
21
+ }
18
22
}
19
- return Time (year, month, day, hour, minute, second).getUNIXTimestamp ();
23
+ return Time (year, month, day, hour, minute, second);
24
+ }
25
+
26
+ unsigned long ArduinoCellular::getTime () {
27
+ return getTimeStruct ().getUNIXTimestamp ();
20
28
}
21
29
22
30
int ArduinoCellular::syncNTPServer (bool forceNTPSync) {
@@ -146,17 +154,8 @@ Time ArduinoCellular::getGPSTime(){
146
154
}
147
155
148
156
Time ArduinoCellular::getCellularTime (){
149
- int year = 1970 ;
150
- int month = 1 ;
151
- int day = 1 ;
152
- int hour = 0 ;
153
- int minute = 0 ;
154
- int second = 0 ;
155
- float tz;
156
- if (syncNTPServer () == 0 ) {
157
- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
158
- }
159
- return Time (year, month, day, hour, minute, second);
157
+ // Get the current time from the network as localtime
158
+ return getTimeStruct (true );
160
159
}
161
160
162
161
0 commit comments