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) {
@@ -145,17 +153,8 @@ Time ArduinoCellular::getGPSTime(){
145
153
}
146
154
147
155
Time ArduinoCellular::getCellularTime (){
148
- int year = 1970 ;
149
- int month = 1 ;
150
- int day = 1 ;
151
- int hour = 0 ;
152
- int minute = 0 ;
153
- int second = 0 ;
154
- float tz;
155
- if (syncNTPServer () == 0 ) {
156
- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
157
- }
158
- return Time (year, month, day, hour, minute, second);
156
+ // Get the current time from the network as localtime
157
+ return getTimeStruct (true );
159
158
}
160
159
161
160
0 commit comments