SystemClock.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * SystemClock.h
8  *
9  ****/
10 
15 #pragma once
16 
17 #include "DateTime.h"
18 #include "WString.h"
19 
24 enum TimeZone {
25  eTZ_UTC = 0,
26  eTZ_Local = 1
27 };
35 {
36 public:
41  time_t now(TimeZone timeType = eTZ_Local) const;
42 
51  bool setTime(time_t time, TimeZone timeType);
52 
59 
64  bool setTimeZoneOffset(int seconds);
65 
70  bool setTimeZone(float localTimezoneOffset)
71  {
72  return setTimeZoneOffset(localTimezoneOffset * SECS_PER_HOUR);
73  }
74 
78  int getTimeZoneOffset() const
79  {
80  return timeZoneOffsetSecs;
81  }
82 
86  bool isSet() const
87  {
88  return timeSet;
89  }
90 
91 private:
92  int timeZoneOffsetSecs = 0;
93  bool timeSet = false;
94 };
95 
103 
The String class.
Definition: WString.h:137
Definition: SystemClock.h:35
time_t now(TimeZone timeType=eTZ_Local) const
Get the current date and time.
String getSystemTimeString(TimeZone timeType=eTZ_Local) const
Get current time as a string.
bool setTimeZone(float localTimezoneOffset)
Set the local time zone offset in hours.
Definition: SystemClock.h:70
bool setTimeZoneOffset(int seconds)
Sets the local time zone offset.
int getTimeZoneOffset() const
Get the current time zone offset.
Definition: SystemClock.h:78
bool isSet() const
Determine if setTime() has been called yet.
Definition: SystemClock.h:86
bool setTime(time_t time, TimeZone timeType)
Set the system clock's time.
TimeZone
Time zones.
Definition: SystemClock.h:24
@ eTZ_UTC
Use universal time coordinate (UTC)
Definition: SystemClock.h:25
@ eTZ_Local
Use local time.
Definition: SystemClock.h:26
#define SECS_PER_HOUR
Definition: DateTime.h:26
SystemClockClass SystemClock
Global instance of system clock object.
Time< T > time(Unit unit, T value)
Helper function to create a Time and deduce the type.
Definition: NanoTime.h:423