├── .gitignore ├── .travis.yml ├── Doxyfile ├── LICENSE ├── README.md ├── build_test.sh ├── docs ├── _date_time_8h.html ├── _date_time_8h.js ├── _date_time_8h_source.html ├── _e_s_p_date_time_8h.html ├── _e_s_p_date_time_8h_source.html ├── _time_elapsed_8h.html ├── _time_elapsed_8h_source.html ├── annotated.html ├── annotated_dup.js ├── bc_s.png ├── bdwn.png ├── class_date_time_class-members.html ├── class_date_time_class.html ├── class_date_time_class.js ├── class_time_elapsed-members.html ├── class_time_elapsed.html ├── class_time_elapsed.js ├── classes.html ├── closed.png ├── dir_68267d1309a1af8e8297ef4c3efbcdba.html ├── dir_68267d1309a1af8e8297ef4c3efbcdba.js ├── doc.png ├── doxygen.css ├── doxygen.png ├── dynsections.js ├── files.html ├── files_dup.js ├── folderclosed.png ├── folderopen.png ├── functions.html ├── functions_func.html ├── functions_vars.html ├── globals.html ├── globals_vars.html ├── index.html ├── jquery.js ├── nav_f.png ├── nav_g.png ├── nav_h.png ├── navtree.css ├── navtree.js ├── navtreedata.js ├── navtreeindex0.js ├── open.png ├── resize.js ├── splitbar.png ├── struct_date_formatter-members.html ├── struct_date_formatter.html ├── struct_date_time_parts-members.html ├── struct_date_time_parts.html ├── struct_date_time_parts.js ├── sync_off.png ├── sync_on.png ├── tab_a.png ├── tab_b.png ├── tab_h.png ├── tab_s.png └── tabs.css ├── examples └── simple │ └── main.cpp ├── include └── README ├── keywords.txt ├── lib └── README ├── library.json ├── library.properties ├── platformio.ini ├── run_test.sh ├── src ├── DateTime.cpp ├── DateTime.h ├── DateTimeTZ.h ├── ESPDateTime.h └── TimeElapsed.h └── test ├── README ├── test_config.h └── test_date_time.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.pdsbak 2 | *.workspace 3 | *.tmp 4 | *.obj 5 | *.hex 6 | *.elf 7 | *.bin 8 | *.out 9 | build 10 | .DS_Store 11 | Objects 12 | Backup Of * 13 | config.h 14 | __pycache__ 15 | *.pyc 16 | .vscode 17 | private.h 18 | config.py 19 | config.ini 20 | config.json 21 | .history 22 | .pio/ 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # * Travis CI Embedded Builds with PlatformIO 2 | # < https://docs.travis-ci.com/user/integration/platformio/ > 3 | # * PlatformIO integration with Travis CI 4 | # < https://docs.platformio.org/page/ci/travis.html > 5 | # * User Guide for `platformio ci` command 6 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 7 | 8 | language: python 9 | python: 10 | - "3.7" 11 | 12 | sudo: false 13 | cache: 14 | directories: 15 | - "~/.platformio" 16 | 17 | env: 18 | - PLATFORMIO_CI_SRC=examples/simple 19 | 20 | install: 21 | - pip install -U platformio 22 | - platformio update 23 | # - export PLATFORMIO_BUILD_FLAGS="-D GLOBAL_MACROS_FOR_ALL_TEST_ENV" 24 | 25 | script: 26 | # - platformio ci --lib="." --board=nodemcuv2 --board=huzzah --board sparkfunBlynk --board=nodemcu-32s --board=esp32cam --board=esp-wrover-kit --board=esp32thing --board=esp32doit-devkit-v1 27 | - platformio ci --lib="." --board=nodemcuv2 --board=nodemcu-32s 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESPDateTime 2 | 3 | This library provides a simple class `DateTimeClass` for sync system timestamp vis ntp and a struct `DateFormatter` to format date time to string, works on **ESP8266** and **ESP32** platform. 4 | 5 | Current Version: **v1.0.4** [![Build Status](https://travis-ci.org/mcxiaoke/ESPDateTime.svg?branch=master)](https://travis-ci.org/mcxiaoke/ESPDateTime) 6 | 7 | # Install 8 | 9 | ## Using PlatformIO 10 | 11 | This libarary is published to [PlatformIO](https://platformio.org/lib/show/6871/ESPDateTime), PlatformIO IDE has built-in PIO Home: Library Manager, you can search `ESPDateTime` in Library Manager and click to install this library. 12 | 13 | Or you can install using platformio cli: 14 | 15 | ```bash 16 | # Using library Id 17 | platformio lib install 6871 18 | # or Using library Name 19 | pio lib install "mcxiaoke/ESPDateTime@^1.0.4" 20 | ``` 21 | 22 | Add dependency to your `platformio.ini` file: 23 | 24 | ```ini 25 | lib_deps = 26 | # Using library Name 27 | mcxiaoke/ESPDateTime @ ^1.0.4 28 | # or You can use the latest git version 29 | https://github.com/mcxiaoke/ESPDateTime.git 30 | ``` 31 | 32 | ## Using Arduino IDE 33 | 34 | I will publish this library to Arduino Library soon. (TODO) 35 | 36 | ## Manual Install 37 | 38 | Clone this repo or download source code at [release](https://github.com/mcxiaoke/ESPDateTime/releases/latest) page, then copy all files in src to your project source directory. 39 | 40 | # Getting Started 41 | 42 | ## Include the Header 43 | 44 | ```cpp 45 | #include 46 | ``` 47 | 48 | ## Config DateTime 49 | 50 | `DateTime` is a global [`DateTimeClass`](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTime.h#L58) object for use in your code. 51 | 52 | You can pick `TimeZone` name from here: [TZ.h](https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h) or here: [DateTimeTZ.h](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTimeTZ.h) 53 | 54 | ```cpp 55 | void setupDateTime() { 56 | // setup this after wifi connected 57 | // you can use custom timeZone,server and timeout 58 | // DateTime.setTimeZone("CST-8"); 59 | // DateTime.setServer("asia.pool.ntp.org"); 60 | // DateTime.begin(15 * 1000); 61 | // from 62 | /** changed from 0.2.x **/ 63 | DateTime.setTimeZone("CST-8"); 64 | // this method config ntp and wait for time sync 65 | // default timeout is 10 seconds 66 | DateTime.begin(/* timeout param */); 67 | if (!DateTime.isTimeValid()) { 68 | Serial.println("Failed to get time from server."); 69 | } 70 | } 71 | ``` 72 | 73 | ## DateTime Functions 74 | 75 | You can use [`DateTime`](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTime.h#L58) to get current time and format time to string, `format` function internal using `strftime` function in ``. 76 | 77 | ```cpp 78 | // alias for getTime() 79 | time_t DateTime.now() 80 | // get current timestap in seconds 81 | time_t DateTime.getTime() 82 | // get current timezone 83 | char* DateTime.getTimeZone() 84 | // get formatted string of time 85 | String DateTime.toString() 86 | // get formatted string of utc time 87 | String DateTime.toUTCString() 88 | // format local time to string, using strftime 89 | // http://www.cplusplus.com/reference/ctime/strftime/ 90 | String DateTime.format(const char* fmt); 91 | // format utc time to string, using strftime 92 | // http://www.cplusplus.com/reference/ctime/strftime/ 93 | String DateTime.formatUTC(const char* fmt); 94 | ``` 95 | 96 | ## Classes 97 | 98 | - [**DateTimeClass**](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTime.h#L58) - Main Class for get current timestamp and format time to string, class of global `DateTime` object. 99 | - [**DateTimeParts**](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTime.h#L20) - Struct for get year/month/day/week part of time struct. 100 | - [**DateFormatter**](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/DateTime.h#L44) - Class for format timestamp to string, include some format constants. 101 | - [**TimeElapsed**](https://github.com/mcxiaoke/ESPDateTime/blob/master/src/TimeElapsed.h) - Class for calculate elapsed time in milliseconds, original code is from [elapsedMillis](https://github.com/pfeerick/elapsedMillis). 102 | 103 | ## Examples 104 | 105 | See [examples](https://github.com/mcxiaoke/ESPDateTime/tree/master/examples/) folder in this project, to run example on your device, WiFi ssid and password must be set in source code. 106 | 107 | ## Documents 108 | 109 | See [API Reference](https://blog.mcxiaoke.com/ESPDateTime/). 110 | 111 | # License 112 | 113 | Copyright 2019-2021 github@mcxiaoke.com 114 | 115 | Licensed under the Apache License, Version 2.0 (the "License"); 116 | you may not use this file except in compliance with the License. 117 | You may obtain a copy of the License at 118 | 119 | http://www.apache.org/licenses/LICENSE-2.0 120 | 121 | Unless required by applicable law or agreed to in writing, software 122 | distributed under the License is distributed on an "AS IS" BASIS, 123 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124 | See the License for the specific language governing permissions and 125 | limitations under the License. 126 | -------------------------------------------------------------------------------- /build_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pio run --environment nodemcu32s && pio run --environment nodemcuv2 3 | -------------------------------------------------------------------------------- /docs/_date_time_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: src/DateTime.h File Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 | Classes | 60 | Variables
61 |
62 |
DateTime.h File Reference
63 |
64 |
65 | 66 |

ESPDateTime header. 67 | More...

68 |
#include <Arduino.h>
69 | #include <time.h>
70 | #include <sys/time.h>
71 |
72 |

Go to the source code of this file.

73 | 74 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |

75 | Classes

struct  DateTimeParts
 DateTime Parts struct, similar to struct tm in <time.h>, containing a calendar date and time broken down into its components, but more readable, include some useful getter methods. More...
 
struct  DateFormatter
 DateTime Formatter constants and static format methods. More...
 
class  DateTimeClass
 DateTime Library Main Class, include time get/set/format methods. More...
 
86 | 88 | 89 | 90 | 91 |

87 | Variables

DateTimeClass DateTime
 Global DateTimeClass object. More...
 
92 |

Detailed Description

93 |

ESPDateTime header.

94 |
Author
Zhang Xiaoke (githu.nosp@m.b@mc.nosp@m.xiaok.nosp@m.e.co.nosp@m.m)
95 |

Variable Documentation

96 | 97 |

◆ DateTime

98 | 99 |
100 |
101 | 102 | 103 | 104 | 105 |
DateTimeClass DateTime
106 |
107 | 108 |

Global DateTimeClass object.

109 | 110 |
111 |
112 |
113 |
114 | 115 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/_date_time_8h.js: -------------------------------------------------------------------------------- 1 | var _date_time_8h = 2 | [ 3 | [ "DateTimeParts", "struct_date_time_parts.html", "struct_date_time_parts" ], 4 | [ "DateFormatter", "struct_date_formatter.html", null ], 5 | [ "DateTimeClass", "class_date_time_class.html", "class_date_time_class" ], 6 | [ "DateTime", "_date_time_8h.html#a4ff522f8d390090d323ee5a3e4e6827a", null ] 7 | ]; -------------------------------------------------------------------------------- /docs/_e_s_p_date_time_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: src/ESPDateTime.h File Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
ESPDateTime.h File Reference
60 |
61 |
62 | 63 |

ESPDateTime header. 64 | More...

65 |
#include <DateTime.h>
66 | #include <TimeElapsed.h>
67 |
68 |

Go to the source code of this file.

69 |

Detailed Description

70 |

ESPDateTime header.

71 |
Author
Zhang Xiaoke (githu.nosp@m.b@mc.nosp@m.xiaok.nosp@m.e.co.nosp@m.m)
72 |
73 |
74 | 75 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /docs/_e_s_p_date_time_8h_source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: src/ESPDateTime.h Source File 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
ESPDateTime.h
60 |
61 |
62 | Go to the documentation of this file.
1 #ifndef ESP_DATE_TIME_LIB_H
63 |
2 #define ESP_DATE_TIME_LIB_H
64 |
3 
65 |
4 /**
66 |
5  * @file ESPDateTime.h
67 |
6  * @author Zhang Xiaoke (github@mcxiaoke.com)
68 |
7  * @brief ESPDateTime header
69 |
8  *
70 |
9  */
71 |
10 
72 |
11 #include <DateTime.h>
73 |
12 #include <TimeElapsed.h>
74 |
13 
75 |
14 #endif
76 |
77 |
78 |
ESPDateTime header.
79 |
ESPDateTime header.
80 | 81 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /docs/_time_elapsed_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: src/TimeElapsed.h File Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 | Classes
60 |
61 |
TimeElapsed.h File Reference
62 |
63 |
64 | 65 |

ESPDateTime header. 66 | More...

67 |
#include <Arduino.h>
68 |
69 |

Go to the source code of this file.

70 | 71 | 73 | 74 | 75 | 76 |

72 | Classes

class  TimeElapsed
 TimeElapsed class. More...
 
77 |

Detailed Description

78 |

ESPDateTime header.

79 |
Author
Zhang Xiaoke (githu.nosp@m.b@mc.nosp@m.xiaok.nosp@m.e.co.nosp@m.m)
80 |
81 |
82 | 83 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Class List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
Class List
60 |
61 |
62 |
Here are the classes, structs, unions and interfaces with brief descriptions:
63 | 64 | 65 | 66 | 67 | 68 |
 CDateFormatterDateTime Formatter constants and static format methods
 CDateTimeClassDateTime Library Main Class, include time get/set/format methods
 CDateTimePartsDateTime Parts struct, similar to struct tm in <time.h>, containing a calendar date and time broken down into its components, but more readable, include some useful getter methods
 CTimeElapsedTimeElapsed class
69 |
70 |
71 |
72 | 73 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /docs/annotated_dup.js: -------------------------------------------------------------------------------- 1 | var annotated_dup = 2 | [ 3 | [ "DateFormatter", "struct_date_formatter.html", null ], 4 | [ "DateTimeClass", "class_date_time_class.html", "class_date_time_class" ], 5 | [ "DateTimeParts", "struct_date_time_parts.html", "struct_date_time_parts" ], 6 | [ "TimeElapsed", "class_time_elapsed.html", "class_time_elapsed" ] 7 | ]; -------------------------------------------------------------------------------- /docs/bc_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/bc_s.png -------------------------------------------------------------------------------- /docs/bdwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/bdwn.png -------------------------------------------------------------------------------- /docs/class_date_time_class-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Member List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
DateTimeClass Member List
60 |
61 |
62 | 63 |

This is the complete list of members for DateTimeClass, including all inherited members.

64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |
begin(const unsigned int timeOutMs=DEFAULT_TIMEOUT)DateTimeClassinline
DateTimeClass(const time_t _timeSecs=TIME_ZERO, const int _timeZone=DEFAULT_TIMEZONE, const char *_ntpServer=NTP_SERVER_1)DateTimeClass
DEFAULT_TIMEOUTDateTimeClassstatic
DEFAULT_TIMEZONEDateTimeClassstatic
forceUpdate(const unsigned int timeOutMs=DEFAULT_TIMEOUT)DateTimeClass
format(const char *fmt)DateTimeClass
formatUTC(const char *fmt)DateTimeClass
getBootTime() constDateTimeClassinline
getParts()DateTimeClassinline
getServer()DateTimeClassinline
getTime() constDateTimeClassinline
getTimeZone() constDateTimeClassinline
isTimeValid() constDateTimeClassinline
now() constDateTimeClassinline
NTP_SERVER_1DateTimeClassstatic
NTP_SERVER_2DateTimeClassstatic
NTP_SERVER_3DateTimeClassstatic
operator!= (defined in DateTimeClass)DateTimeClassfriend
operator+(const time_t timeDeltaSecs) (defined in DateTimeClass)DateTimeClassinline
operator+=(const time_t timeDeltaSecs) (defined in DateTimeClass)DateTimeClassinline
operator-(const time_t timeDeltaSecs) (defined in DateTimeClass)DateTimeClassinline
operator-=(const time_t timeDeltaSecs) (defined in DateTimeClass)DateTimeClassinline
operator< (defined in DateTimeClass)DateTimeClassfriend
operator<= (defined in DateTimeClass)DateTimeClassfriend
operator== (defined in DateTimeClass)DateTimeClassfriend
operator> (defined in DateTimeClass)DateTimeClassfriend
operator>= (defined in DateTimeClass)DateTimeClassfriend
osTime() constDateTimeClassinline
SECS_START_POINTDateTimeClassstatic
setServer(const char *_server)DateTimeClass
setTime(const time_t timeSecs, bool forceSet=false)DateTimeClass
setTimeZone(int _timeZone)DateTimeClass
TIME_ZERODateTimeClassstatic
TIMEZONE_CHINADateTimeClassstatic
TIMEZONE_UTCDateTimeClassstatic
toISOString()DateTimeClassinline
toString()DateTimeClassinline
toUTCString()DateTimeClassinline
utcTime() constDateTimeClassinline
105 |
106 | 107 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/class_date_time_class.js: -------------------------------------------------------------------------------- 1 | var class_date_time_class = 2 | [ 3 | [ "DateTimeClass", "class_date_time_class.html#a931abc1c1298ac3d7ac032d64649dbbe", null ], 4 | [ "begin", "class_date_time_class.html#aae495ea9aec8bb77e1645301b0e888f1", null ], 5 | [ "forceUpdate", "class_date_time_class.html#a54c7540f9e780371a9aa6b917ae45272", null ], 6 | [ "format", "class_date_time_class.html#a690630648afb04e79f589fcdaa069549", null ], 7 | [ "formatUTC", "class_date_time_class.html#a6cde1f6d32af4c05139954223ef910b5", null ], 8 | [ "getBootTime", "class_date_time_class.html#aa2ad7584541f02446196f49763099085", null ], 9 | [ "getParts", "class_date_time_class.html#a07ef7e429f2ec28bc5225e43195e7cb3", null ], 10 | [ "getServer", "class_date_time_class.html#a26fd7301f3915a987822a060b3801fa5", null ], 11 | [ "getTime", "class_date_time_class.html#a0523e465fac5852931ec702c7f1301d1", null ], 12 | [ "getTimeZone", "class_date_time_class.html#a773518f5984983ee3b14b0de9f6ea906", null ], 13 | [ "isTimeValid", "class_date_time_class.html#a82beb06c8f8a547933dfa194f15491a5", null ], 14 | [ "now", "class_date_time_class.html#a917fe6580ac0845bde086daba3da632c", null ], 15 | [ "operator+", "class_date_time_class.html#a3f31d65dc39a994de881da7614fc0904", null ], 16 | [ "operator+=", "class_date_time_class.html#a833e83e7ef15015310c946a04696dab6", null ], 17 | [ "operator-", "class_date_time_class.html#a70fab4ca084a1b7e1c3a85b5b2d5add4", null ], 18 | [ "operator-=", "class_date_time_class.html#ad998bce7a2d4619e896ba856e2b916af", null ], 19 | [ "osTime", "class_date_time_class.html#a22f3bc3de34665a9c6ee1ed6d0daf04a", null ], 20 | [ "setServer", "class_date_time_class.html#a5bb5466cb538229d419b296fbcca6a91", null ], 21 | [ "setTime", "class_date_time_class.html#aa724fb35f3582b1a6ab4c30e12840428", null ], 22 | [ "setTimeZone", "class_date_time_class.html#ab031ddc33522fa7a2a2ff70361f8b501", null ], 23 | [ "toISOString", "class_date_time_class.html#a8d03bec0dd6c87a5015b399e81321457", null ], 24 | [ "toString", "class_date_time_class.html#a8fab4bbfdb1bb7a9ce23e8f2aa646668", null ], 25 | [ "toUTCString", "class_date_time_class.html#acfc607647c589bfb130c9239dfc2ac85", null ], 26 | [ "utcTime", "class_date_time_class.html#a4430dc17a5058cf95c263a544f55c11c", null ], 27 | [ "operator!=", "class_date_time_class.html#aaf8f1c65ec5a0551069493202a6b3517", null ], 28 | [ "operator<", "class_date_time_class.html#ae184a16b6768e15175dee98f18313faa", null ], 29 | [ "operator<=", "class_date_time_class.html#ab9c6a7854b38720063892f50cc7abae4", null ], 30 | [ "operator==", "class_date_time_class.html#a789a9866dc8a41582361f836a31ca5a8", null ], 31 | [ "operator>", "class_date_time_class.html#ad073516be78abbeee67bf9e312c4c7ef", null ], 32 | [ "operator>=", "class_date_time_class.html#ae361a402eb1b1fd620e0ed986f0c202c", null ] 33 | ]; -------------------------------------------------------------------------------- /docs/class_time_elapsed-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Member List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
TimeElapsed Member List
60 |
61 |
62 | 63 |

This is the complete list of members for TimeElapsed, including all inherited members.

64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
operator unsigned long() const (defined in TimeElapsed)TimeElapsedinline
operator+(int val) const (defined in TimeElapsed)TimeElapsedinline
operator+(unsigned int val) const (defined in TimeElapsed)TimeElapsedinline
operator+(long val) const (defined in TimeElapsed)TimeElapsedinline
operator+(unsigned long val) const (defined in TimeElapsed)TimeElapsedinline
operator+=(unsigned long val) (defined in TimeElapsed)TimeElapsedinline
operator-(int val) const (defined in TimeElapsed)TimeElapsedinline
operator-(unsigned int val) const (defined in TimeElapsed)TimeElapsedinline
operator-(long val) const (defined in TimeElapsed)TimeElapsedinline
operator-(unsigned long val) const (defined in TimeElapsed)TimeElapsedinline
operator-=(unsigned long val) (defined in TimeElapsed)TimeElapsedinline
operator=(const TimeElapsed &rhs) (defined in TimeElapsed)TimeElapsedinline
operator=(unsigned long val) (defined in TimeElapsed)TimeElapsedinline
TimeElapsed() (defined in TimeElapsed)TimeElapsedinline
TimeElapsed(unsigned long val) (defined in TimeElapsed)TimeElapsedinline
TimeElapsed(const TimeElapsed &rhs) (defined in TimeElapsed)TimeElapsedinline
82 |
83 | 84 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/class_time_elapsed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: TimeElapsed Class Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 | 61 |
62 |
TimeElapsed Class Reference
63 |
64 |
65 | 66 |

TimeElapsed class. 67 | More...

68 | 69 |

#include <TimeElapsed.h>

70 | 71 | 73 | 75 | 76 | 78 | 79 | 81 | 82 | 84 | 85 | 87 | 88 | 90 | 91 | 93 | 94 | 96 | 97 | 99 | 100 | 102 | 103 | 105 | 106 | 108 | 109 | 111 | 112 | 114 | 115 | 117 | 118 |

72 | Public Member Functions

74 |  TimeElapsed (unsigned long val)
 
77 |  TimeElapsed (const TimeElapsed &rhs)
 
80 |  operator unsigned long () const
 
83 | TimeElapsedoperator= (const TimeElapsed &rhs)
 
86 | TimeElapsedoperator= (unsigned long val)
 
89 | TimeElapsedoperator-= (unsigned long val)
 
92 | TimeElapsedoperator+= (unsigned long val)
 
95 | TimeElapsed operator- (int val) const
 
98 | TimeElapsed operator- (unsigned int val) const
 
101 | TimeElapsed operator- (long val) const
 
104 | TimeElapsed operator- (unsigned long val) const
 
107 | TimeElapsed operator+ (int val) const
 
110 | TimeElapsed operator+ (unsigned int val) const
 
113 | TimeElapsed operator+ (long val) const
 
116 | TimeElapsed operator+ (unsigned long val) const
 
119 |

Detailed Description

120 |

TimeElapsed class.

121 |

The documentation for this class was generated from the following file: 124 |
125 |
126 | 127 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/class_time_elapsed.js: -------------------------------------------------------------------------------- 1 | var class_time_elapsed = 2 | [ 3 | [ "TimeElapsed", "class_time_elapsed.html#aede3e3ae720a8bfa7793615fca0da12e", null ], 4 | [ "TimeElapsed", "class_time_elapsed.html#a453dd9547a63d2c7db0968d293fffc2b", null ], 5 | [ "TimeElapsed", "class_time_elapsed.html#aee5fd06cee169a6c5e7b2f257ff1aa2e", null ], 6 | [ "operator unsigned long", "class_time_elapsed.html#a9463bdeb808800a6093b8955da5b4761", null ], 7 | [ "operator+", "class_time_elapsed.html#aa10444be12475fe340334ea0da295dd7", null ], 8 | [ "operator+", "class_time_elapsed.html#a3d7f579bc43edc779c2c6d705fffaf37", null ], 9 | [ "operator+", "class_time_elapsed.html#a3bc2e26c99ba1a9727bb7bf4535f41d7", null ], 10 | [ "operator+", "class_time_elapsed.html#a81f16042c1ae8f7054316f6f0af9ce49", null ], 11 | [ "operator+=", "class_time_elapsed.html#aada34f573909787c6d68b24fc4221a96", null ], 12 | [ "operator-", "class_time_elapsed.html#adfba4ed1dbcbc486d753d805974a98d4", null ], 13 | [ "operator-", "class_time_elapsed.html#a9613e79fb6804bd47ed9f88256f98670", null ], 14 | [ "operator-", "class_time_elapsed.html#afefc80cd94ba1f46662aa4833d1d2f86", null ], 15 | [ "operator-", "class_time_elapsed.html#ac1c010127631d9d77d1d5300ee98fbbd", null ], 16 | [ "operator-=", "class_time_elapsed.html#a35df3fc10886cd9880580315130c4510", null ], 17 | [ "operator=", "class_time_elapsed.html#a69e5fdad5dd866aa7377b51010de25d7", null ], 18 | [ "operator=", "class_time_elapsed.html#a7b7c395da34defffd493d166f627480c", null ] 19 | ]; -------------------------------------------------------------------------------- /docs/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Class Index 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
Class Index
60 |
61 |
62 |
d | t
63 | 64 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
  d  
65 |
DateTimeClass   
  t  
68 |
DateTimeParts   
DateFormatter   TimeElapsed   
77 |
d | t
78 |
79 |
80 | 81 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /docs/closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/closed.png -------------------------------------------------------------------------------- /docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: src Directory Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
src Directory Reference
60 |
61 |
62 | 63 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |

64 | Files

file  DateTime.h [code]
 ESPDateTime header.
 
file  ESPDateTime.h [code]
 ESPDateTime header.
 
file  TimeElapsed.h [code]
 ESPDateTime header.
 
75 |
76 |
77 | 78 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js: -------------------------------------------------------------------------------- 1 | var dir_68267d1309a1af8e8297ef4c3efbcdba = 2 | [ 3 | [ "DateTime.h", "_date_time_8h.html", "_date_time_8h" ], 4 | [ "ESPDateTime.h", "_e_s_p_date_time_8h.html", null ], 5 | [ "TimeElapsed.h", "_time_elapsed_8h.html", [ 6 | [ "TimeElapsed", "class_time_elapsed.html", "class_time_elapsed" ] 7 | ] ] 8 | ]; -------------------------------------------------------------------------------- /docs/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/doc.png -------------------------------------------------------------------------------- /docs/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/doxygen.png -------------------------------------------------------------------------------- /docs/dynsections.js: -------------------------------------------------------------------------------- 1 | /* 2 | @licstart The following is the entire license notice for the 3 | JavaScript code in this file. 4 | 5 | Copyright (C) 1997-2017 by Dimitri van Heesch 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | @licend The above is the entire license notice 22 | for the JavaScript code in this file 23 | */ 24 | function toggleVisibility(linkObj) 25 | { 26 | var base = $(linkObj).attr('id'); 27 | var summary = $('#'+base+'-summary'); 28 | var content = $('#'+base+'-content'); 29 | var trigger = $('#'+base+'-trigger'); 30 | var src=$(trigger).attr('src'); 31 | if (content.is(':visible')===true) { 32 | content.hide(); 33 | summary.show(); 34 | $(linkObj).addClass('closed').removeClass('opened'); 35 | $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png'); 36 | } else { 37 | content.show(); 38 | summary.hide(); 39 | $(linkObj).removeClass('closed').addClass('opened'); 40 | $(trigger).attr('src',src.substring(0,src.length-10)+'open.png'); 41 | } 42 | return false; 43 | } 44 | 45 | function updateStripes() 46 | { 47 | $('table.directory tr'). 48 | removeClass('even').filter(':visible:even').addClass('even'); 49 | } 50 | 51 | function toggleLevel(level) 52 | { 53 | $('table.directory tr').each(function() { 54 | var l = this.id.split('_').length-1; 55 | var i = $('#img'+this.id.substring(3)); 56 | var a = $('#arr'+this.id.substring(3)); 57 | if (l 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: File List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
File List
60 |
61 |
62 |
Here is a list of all documented files with brief descriptions:
63 |
[detail level 12]
64 | 65 | 66 | 67 | 68 |
  src
 DateTime.hESPDateTime header
 ESPDateTime.hESPDateTime header
 TimeElapsed.hESPDateTime header
69 |
70 |
71 |
72 | 73 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /docs/files_dup.js: -------------------------------------------------------------------------------- 1 | var files_dup = 2 | [ 3 | [ "src", "dir_68267d1309a1af8e8297ef4c3efbcdba.html", "dir_68267d1309a1af8e8297ef4c3efbcdba" ] 4 | ]; -------------------------------------------------------------------------------- /docs/folderclosed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/folderclosed.png -------------------------------------------------------------------------------- /docs/folderopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/folderopen.png -------------------------------------------------------------------------------- /docs/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Class Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
Here is a list of all documented class members with links to the class documentation for each member:
59 | 60 |

- _ -

71 | 72 | 73 |

- b -

78 | 79 | 80 |

- c -

85 | 86 | 87 |

- d -

101 | 102 | 103 |

- f -

119 | 120 | 121 |

- g -

164 | 165 | 166 |

- h -

171 | 172 | 173 |

- i -

181 | 182 | 183 |

- n -

197 | 198 | 199 |

- o -

204 | 205 | 206 |

- s -

223 | 224 | 225 |

- t -

249 | 250 | 251 |

- u -

256 |
257 |
258 | 259 | 266 | 267 | 268 | -------------------------------------------------------------------------------- /docs/functions_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Class Members - Functions 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |   59 | 60 |

- b -

65 | 66 | 67 |

- d -

72 | 73 | 74 |

- f -

90 | 91 | 92 |

- g -

135 | 136 | 137 |

- i -

142 | 143 | 144 |

- n -

149 | 150 | 151 |

- o -

156 | 157 | 158 |

- s -

169 | 170 | 171 |

- t -

183 | 184 | 185 |

- u -

190 |
191 |
192 | 193 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /docs/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Class Members - Variables 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |   114 |
115 |
116 | 117 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /docs/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: File Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
Here is a list of all documented file members with links to the documentation:
63 |
64 |
65 | 66 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /docs/globals_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: File Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |   63 |
64 |
65 | 66 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /docs/nav_f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/nav_f.png -------------------------------------------------------------------------------- /docs/nav_g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/nav_g.png -------------------------------------------------------------------------------- /docs/nav_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/nav_h.png -------------------------------------------------------------------------------- /docs/navtree.css: -------------------------------------------------------------------------------- 1 | #nav-tree .children_ul { 2 | margin:0; 3 | padding:4px; 4 | } 5 | 6 | #nav-tree ul { 7 | list-style:none outside none; 8 | margin:0px; 9 | padding:0px; 10 | } 11 | 12 | #nav-tree li { 13 | white-space:nowrap; 14 | margin:0px; 15 | padding:0px; 16 | } 17 | 18 | #nav-tree .plus { 19 | margin:0px; 20 | } 21 | 22 | #nav-tree .selected { 23 | background-image: url('tab_a.png'); 24 | background-repeat:repeat-x; 25 | color: #fff; 26 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 27 | } 28 | 29 | #nav-tree img { 30 | margin:0px; 31 | padding:0px; 32 | border:0px; 33 | vertical-align: middle; 34 | } 35 | 36 | #nav-tree a { 37 | text-decoration:none; 38 | padding:0px; 39 | margin:0px; 40 | outline:none; 41 | } 42 | 43 | #nav-tree .label { 44 | margin:0px; 45 | padding:0px; 46 | font: 12px 'Lucida Grande',Geneva,Helvetica,Arial,sans-serif; 47 | } 48 | 49 | #nav-tree .label a { 50 | padding:2px; 51 | } 52 | 53 | #nav-tree .selected a { 54 | text-decoration:none; 55 | color:#fff; 56 | } 57 | 58 | #nav-tree .children_ul { 59 | margin:0px; 60 | padding:0px; 61 | } 62 | 63 | #nav-tree .item { 64 | margin:0px; 65 | padding:0px; 66 | } 67 | 68 | #nav-tree { 69 | padding: 0px 0px; 70 | background-color: #FAFAFF; 71 | font-size:14px; 72 | overflow:auto; 73 | } 74 | 75 | #doc-content { 76 | overflow:auto; 77 | display:block; 78 | padding:0px; 79 | margin:0px; 80 | -webkit-overflow-scrolling : touch; /* iOS 5+ */ 81 | } 82 | 83 | #side-nav { 84 | padding:0 6px 0 0; 85 | margin: 0px; 86 | display:block; 87 | position: absolute; 88 | left: 0px; 89 | width: 250px; 90 | } 91 | 92 | .ui-resizable .ui-resizable-handle { 93 | display:block; 94 | } 95 | 96 | .ui-resizable-e { 97 | background-image:url("splitbar.png"); 98 | background-size:100%; 99 | background-repeat:repeat-y; 100 | background-attachment: scroll; 101 | cursor:ew-resize; 102 | height:100%; 103 | right:0; 104 | top:0; 105 | width:6px; 106 | } 107 | 108 | .ui-resizable-handle { 109 | display:none; 110 | font-size:0.1px; 111 | position:absolute; 112 | z-index:1; 113 | } 114 | 115 | #nav-tree-contents { 116 | margin: 6px 0px 0px 0px; 117 | } 118 | 119 | #nav-tree { 120 | background-image:url('nav_h.png'); 121 | background-repeat:repeat-x; 122 | background-color: #F9FAFC; 123 | -webkit-overflow-scrolling : touch; /* iOS 5+ */ 124 | } 125 | 126 | #nav-sync { 127 | position:absolute; 128 | top:5px; 129 | right:24px; 130 | z-index:0; 131 | } 132 | 133 | #nav-sync img { 134 | opacity:0.3; 135 | } 136 | 137 | #nav-sync img:hover { 138 | opacity:0.9; 139 | } 140 | 141 | @media print 142 | { 143 | #nav-tree { display: none; } 144 | div.ui-resizable-handle { display: none; position: relative; } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /docs/navtreedata.js: -------------------------------------------------------------------------------- 1 | /* 2 | @licstart The following is the entire license notice for the 3 | JavaScript code in this file. 4 | 5 | Copyright (C) 1997-2019 by Dimitri van Heesch 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of version 2 of the GNU General Public License as published by 9 | the Free Software Foundation 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | 20 | @licend The above is the entire license notice 21 | for the JavaScript code in this file 22 | */ 23 | var NAVTREE = 24 | [ 25 | [ "ESP DateTime", "index.html", [ 26 | [ "ESPDateTime", "index.html", [ 27 | [ "Install", "index.html#autotoc_md1", [ 28 | [ "Using PlatformIO", "index.html#autotoc_md2", null ], 29 | [ "Using Arduino IDE", "index.html#autotoc_md3", null ], 30 | [ "Manual Install", "index.html#autotoc_md4", null ] 31 | ] ], 32 | [ "Getting Started", "index.html#autotoc_md5", [ 33 | [ "Include the Header", "index.html#autotoc_md6", null ], 34 | [ "Config DateTime", "index.html#autotoc_md7", null ], 35 | [ "DateTime Functions", "index.html#autotoc_md8", null ], 36 | [ "Classes", "index.html#autotoc_md9", null ], 37 | [ "Examples", "index.html#autotoc_md10", null ], 38 | [ "Documents", "index.html#autotoc_md11", null ] 39 | ] ], 40 | [ "License", "index.html#autotoc_md12", null ] 41 | ] ], 42 | [ "Classes", "annotated.html", [ 43 | [ "Class List", "annotated.html", "annotated_dup" ], 44 | [ "Class Members", "functions.html", [ 45 | [ "All", "functions.html", null ], 46 | [ "Functions", "functions_func.html", null ], 47 | [ "Variables", "functions_vars.html", null ] 48 | ] ] 49 | ] ], 50 | [ "Files", "files.html", [ 51 | [ "File List", "files.html", "files_dup" ], 52 | [ "File Members", "globals.html", [ 53 | [ "All", "globals.html", null ], 54 | [ "Variables", "globals_vars.html", null ] 55 | ] ] 56 | ] ] 57 | ] ] 58 | ]; 59 | 60 | var NAVTREEINDEX = 61 | [ 62 | "_date_time_8h.html" 63 | ]; 64 | 65 | var SYNCONMSG = 'click to disable panel synchronisation'; 66 | var SYNCOFFMSG = 'click to enable panel synchronisation'; -------------------------------------------------------------------------------- /docs/navtreeindex0.js: -------------------------------------------------------------------------------- 1 | var NAVTREEINDEX0 = 2 | { 3 | "_date_time_8h.html":[2,0,0,0], 4 | "_date_time_8h.html#a4ff522f8d390090d323ee5a3e4e6827a":[2,0,0,0,3], 5 | "_date_time_8h_source.html":[2,0,0,0], 6 | "_e_s_p_date_time_8h.html":[2,0,0,1], 7 | "_e_s_p_date_time_8h_source.html":[2,0,0,1], 8 | "_time_elapsed_8h.html":[2,0,0,2], 9 | "_time_elapsed_8h_source.html":[2,0,0,2], 10 | "annotated.html":[1,0], 11 | "class_date_time_class.html":[1,0,1], 12 | "class_date_time_class.html#a0523e465fac5852931ec702c7f1301d1":[1,0,1,8], 13 | "class_date_time_class.html#a07ef7e429f2ec28bc5225e43195e7cb3":[1,0,1,6], 14 | "class_date_time_class.html#a22f3bc3de34665a9c6ee1ed6d0daf04a":[1,0,1,16], 15 | "class_date_time_class.html#a26fd7301f3915a987822a060b3801fa5":[1,0,1,7], 16 | "class_date_time_class.html#a3f31d65dc39a994de881da7614fc0904":[1,0,1,12], 17 | "class_date_time_class.html#a4430dc17a5058cf95c263a544f55c11c":[1,0,1,23], 18 | "class_date_time_class.html#a54c7540f9e780371a9aa6b917ae45272":[1,0,1,2], 19 | "class_date_time_class.html#a5bb5466cb538229d419b296fbcca6a91":[1,0,1,17], 20 | "class_date_time_class.html#a690630648afb04e79f589fcdaa069549":[1,0,1,3], 21 | "class_date_time_class.html#a6cde1f6d32af4c05139954223ef910b5":[1,0,1,4], 22 | "class_date_time_class.html#a70fab4ca084a1b7e1c3a85b5b2d5add4":[1,0,1,14], 23 | "class_date_time_class.html#a773518f5984983ee3b14b0de9f6ea906":[1,0,1,9], 24 | "class_date_time_class.html#a789a9866dc8a41582361f836a31ca5a8":[1,0,1,27], 25 | "class_date_time_class.html#a82beb06c8f8a547933dfa194f15491a5":[1,0,1,10], 26 | "class_date_time_class.html#a833e83e7ef15015310c946a04696dab6":[1,0,1,13], 27 | "class_date_time_class.html#a8d03bec0dd6c87a5015b399e81321457":[1,0,1,20], 28 | "class_date_time_class.html#a8fab4bbfdb1bb7a9ce23e8f2aa646668":[1,0,1,21], 29 | "class_date_time_class.html#a917fe6580ac0845bde086daba3da632c":[1,0,1,11], 30 | "class_date_time_class.html#a931abc1c1298ac3d7ac032d64649dbbe":[1,0,1,0], 31 | "class_date_time_class.html#aa2ad7584541f02446196f49763099085":[1,0,1,5], 32 | "class_date_time_class.html#aa724fb35f3582b1a6ab4c30e12840428":[1,0,1,18], 33 | "class_date_time_class.html#aae495ea9aec8bb77e1645301b0e888f1":[1,0,1,1], 34 | "class_date_time_class.html#aaf8f1c65ec5a0551069493202a6b3517":[1,0,1,24], 35 | "class_date_time_class.html#ab031ddc33522fa7a2a2ff70361f8b501":[1,0,1,19], 36 | "class_date_time_class.html#ab9c6a7854b38720063892f50cc7abae4":[1,0,1,26], 37 | "class_date_time_class.html#acfc607647c589bfb130c9239dfc2ac85":[1,0,1,22], 38 | "class_date_time_class.html#ad073516be78abbeee67bf9e312c4c7ef":[1,0,1,28], 39 | "class_date_time_class.html#ad998bce7a2d4619e896ba856e2b916af":[1,0,1,15], 40 | "class_date_time_class.html#ae184a16b6768e15175dee98f18313faa":[1,0,1,25], 41 | "class_date_time_class.html#ae361a402eb1b1fd620e0ed986f0c202c":[1,0,1,29], 42 | "class_time_elapsed.html":[1,0,3], 43 | "class_time_elapsed.html#a35df3fc10886cd9880580315130c4510":[1,0,3,13], 44 | "class_time_elapsed.html#a3bc2e26c99ba1a9727bb7bf4535f41d7":[1,0,3,6], 45 | "class_time_elapsed.html#a3d7f579bc43edc779c2c6d705fffaf37":[1,0,3,5], 46 | "class_time_elapsed.html#a453dd9547a63d2c7db0968d293fffc2b":[1,0,3,1], 47 | "class_time_elapsed.html#a69e5fdad5dd866aa7377b51010de25d7":[1,0,3,14], 48 | "class_time_elapsed.html#a7b7c395da34defffd493d166f627480c":[1,0,3,15], 49 | "class_time_elapsed.html#a81f16042c1ae8f7054316f6f0af9ce49":[1,0,3,7], 50 | "class_time_elapsed.html#a9463bdeb808800a6093b8955da5b4761":[1,0,3,3], 51 | "class_time_elapsed.html#a9613e79fb6804bd47ed9f88256f98670":[1,0,3,10], 52 | "class_time_elapsed.html#aa10444be12475fe340334ea0da295dd7":[1,0,3,4], 53 | "class_time_elapsed.html#aada34f573909787c6d68b24fc4221a96":[1,0,3,8], 54 | "class_time_elapsed.html#ac1c010127631d9d77d1d5300ee98fbbd":[1,0,3,12], 55 | "class_time_elapsed.html#adfba4ed1dbcbc486d753d805974a98d4":[1,0,3,9], 56 | "class_time_elapsed.html#aede3e3ae720a8bfa7793615fca0da12e":[1,0,3,0], 57 | "class_time_elapsed.html#aee5fd06cee169a6c5e7b2f257ff1aa2e":[1,0,3,2], 58 | "class_time_elapsed.html#afefc80cd94ba1f46662aa4833d1d2f86":[1,0,3,11], 59 | "dir_68267d1309a1af8e8297ef4c3efbcdba.html":[2,0,0], 60 | "files.html":[2,0], 61 | "functions.html":[1,1,0], 62 | "functions_func.html":[1,1,1], 63 | "functions_vars.html":[1,1,2], 64 | "globals.html":[2,1,0], 65 | "globals_vars.html":[2,1,1], 66 | "index.html":[0], 67 | "index.html":[], 68 | "index.html#autotoc_md1":[0,0], 69 | "index.html#autotoc_md10":[0,1,4], 70 | "index.html#autotoc_md11":[0,1,5], 71 | "index.html#autotoc_md12":[0,2], 72 | "index.html#autotoc_md2":[0,0,0], 73 | "index.html#autotoc_md3":[0,0,1], 74 | "index.html#autotoc_md4":[0,0,2], 75 | "index.html#autotoc_md5":[0,1], 76 | "index.html#autotoc_md6":[0,1,0], 77 | "index.html#autotoc_md7":[0,1,1], 78 | "index.html#autotoc_md8":[0,1,2], 79 | "index.html#autotoc_md9":[0,1,3], 80 | "pages.html":[], 81 | "struct_date_formatter.html":[1,0,0], 82 | "struct_date_time_parts.html":[1,0,2], 83 | "struct_date_time_parts.html#a09762117726998bdf734cc0013d5fdbe":[1,0,2,8], 84 | "struct_date_time_parts.html#a12b3033250329e4bd22945e7b0f53c28":[1,0,2,11], 85 | "struct_date_time_parts.html#a20a9a75d3f7ed8ffdfdca59bfe25e2c8":[1,0,2,13], 86 | "struct_date_time_parts.html#a23c0c57d37c178359fd76be0996d20ad":[1,0,2,4], 87 | "struct_date_time_parts.html#a460df90cbdb925087b59ffaf130dafae":[1,0,2,0], 88 | "struct_date_time_parts.html#a66f5fc739866f1c09cc5c02c14cb771d":[1,0,2,1], 89 | "struct_date_time_parts.html#a6b321b7845a89a3c6ad52176daec8d95":[1,0,2,6], 90 | "struct_date_time_parts.html#a6d83a22432d99601ef113b020d4976fe":[1,0,2,12], 91 | "struct_date_time_parts.html#a8eae5ec1c3f06fb641dd059e9a4503fa":[1,0,2,7], 92 | "struct_date_time_parts.html#abae74225a60aea4499009170437cba62":[1,0,2,2], 93 | "struct_date_time_parts.html#ac22ee88a56d70c5660a4e14a2b1ede80":[1,0,2,10], 94 | "struct_date_time_parts.html#acc77b2af9393b4ae0f84718b6a0e7541":[1,0,2,14], 95 | "struct_date_time_parts.html#ad24590f3bcd2c442d86134222a963228":[1,0,2,3], 96 | "struct_date_time_parts.html#adcc5141646b82270de6718cc83e8557c":[1,0,2,5], 97 | "struct_date_time_parts.html#ae431a2065019aee926b05394dd972332":[1,0,2,9] 98 | }; 99 | -------------------------------------------------------------------------------- /docs/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/open.png -------------------------------------------------------------------------------- /docs/resize.js: -------------------------------------------------------------------------------- 1 | /* 2 | @licstart The following is the entire license notice for the 3 | JavaScript code in this file. 4 | 5 | Copyright (C) 1997-2017 by Dimitri van Heesch 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | @licend The above is the entire license notice 22 | for the JavaScript code in this file 23 | */ 24 | function initResizable() 25 | { 26 | var cookie_namespace = 'doxygen'; 27 | var sidenav,navtree,content,header,collapsed,collapsedWidth=0,barWidth=6,desktop_vp=768,titleHeight; 28 | 29 | function readCookie(cookie) 30 | { 31 | var myCookie = cookie_namespace+"_"+cookie+"="; 32 | if (document.cookie) { 33 | var index = document.cookie.indexOf(myCookie); 34 | if (index != -1) { 35 | var valStart = index + myCookie.length; 36 | var valEnd = document.cookie.indexOf(";", valStart); 37 | if (valEnd == -1) { 38 | valEnd = document.cookie.length; 39 | } 40 | var val = document.cookie.substring(valStart, valEnd); 41 | return val; 42 | } 43 | } 44 | return 0; 45 | } 46 | 47 | function writeCookie(cookie, val, expiration) 48 | { 49 | if (val==undefined) return; 50 | if (expiration == null) { 51 | var date = new Date(); 52 | date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week 53 | expiration = date.toGMTString(); 54 | } 55 | document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/"; 56 | } 57 | 58 | function resizeWidth() 59 | { 60 | var windowWidth = $(window).width() + "px"; 61 | var sidenavWidth = $(sidenav).outerWidth(); 62 | content.css({marginLeft:parseInt(sidenavWidth)+"px"}); 63 | writeCookie('width',sidenavWidth-barWidth, null); 64 | } 65 | 66 | function restoreWidth(navWidth) 67 | { 68 | var windowWidth = $(window).width() + "px"; 69 | content.css({marginLeft:parseInt(navWidth)+barWidth+"px"}); 70 | sidenav.css({width:navWidth + "px"}); 71 | } 72 | 73 | function resizeHeight() 74 | { 75 | var headerHeight = header.outerHeight(); 76 | var footerHeight = footer.outerHeight(); 77 | var windowHeight = $(window).height() - headerHeight - footerHeight; 78 | content.css({height:windowHeight + "px"}); 79 | navtree.css({height:windowHeight + "px"}); 80 | sidenav.css({height:windowHeight + "px"}); 81 | var width=$(window).width(); 82 | if (width!=collapsedWidth) { 83 | if (width=desktop_vp) { 84 | if (!collapsed) { 85 | collapseExpand(); 86 | } 87 | } else if (width>desktop_vp && collapsedWidth0) { 99 | restoreWidth(0); 100 | collapsed=true; 101 | } 102 | else { 103 | var width = readCookie('width'); 104 | if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); } 105 | collapsed=false; 106 | } 107 | } 108 | 109 | header = $("#top"); 110 | sidenav = $("#side-nav"); 111 | content = $("#doc-content"); 112 | navtree = $("#nav-tree"); 113 | footer = $("#nav-path"); 114 | $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } }); 115 | $(sidenav).resizable({ minWidth: 0 }); 116 | $(window).resize(function() { resizeHeight(); }); 117 | var device = navigator.userAgent.toLowerCase(); 118 | var touch_device = device.match(/(iphone|ipod|ipad|android)/); 119 | if (touch_device) { /* wider split bar for touch only devices */ 120 | $(sidenav).css({ paddingRight:'20px' }); 121 | $('.ui-resizable-e').css({ width:'20px' }); 122 | $('#nav-sync').css({ right:'34px' }); 123 | barWidth=20; 124 | } 125 | var width = readCookie('width'); 126 | if (width) { restoreWidth(width); } else { resizeWidth(); } 127 | resizeHeight(); 128 | var url = location.href; 129 | var i=url.indexOf("#"); 130 | if (i>=0) window.location.hash=url.substr(i); 131 | var _preventDefault = function(evt) { evt.preventDefault(); }; 132 | $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault); 133 | $(".ui-resizable-handle").dblclick(collapseExpand); 134 | $(window).on('load',resizeHeight); 135 | } 136 | /* @license-end */ 137 | -------------------------------------------------------------------------------- /docs/splitbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/splitbar.png -------------------------------------------------------------------------------- /docs/struct_date_formatter-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Member List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
DateFormatter Member List
60 |
61 |
62 | 63 |

This is the complete list of members for DateFormatter, including all inherited members.

64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
COMPATDateFormatterstatic
DATE_ONLYDateFormatterstatic
format(const char *fmt, const time_t timeSecs, const int timeZone=0)DateFormatterinlinestatic
HTTPDateFormatterstatic
ISO8601DateFormatterstatic
SIMPLEDateFormatterstatic
TIME_ONLYDateFormatterstatic
73 |
74 | 75 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/struct_date_time_parts-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ESP DateTime: Member List 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 34 | 35 | 36 |
29 |
ESP DateTime 30 |  0.2.0 31 |
32 |
Date Time Functions and Classes for ESP8266 and ESP32
33 |
37 |
38 | 39 | 40 |
41 |
42 | 47 |
49 |
50 |
51 | 56 |
57 |
58 |
59 |
DateTimeParts Member List
60 |
61 |
62 | 63 |

This is the complete list of members for DateTimeParts, including all inherited members.

64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
_tmDateTimeParts
_tsDateTimeParts
_tzDateTimeParts
format(const char *fmt) constDateTimeParts
from(const time_t timeSecs, const int timeZone=0)DateTimePartsstatic
from(DateTimeClass *dateTime)DateTimePartsstatic
getHours() constDateTimePartsinline
getMinutes() constDateTimePartsinline
getMonth() constDateTimePartsinline
getMonthDay() constDateTimePartsinline
getSeconds() constDateTimePartsinline
getTime() constDateTimePartsinline
getTimeZone() constDateTimePartsinline
getWeekDay() constDateTimePartsinline
getYear() constDateTimePartsinline
getYearDay() constDateTimePartsinline
toString() constDateTimeParts
83 |
84 | 85 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/struct_date_time_parts.js: -------------------------------------------------------------------------------- 1 | var struct_date_time_parts = 2 | [ 3 | [ "format", "struct_date_time_parts.html#a460df90cbdb925087b59ffaf130dafae", null ], 4 | [ "getHours", "struct_date_time_parts.html#a66f5fc739866f1c09cc5c02c14cb771d", null ], 5 | [ "getMinutes", "struct_date_time_parts.html#abae74225a60aea4499009170437cba62", null ], 6 | [ "getMonth", "struct_date_time_parts.html#ad24590f3bcd2c442d86134222a963228", null ], 7 | [ "getMonthDay", "struct_date_time_parts.html#a23c0c57d37c178359fd76be0996d20ad", null ], 8 | [ "getSeconds", "struct_date_time_parts.html#adcc5141646b82270de6718cc83e8557c", null ], 9 | [ "getTime", "struct_date_time_parts.html#a6b321b7845a89a3c6ad52176daec8d95", null ], 10 | [ "getTimeZone", "struct_date_time_parts.html#a8eae5ec1c3f06fb641dd059e9a4503fa", null ], 11 | [ "getWeekDay", "struct_date_time_parts.html#a09762117726998bdf734cc0013d5fdbe", null ], 12 | [ "getYear", "struct_date_time_parts.html#ae431a2065019aee926b05394dd972332", null ], 13 | [ "getYearDay", "struct_date_time_parts.html#ac22ee88a56d70c5660a4e14a2b1ede80", null ], 14 | [ "toString", "struct_date_time_parts.html#a12b3033250329e4bd22945e7b0f53c28", null ], 15 | [ "_tm", "struct_date_time_parts.html#a6d83a22432d99601ef113b020d4976fe", null ], 16 | [ "_ts", "struct_date_time_parts.html#a20a9a75d3f7ed8ffdfdca59bfe25e2c8", null ], 17 | [ "_tz", "struct_date_time_parts.html#acc77b2af9393b4ae0f84718b6a0e7541", null ] 18 | ]; -------------------------------------------------------------------------------- /docs/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/sync_off.png -------------------------------------------------------------------------------- /docs/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/sync_on.png -------------------------------------------------------------------------------- /docs/tab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/tab_a.png -------------------------------------------------------------------------------- /docs/tab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/tab_b.png -------------------------------------------------------------------------------- /docs/tab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/tab_h.png -------------------------------------------------------------------------------- /docs/tab_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcxiaoke/ESPDateTime/349aafca4eeac95f81d0dc89ef87d534b1b52b90/docs/tab_s.png -------------------------------------------------------------------------------- /docs/tabs.css: -------------------------------------------------------------------------------- 1 | .sm{position:relative;z-index:9999}.sm,.sm ul,.sm li{display:block;list-style:none;margin:0;padding:0;line-height:normal;direction:ltr;text-align:left;-webkit-tap-highlight-color:rgba(0,0,0,0)}.sm-rtl,.sm-rtl ul,.sm-rtl li{direction:rtl;text-align:right}.sm>li>h1,.sm>li>h2,.sm>li>h3,.sm>li>h4,.sm>li>h5,.sm>li>h6{margin:0;padding:0}.sm ul{display:none}.sm li,.sm a{position:relative}.sm a{display:block}.sm a.disabled{cursor:not-allowed}.sm:after{content:"\00a0";display:block;height:0;font:0/0 serif;clear:both;visibility:hidden;overflow:hidden}.sm,.sm *,.sm *:before,.sm *:after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}.sm-dox{background-image:url("tab_b.png")}.sm-dox a,.sm-dox a:focus,.sm-dox a:hover,.sm-dox a:active{padding:0 12px;padding-right:43px;font-family:"Lucida Grande","Geneva","Helvetica",Arial,sans-serif;font-size:13px;font-weight:bold;line-height:36px;text-decoration:none;text-shadow:0 1px 1px rgba(255,255,255,0.9);color:#283a5d;outline:0}.sm-dox a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:white;text-shadow:0 1px 1px black}.sm-dox a.current{color:#d23600}.sm-dox a.disabled{color:#bbb}.sm-dox a span.sub-arrow{position:absolute;top:50%;margin-top:-14px;left:auto;right:3px;width:28px;height:28px;overflow:hidden;font:bold 12px/28px monospace!important;text-align:center;text-shadow:none;background:rgba(255,255,255,0.5);-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px}.sm-dox a.highlighted span.sub-arrow:before{display:block;content:'-'}.sm-dox>li:first-child>a,.sm-dox>li:first-child>:not(ul) a{-moz-border-radius:5px 5px 0 0;-webkit-border-radius:5px;border-radius:5px 5px 0 0}.sm-dox>li:last-child>a,.sm-dox>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul{-moz-border-radius:0 0 5px 5px;-webkit-border-radius:0;border-radius:0 0 5px 5px}.sm-dox>li:last-child>a.highlighted,.sm-dox>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>a.highlighted,.sm-dox>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>ul>li:last-child>*:not(ul) a.highlighted{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0}.sm-dox ul{background:rgba(162,162,162,0.1)}.sm-dox ul a,.sm-dox ul a:focus,.sm-dox ul a:hover,.sm-dox ul a:active{font-size:12px;border-left:8px solid transparent;line-height:36px;text-shadow:none;background-color:white;background-image:none}.sm-dox ul a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:white;text-shadow:0 1px 1px black}.sm-dox ul ul a,.sm-dox ul ul a:hover,.sm-dox ul ul a:focus,.sm-dox ul ul a:active{border-left:16px solid transparent}.sm-dox ul ul ul a,.sm-dox ul ul ul a:hover,.sm-dox ul ul ul a:focus,.sm-dox ul ul ul a:active{border-left:24px solid transparent}.sm-dox ul ul ul ul a,.sm-dox ul ul ul ul a:hover,.sm-dox ul ul ul ul a:focus,.sm-dox ul ul ul ul a:active{border-left:32px solid transparent}.sm-dox ul ul ul ul ul a,.sm-dox ul ul ul ul ul a:hover,.sm-dox ul ul ul ul ul a:focus,.sm-dox ul ul ul ul ul a:active{border-left:40px solid transparent}@media(min-width:768px){.sm-dox ul{position:absolute;width:12em}.sm-dox li{float:left}.sm-dox.sm-rtl li{float:right}.sm-dox ul li,.sm-dox.sm-rtl ul li,.sm-dox.sm-vertical li{float:none}.sm-dox a{white-space:nowrap}.sm-dox ul a,.sm-dox.sm-vertical a{white-space:normal}.sm-dox .sm-nowrap>li>a,.sm-dox .sm-nowrap>li>:not(ul) a{white-space:nowrap}.sm-dox{padding:0 10px;background-image:url("tab_b.png");line-height:36px}.sm-dox a span.sub-arrow{top:50%;margin-top:-2px;right:12px;width:0;height:0;border-width:4px;border-style:solid dashed dashed dashed;border-color:#283a5d transparent transparent transparent;background:transparent;-moz-border-radius:0;-webkit-border-radius:0;border-radius:0}.sm-dox a,.sm-dox a:focus,.sm-dox a:active,.sm-dox a:hover,.sm-dox a.highlighted{padding:0 12px;background-image:url("tab_s.png");background-repeat:no-repeat;background-position:right;-moz-border-radius:0!important;-webkit-border-radius:0;border-radius:0!important}.sm-dox a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:white;text-shadow:0 1px 1px black}.sm-dox a:hover span.sub-arrow{border-color:white transparent transparent transparent}.sm-dox a.has-submenu{padding-right:24px}.sm-dox li{border-top:0}.sm-dox>li>ul:before,.sm-dox>li>ul:after{content:'';position:absolute;top:-18px;left:30px;width:0;height:0;overflow:hidden;border-width:9px;border-style:dashed dashed solid dashed;border-color:transparent transparent #bbb transparent}.sm-dox>li>ul:after{top:-16px;left:31px;border-width:8px;border-color:transparent transparent #fff transparent}.sm-dox ul{border:1px solid #bbb;padding:5px 0;background:#fff;-moz-border-radius:5px!important;-webkit-border-radius:5px;border-radius:5px!important;-moz-box-shadow:0 5px 9px rgba(0,0,0,0.2);-webkit-box-shadow:0 5px 9px rgba(0,0,0,0.2);box-shadow:0 5px 9px rgba(0,0,0,0.2)}.sm-dox ul a span.sub-arrow{right:8px;top:50%;margin-top:-5px;border-width:5px;border-color:transparent transparent transparent #555;border-style:dashed dashed dashed solid}.sm-dox ul a,.sm-dox ul a:hover,.sm-dox ul a:focus,.sm-dox ul a:active,.sm-dox ul a.highlighted{color:#555;background-image:none;border:0!important;color:#555;background-image:none}.sm-dox ul a:hover{background-image:url("tab_a.png");background-repeat:repeat-x;color:white;text-shadow:0 1px 1px black}.sm-dox ul a:hover span.sub-arrow{border-color:transparent transparent transparent white}.sm-dox span.scroll-up,.sm-dox span.scroll-down{position:absolute;display:none;visibility:hidden;overflow:hidden;background:#fff;height:36px}.sm-dox span.scroll-up:hover,.sm-dox span.scroll-down:hover{background:#eee}.sm-dox span.scroll-up:hover span.scroll-up-arrow,.sm-dox span.scroll-up:hover span.scroll-down-arrow{border-color:transparent transparent #d23600 transparent}.sm-dox span.scroll-down:hover span.scroll-down-arrow{border-color:#d23600 transparent transparent transparent}.sm-dox span.scroll-up-arrow,.sm-dox span.scroll-down-arrow{position:absolute;top:0;left:50%;margin-left:-6px;width:0;height:0;overflow:hidden;border-width:6px;border-style:dashed dashed solid dashed;border-color:transparent transparent #555 transparent}.sm-dox span.scroll-down-arrow{top:8px;border-style:solid dashed dashed dashed;border-color:#555 transparent transparent transparent}.sm-dox.sm-rtl a.has-submenu{padding-right:12px;padding-left:24px}.sm-dox.sm-rtl a span.sub-arrow{right:auto;left:12px}.sm-dox.sm-rtl.sm-vertical a.has-submenu{padding:10px 20px}.sm-dox.sm-rtl.sm-vertical a span.sub-arrow{right:auto;left:8px;border-style:dashed solid dashed dashed;border-color:transparent #555 transparent transparent}.sm-dox.sm-rtl>li>ul:before{left:auto;right:30px}.sm-dox.sm-rtl>li>ul:after{left:auto;right:31px}.sm-dox.sm-rtl ul a.has-submenu{padding:10px 20px!important}.sm-dox.sm-rtl ul a span.sub-arrow{right:auto;left:8px;border-style:dashed solid dashed dashed;border-color:transparent #555 transparent transparent}.sm-dox.sm-vertical{padding:10px 0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px}.sm-dox.sm-vertical a{padding:10px 20px}.sm-dox.sm-vertical a:hover,.sm-dox.sm-vertical a:focus,.sm-dox.sm-vertical a:active,.sm-dox.sm-vertical a.highlighted{background:#fff}.sm-dox.sm-vertical a.disabled{background-image:url("tab_b.png")}.sm-dox.sm-vertical a span.sub-arrow{right:8px;top:50%;margin-top:-5px;border-width:5px;border-style:dashed dashed dashed solid;border-color:transparent transparent transparent #555}.sm-dox.sm-vertical>li>ul:before,.sm-dox.sm-vertical>li>ul:after{display:none}.sm-dox.sm-vertical ul a{padding:10px 20px}.sm-dox.sm-vertical ul a:hover,.sm-dox.sm-vertical ul a:focus,.sm-dox.sm-vertical ul a:active,.sm-dox.sm-vertical ul a.highlighted{background:#eee}.sm-dox.sm-vertical ul a.disabled{background:#fff}} -------------------------------------------------------------------------------- /examples/simple/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #if defined(ESP8266) 4 | #include 5 | #elif defined(ESP32) 6 | #include 7 | #endif 8 | #include "ESPDateTime.h" 9 | #include "config.h" 10 | 11 | // don't forget to change this to real ssid/password 12 | // or set these in config.h and include it 13 | #ifndef WIFI_SSID 14 | #error WIFI_SSID "Need define WiFi SSID in config.h" 15 | #error WIFI_PASS "Need define WiFi Password config.h" 16 | #endif 17 | 18 | unsigned long lastMs = 0; 19 | 20 | unsigned long ms = millis(); 21 | 22 | void setupWiFi() { 23 | WiFi.mode(WIFI_STA); 24 | WiFi.begin(WIFI_SSID, WIFI_PASS); 25 | Serial.println(millis()); 26 | Serial.print("WiFi Connecting..."); 27 | while (WiFi.status() != WL_CONNECTED) { 28 | delay(500); 29 | Serial.print(WiFi.status()); 30 | } 31 | Serial.println(); 32 | } 33 | 34 | void setupDateTime() { 35 | // setup this after wifi connected 36 | // you can use custom timeZone,server and timeout 37 | // DateTime.setTimeZone(-4); 38 | // DateTime.setServer("asia.pool.ntp.org"); 39 | // DateTime.begin(15 * 1000); 40 | DateTime.setServer("time.pool.aliyun.com"); 41 | DateTime.setTimeZone("CST-8"); 42 | DateTime.begin(); 43 | if (!DateTime.isTimeValid()) { 44 | Serial.println("Failed to get time from server."); 45 | } else { 46 | Serial.printf("Date Now is %s\n", DateTime.toISOString().c_str()); 47 | Serial.printf("Timestamp is %ld\n", DateTime.now()); 48 | } 49 | } 50 | 51 | /** 52 | * More examples and docs see : 53 | * https://github.com/mcxiaoke/ESPDateTime 54 | * 55 | */ 56 | 57 | void showTime() { 58 | Serial.printf("TimeZone: %s\n", DateTime.getTimeZone()); 59 | Serial.printf("Up Time: %lu seconds\n", millis() / 1000); 60 | Serial.printf("Boot Time: %ld seconds\n", DateTime.getBootTime()); 61 | Serial.printf("Cur Time: %ld seconds\n", 62 | DateTime.getBootTime() + millis() / 1000); 63 | Serial.printf("Now Time: %ld\n", DateTime.now()); 64 | Serial.printf("OS Time: %ld\n", DateTime.osTime()); 65 | Serial.printf("NTP Time: %ld\n", DateTime.ntpTime(2 * 1000L)); 66 | // Serial.println(); 67 | Serial.printf("Local Time: %s\n", 68 | DateTime.format(DateFormatter::SIMPLE).c_str()); 69 | Serial.printf("ISO86 Time: %s\n", DateTime.toISOString().c_str()); 70 | Serial.printf("UTC Time: %s\n", 71 | DateTime.formatUTC(DateFormatter::SIMPLE).c_str()); 72 | Serial.printf("UTC86 Time: %s\n", 73 | DateTime.formatUTC(DateFormatter::ISO8601).c_str()); 74 | 75 | Serial.println("==========="); 76 | time_t t = time(NULL); 77 | Serial.printf("OS local: %s", asctime(localtime(&t))); 78 | Serial.printf("OS UTC: %s", asctime(gmtime(&t))); 79 | } 80 | 81 | void setup() { 82 | delay(1000); 83 | Serial.begin(115200); 84 | setupWiFi(); 85 | setupDateTime(); 86 | Serial.println(DateTime.now()); 87 | Serial.println("--------------------"); 88 | Serial.println(DateTime.toString()); 89 | Serial.println(DateTime.toISOString()); 90 | Serial.println(DateTime.toUTCString()); 91 | Serial.println("--------------------"); 92 | Serial.println(DateTime.format(DateFormatter::COMPAT)); 93 | Serial.println(DateTime.format(DateFormatter::DATE_ONLY)); 94 | Serial.println(DateTime.format(DateFormatter::TIME_ONLY)); 95 | Serial.println("--------------------"); 96 | DateTimeParts p = DateTime.getParts(); 97 | Serial.printf("%04d/%02d/%02d %02d:%02d:%02d %ld (%s)\n", p.getYear(), 98 | p.getMonth(), p.getMonthDay(), p.getHours(), p.getMinutes(), 99 | p.getSeconds(), p.getTime(), p.getTimeZone()); 100 | Serial.println("--------------------"); 101 | showTime(); 102 | } 103 | 104 | void loop() { 105 | if (millis() - ms > 15 * 1000L) { 106 | ms = millis(); 107 | Serial.println("--------------------"); 108 | if (!DateTime.isTimeValid()) { 109 | Serial.println("Failed to get time from server, retry."); 110 | DateTime.begin(); 111 | } else { 112 | showTime(); 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | # Syntax Coloring Map For ExampleLibrary 2 | 3 | # Datatypes (KEYWORD1) 4 | DateTimeParts KEYWORD1 5 | DateFormatter KEYWORD1 6 | DateTimeClass KEYWORD1 7 | TimeElapsed KEYWORD1 8 | 9 | # Methods and Functions (KEYWORD2) 10 | setTimeZone KEYWORD2 11 | setServer KEYWORD2 12 | forceUpdate KEYWORD2 13 | setTime KEYWORD2 14 | format KEYWORD2 15 | formatUTC KEYWORD2 16 | begin KEYWORD2 17 | isTimeValid KEYWORD2 18 | getBootTime KEYWORD2 19 | now KEYWORD2 20 | getTime KEYWORD2 21 | getTimeZone KEYWORD2 22 | getServer KEYWORD2 23 | getParts KEYWORD2 24 | toString KEYWORD2 25 | toISOString KEYWORD2 26 | toUTCString KEYWORD2 27 | 28 | getYear KEYWORD2 29 | getMonth KEYWORD2 30 | getYearDay KEYWORD2 31 | getMonthDay KEYWORD2 32 | getWeekDay KEYWORD2 33 | getHours KEYWORD2 34 | getMinutes KEYWORD2 35 | getSeconds KEYWORD2 36 | from KEYWORD2 37 | 38 | # Instances (KEYWORD2) 39 | DateTime KEYWORD2 40 | 41 | # Constants (LITERAL1) 42 | ISO8601 LITERAL1 43 | HTTP LITERAL1 44 | SIMPLE LITERAL1 45 | COMPAT LITERAL1 46 | DATE_ONLY LITERAL1 47 | TIME_ONLY LITERAL1 48 | DEFAULT_TIMEZONE LITERAL1 49 | DEFAULT_TIMEOUT LITERAL1 50 | NTP_SERVER_1 LITERAL1 51 | NTP_SERVER_2 LITERAL1 52 | NTP_SERVER_3 LITERAL1 53 | TIME_ZERO LITERAL1 -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ESPDateTime", 3 | "keywords": "esp8266,esp32,arduino,utils,datetime,date,time,formatter,ntp,device,display,rtc", 4 | "description": "Date Time Functions and Classes for ESP8266 and ESP32", 5 | "homepage": "https://github.com/mcxiaoke/ESPDateTime", 6 | "authors": { 7 | "name": "Zhang Xiaoke", 8 | "email": "github@mcxiaoke.com", 9 | "url": "https://github.com/mcxiaoke", 10 | "maintainer": true 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/mcxiaoke/ESPDateTime.git" 15 | }, 16 | "version": "1.0.4", 17 | "license": "Apache-2.0", 18 | "frameworks": "arduino", 19 | "platforms": ["espressif8266", "espressif32"] 20 | } 21 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESPDateTime 2 | version=1.0.4 3 | author=Zhang Xiaoke 4 | maintainer=Zhang Xiaoke 5 | sentence=Date Time Functions and Classes for ESP8266 and ESP32 6 | paragraph=This library provides a simple class for sync system timestamp vis ntp and format date time to string, works on esp8266 and esp32 platform. 7 | category=Other 8 | url=https://github.com/mcxiaoke/ESPDateTime 9 | architectures=* 10 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | default_envs = nodemcuv2 13 | 14 | [env] 15 | framework = arduino 16 | # upload_speed = 115200 17 | monitor_speed = 115200 18 | 19 | [env:nodemcuv2] 20 | build_type = debug 21 | platform = espressif8266 22 | board = nodemcuv2 23 | build_flags = -DDEBUG -DESP_DATE_TIME_DEBUG 24 | src_filter = +<.> +<../examples/simple> 25 | 26 | [env:nodemcu32s] 27 | build_type = debug 28 | platform = espressif32 29 | board = nodemcu-32s 30 | build_flags = -DDEBUG -DESP_DATE_TIME_DEBUG 31 | src_filter = +<.> +<../examples/simple> 32 | 33 | [env:testnodemcuv2] 34 | build_type = debug 35 | platform = espressif8266 36 | board = nodemcuv2 37 | build_flags = -DDEBUG -DESP_DATE_TIME_DEBUG 38 | lib_deps = bxparks/AUnit @ ^1.5.1 39 | test_build_project_src = true 40 | 41 | [env:testnodemcu32s] 42 | build_type = debug 43 | platform = espressif32 44 | board = nodemcu-32s 45 | build_flags = -DDEBUG -DESP_DATE_TIME_DEBUG 46 | lib_deps = bxparks/AUnit @ ^1.5.1 47 | test_build_project_src = true 48 | 49 | -------------------------------------------------------------------------------- /run_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | pio test -e testnodemcuv2 3 | # pio test -e testnodemcu-32s 4 | -------------------------------------------------------------------------------- /src/DateTime.cpp: -------------------------------------------------------------------------------- 1 | #include "DateTime.h" 2 | 3 | // static time_t getCurrentTime() { 4 | // need #include 5 | // using std::chrono::system_clock; 6 | // auto now = system_clock::now(); 7 | // std::time_t now_time_t = system_clock::to_time_t(now); 8 | // } 9 | 10 | static time_t validateTime(const time_t timeSecs) { 11 | auto bootSecs = timeSecs - (time_t)(millis() / 1000); 12 | return bootSecs > DateTimeClass::SECS_START_POINT ? bootSecs 13 | : DateTimeClass::TIME_ZERO; 14 | } 15 | 16 | String DateTimeParts::format(const char* fmt) const { 17 | char buf[64]; 18 | struct tm* t = localtime(&_ts); 19 | strftime(buf, sizeof(buf), fmt, t); 20 | return String(buf); 21 | } 22 | 23 | String DateTimeParts::formatUTC(const char* fmt) const { 24 | char buf[64]; 25 | struct tm* t = gmtime(&_ts); 26 | strftime(buf, sizeof(buf), fmt, t); 27 | return String(buf); 28 | } 29 | 30 | String DateTimeParts::toString() const { 31 | return format(DateFormatter::ISO8601); 32 | } 33 | 34 | DateTimeParts DateTimeParts::from(const time_t timeSecs, const char* timeZone) { 35 | return {timeSecs, timeZone}; 36 | } 37 | 38 | DateTimeParts DateTimeParts::from(DateTimeClass* dateTime) { 39 | return from(dateTime->getTime(), dateTime->getTimeZone()); 40 | } 41 | 42 | DateTimeClass::DateTimeClass(const time_t _timeSecs, const char* _timeZone, 43 | const char* _ntpServer) 44 | : bootTimeSecs(validateTime(_timeSecs)), 45 | timeZone(_timeZone), 46 | ntpServer1(_ntpServer), 47 | ntpMode(bootTimeSecs == TIME_ZERO) {} 48 | 49 | bool DateTimeClass::setTimeZone(const char* _timeZone) { 50 | if (strcmp(timeZone, _timeZone) == 0) { 51 | return false; 52 | } 53 | timeZone = _timeZone; 54 | #ifdef ESP_DATE_TIME_DEBUG 55 | Serial.printf("setTimeZone to %s\n", _timeZone); 56 | #endif 57 | return true; 58 | } 59 | void DateTimeClass::setServer(const char* _server1, const char* _server2, 60 | const char* _server3) { 61 | #ifdef ESP_DATE_TIME_DEBUG 62 | Serial.printf("setServer to %s,%s,%s\n", _server1, _server2, _server3); 63 | #endif 64 | ntpServer1 = _server1; 65 | ntpServer2 = _server2; 66 | ntpServer3 = _server3; 67 | } 68 | 69 | bool DateTimeClass::forceUpdate(const unsigned int timeOutMs) { 70 | #ifdef ESP_DATE_TIME_DEBUG 71 | Serial.printf("forceUpdate,timeZone:%s, server:%s, timeOut:%u\n", timeZone, 72 | ntpServer1, timeOutMs); 73 | #endif 74 | // esp8266 not support time_zone, just add seconds 75 | // so strftime %z always +0000 76 | #if defined(ESP8266) 77 | configTime(timeZone, ntpServer1, ntpServer2, ntpServer3); 78 | #elif defined(ESP32) 79 | configTzTime(timeZone, ntpServer1, ntpServer2, ntpServer3); 80 | #endif 81 | time_t now = time(nullptr); 82 | auto startMs = millis(); 83 | unsigned long retryCount = 0; 84 | while (now < SECS_START_POINT && (millis() - startMs < timeOutMs)) { 85 | delay(50 + 50 * retryCount++); 86 | now = time(nullptr); 87 | } 88 | #ifdef ESP_DATE_TIME_DEBUG 89 | Serial.printf("forceUpdate,now:%ld\n", now); 90 | #endif 91 | ntpMode = true; 92 | setTime(time(nullptr)); 93 | return isTimeValid(); 94 | } 95 | 96 | time_t DateTimeClass::ntpTime(const unsigned int timeOutMs) { 97 | #ifdef ESP_DATE_TIME_DEBUG 98 | Serial.printf("ntpTime,timeZone:%s, server:%s, timeOut:%u\n", timeZone, 99 | ntpServer1, timeOutMs); 100 | #endif 101 | time_t now = time(nullptr); 102 | auto startMs = millis(); 103 | unsigned long retryCount = 0; 104 | while (millis() - startMs < timeOutMs) { 105 | delay(50 + 50 * retryCount++); 106 | now = time(nullptr); 107 | } 108 | #ifdef ESP_DATE_TIME_DEBUG 109 | Serial.printf("ntpTime,now:%ld\n", now); 110 | #endif 111 | return now; 112 | } 113 | 114 | bool DateTimeClass::setTime(const time_t timeSecs, bool forceSet) { 115 | if (forceSet || timeSecs > SECS_START_POINT) { 116 | bootTimeSecs = timeSecs - (time_t)(millis() / 1000); 117 | } 118 | #ifdef ESP_DATE_TIME_DEBUG 119 | Serial.printf("setTime,timeSecs:%ld, bootTimeSecs:%ld\n", timeSecs, 120 | bootTimeSecs); 121 | #endif 122 | return isTimeValid(); 123 | } 124 | 125 | String DateTimeClass::format(const char* fmt) { return getParts().format(fmt); } 126 | 127 | String DateTimeClass::formatUTC(const char* fmt) { 128 | return getParts().formatUTC(fmt); 129 | } 130 | 131 | DateTimeClass DateTime; -------------------------------------------------------------------------------- /src/DateTime.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP_DATE_TIME_CLASS_H 2 | #define ESP_DATE_TIME_CLASS_H 3 | 4 | /** 5 | * @file DateTime.h 6 | * @author Zhang Xiaoke (github@mcxiaoke.com) 7 | * @brief ESPDateTime header 8 | * 9 | */ 10 | 11 | #if !defined(ESP8266) && !defined(ESP32) 12 | #error "ESPDateTime only support ESP32 or ESP8266 platform!" 13 | #endif 14 | 15 | /** 16 | * @brief Default TimeZone Offset GMT+0 17 | * 18 | */ 19 | #define DEFAULT_TIMEZONE "UTC0" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | class DateTimeClass; 26 | 27 | /** 28 | * @brief DateTime Parts struct, similar to struct tm in , containing a 29 | * calendar date and time broken down into its components, but more readable, 30 | * include some useful getter methods. 31 | * 32 | */ 33 | struct DateTimeParts { 34 | // http://www.cplusplus.com/reference/ctime/tm/ 35 | const time_t _ts; /**< timestamp variable, internal */ 36 | const char* _tz; /**< timezone variable, internal */ 37 | /** 38 | * @brief Get current timestamp, in seconds 39 | * 40 | * @return time_t timestamp, in seconds 41 | */ 42 | time_t getTime() const { return _ts; } 43 | /** 44 | * @brief Get internal timezone offset 45 | * 46 | * @return int timezone offset 47 | */ 48 | const char* getTimeZone() const { return _tz; } 49 | /** 50 | * @brief Get the year (format: 19xx, 20xx) 51 | * 52 | * @return int year value 53 | */ 54 | int getYear() const { 55 | struct tm* t = localtime(&_ts); 56 | return t->tm_year + 1900; 57 | } 58 | /** 59 | * @brief Get months since January (0-11) 60 | * 61 | * @return int month value 62 | */ 63 | int getMonth() const { 64 | struct tm* t = localtime(&_ts); 65 | return t->tm_mon; 66 | } 67 | /** 68 | * @brief Get days since January 1 (0-365) 69 | * 70 | * @return int day of year 71 | */ 72 | int getYearDay() const { 73 | struct tm* t = localtime(&_ts); 74 | return t->tm_yday; 75 | } 76 | /** 77 | * @brief Get day of the month (1-31) 78 | * 79 | * @return int month day 80 | */ 81 | int getMonthDay() const { 82 | struct tm* t = localtime(&_ts); 83 | return t->tm_mday; 84 | } 85 | /** 86 | * @brief Get days since Sunday (0-6) 87 | * 88 | * @return int day of week 89 | */ 90 | int getWeekDay() const { 91 | struct tm* t = localtime(&_ts); 92 | return t->tm_wday; 93 | } 94 | /** 95 | * @brief Get hours since midnight (0-23) 96 | * 97 | * @return int hours 98 | */ 99 | int getHours() const { 100 | struct tm* t = localtime(&_ts); 101 | return t->tm_hour; 102 | } 103 | /** 104 | * @brief Get minutes after the hour (0-59) 105 | * 106 | * @return int minutes 107 | */ 108 | int getMinutes() const { 109 | struct tm* t = localtime(&_ts); 110 | return t->tm_min; 111 | } 112 | /** 113 | * @brief Get seconds after the minute (0-60) 114 | * 115 | * @return int seconds 116 | */ 117 | int getSeconds() const { 118 | struct tm* t = localtime(&_ts); 119 | return t->tm_sec; 120 | } 121 | 122 | /** 123 | * @brief Foramt current time to string representation 124 | * 125 | * @param fmt format string for strftime 126 | * @return String string representation of current time 127 | */ 128 | String format(const char* fmt) const; 129 | 130 | /** 131 | * @brief Foramt utc time to string representation 132 | * 133 | * @param fmt format string for strftime 134 | * @return String string representation of current time 135 | */ 136 | String formatUTC(const char* fmt) const; 137 | /** 138 | * @brief Get string representation of current time 139 | * 140 | * @return String string representation of current time 141 | */ 142 | String toString() const; 143 | 144 | /** 145 | * @brief factory method for constructing DateTimeParts from timestamp and 146 | * timezone. 147 | * 148 | * @param timeSecs timestamp in seconds since 1970 149 | * @param timeZone timezone offset (-11,+13) 150 | * @return DateTimeParts DateTimeParts object 151 | */ 152 | static DateTimeParts from(const time_t timeSecs, 153 | const char* timeZone = DEFAULT_TIMEZONE); 154 | /** 155 | * @brief factory method for constructing DateTimeParts from DateTimeClass 156 | * object. 157 | * 158 | * @param dateTime DateTimeClass object 159 | * @return DateTimeParts DateTimeParts object 160 | */ 161 | static DateTimeParts from(DateTimeClass* dateTime); 162 | }; 163 | 164 | /** 165 | * @brief DateTime Formatter constants and static format methods. 166 | * 167 | * Details in http://www.cplusplus.com/reference/ctime/strftime/ 168 | * 169 | */ 170 | struct DateFormatter { 171 | /** 172 | * @brief ISO8601 date time string format (2019-11-29T23:29:55+0800). 173 | * 174 | */ 175 | constexpr static const char* ISO8601 = "%FT%T%z"; 176 | /** 177 | * @brief RFC1123 date time string format (Fri, 29 Nov 2019 15:29:55 GMT) 178 | * 179 | */ 180 | constexpr static const char* HTTP = "%a, %d %b %Y %H:%M:%S GMT"; 181 | /** 182 | * @brief Simple date time string format (2019-11-29 23:29:55). 183 | * 184 | */ 185 | constexpr static const char* SIMPLE = "%F %T"; 186 | /** 187 | * @brief Compat date time string format (20191129_232955). 188 | * 189 | */ 190 | constexpr static const char* COMPAT = "%Y%m%d_%H%M%S"; 191 | /** 192 | * @brief Date Only date time string format (2019-11-29). 193 | * 194 | */ 195 | constexpr static const char* DATE_ONLY = "%F"; 196 | /** 197 | * @brief Time Only date time string format (23:29:55). 198 | * 199 | */ 200 | constexpr static const char* TIME_ONLY = "%T"; 201 | /** 202 | * @brief utility method for formatting time using fmt. 203 | * 204 | * @param fmt date time format string 205 | * @param timeSecs timestamp value 206 | * @param timeZone timezone offset (-11,13) 207 | * @return String string representation of timeSecs 208 | */ 209 | inline static String format(const char* fmt, const time_t timeSecs, 210 | const char* timeZone = DEFAULT_TIMEZONE) { 211 | return DateTimeParts::from(timeSecs, timeZone).format(fmt); 212 | } 213 | }; 214 | 215 | /** 216 | * @brief DateTime Library Main Class, include time get/set/format methods. 217 | * 218 | */ 219 | class DateTimeClass { 220 | public: 221 | /** 222 | * @brief Valid min timestamp value 1609459200 (2021/01/01 00:00:00). 223 | * 224 | * return value from time(null) < 1609459200 means system time invalid 225 | * 226 | */ 227 | constexpr static time_t SECS_START_POINT = 1609459200; // 20191128 228 | /** 229 | * @brief Unix Time Zero constant (1970-01-01 00:00:00) 230 | * 231 | */ 232 | constexpr static time_t TIME_ZERO = 0; 233 | /** 234 | * @brief NTP Request default timeout: 10 seconds 235 | * 236 | */ 237 | constexpr static unsigned int DEFAULT_TIMEOUT = 10 * 1000; // milliseconds 238 | /** 239 | * @brief NTP Server 1 240 | * 241 | */ 242 | constexpr static const char* NTP_SERVER_1 = "pool.ntp.org"; 243 | /** 244 | * @brief NTP Server 2 245 | * 246 | */ 247 | constexpr static const char* NTP_SERVER_2 = "time.apple.com"; 248 | /** 249 | * @brief NTP Server 3 250 | * 251 | */ 252 | constexpr static const char* NTP_SERVER_3 = "time.windows.com"; 253 | /** 254 | * @brief Construct a new DateTimeClass object. 255 | * 256 | * @param _timeSecs set initialize timestamp 257 | * @param _timeZone set initialize timezone offset 258 | * @param _ntpServer set initialize ntp server 259 | */ 260 | DateTimeClass(const time_t _timeSecs = TIME_ZERO, 261 | const char* _timeZone = DEFAULT_TIMEZONE, 262 | const char* _ntpServer = NTP_SERVER_1); 263 | /** 264 | * @brief Set the TimeZone offset 265 | * 266 | * @param _timeZone time zone offset value 267 | * @return true if time zone valid and changed 268 | * @return false if time zone not valid or not changed 269 | */ 270 | bool setTimeZone(const char* _timeZone); 271 | /** 272 | * @brief Set the NTP Server 273 | * 274 | * @param _server1 ntp server domain name or ip address 275 | * @param _server2 ntp server domain name or ip address 276 | * @param _server3 ntp server domain name or ip address 277 | */ 278 | void setServer(const char* _server1, const char* _server2 = NTP_SERVER_2, 279 | const char* _server3 = NTP_SERVER_3); 280 | /** 281 | * @brief Force NTP Sync to update system timestamp for internal use, please * 282 | * using begin() instead. 283 | * 284 | * @param timeOutMs ntp request timeout 285 | * @return true if timestamp updated and valid 286 | * @return false if timestamp not valid 287 | */ 288 | bool forceUpdate(const unsigned int timeOutMs = DEFAULT_TIMEOUT); 289 | /** 290 | * @brief Force NTP Sync, but not call setTime(). 291 | * 292 | * @param timeOutMs ntp request timeout 293 | */ 294 | time_t ntpTime(const unsigned int timeOutMs = DEFAULT_TIMEOUT); 295 | /** 296 | * @brief Set the timestamp from outside, for test only 297 | * 298 | * @param timeSecs timestamp in seconds 299 | * @param forceSet ignore valid check, force set 300 | * @return true if timestamp valid 301 | * @return false if timestamp not valid 302 | */ 303 | bool setTime(const time_t timeSecs, bool forceSet = false); 304 | /** 305 | * @brief Format current local time to string 306 | * 307 | * Attention: ESP8266 does not support real timezone, it just add timeZone 308 | * 3600 seconds to original timestamp, so %z format is always +0000 309 | * 310 | * @param fmt date time format 311 | * @return String string representation of local time 312 | */ 313 | String format(const char* fmt); 314 | /** 315 | * @brief Format current utc time to string 316 | * 317 | * @param fmt date time format 318 | * @return String String string representation of utc time 319 | */ 320 | String formatUTC(const char* fmt); 321 | // inline functions 322 | // void formatTo(const char* fmt, char* dst); 323 | /** 324 | * @brief Begin ntp sync to update system time 325 | * 326 | * @param timeOutMs ntp request timeout 327 | * @return true if timestamp updated and valid 328 | * @return false if timestamp not valid 329 | */ 330 | inline bool begin(const unsigned int timeOutMs = DEFAULT_TIMEOUT) { 331 | return isTimeValid() || forceUpdate(timeOutMs); 332 | } 333 | /** 334 | * @brief Check current timestamp is or not valid time 335 | * 336 | * @return true if time valid 337 | * @return false if time not valid 338 | */ 339 | inline bool isTimeValid() const { return bootTimeSecs > SECS_START_POINT; } 340 | /** 341 | * @brief Get system boot timestamp in seconds 342 | * 343 | * @return time_t boot timestamp 344 | */ 345 | inline time_t getBootTime() const { 346 | return bootTimeSecs > SECS_START_POINT ? bootTimeSecs : TIME_ZERO; 347 | } 348 | /** 349 | * @brief Get current local timestamp, alias of getTime() 350 | * 351 | * @return time_t timestamp 352 | */ 353 | inline time_t now() const { return getTime(); } 354 | /** 355 | * @brief Get current local timestamp 356 | * 357 | * @return time_t timestamp 358 | */ 359 | inline time_t getTime() const { return osTime(); } 360 | /** 361 | * @brief Get os timestamp, in seconds 362 | * 363 | * @return time_t timestamp, in seconds 364 | */ 365 | inline time_t osTime() const { 366 | auto t = time(nullptr); 367 | return t > SECS_START_POINT ? t : (time_t)(millis() / 1000); 368 | } 369 | /** 370 | * @brief Get current timezone offset 371 | * 372 | * @return int time zone offset 373 | */ 374 | inline const char* getTimeZone() const { return timeZone; } 375 | /** 376 | * @brief Get current ntp server address 377 | * 378 | * @return const char* ntp server 379 | */ 380 | inline const char* getServer() { return ntpServer1; } 381 | /** 382 | * @brief Get DateTimeParts object 383 | * 384 | * @return DateTimeParts DateTimeParts object 385 | */ 386 | inline DateTimeParts getParts() { return DateTimeParts::from(this); } 387 | /** 388 | * @brief String simple string representation of local time 389 | * 390 | * @return String string representation 391 | */ 392 | inline String toString() { return format(DateFormatter::SIMPLE); } 393 | /** 394 | * @brief String ISO8601 representation of local time 395 | * 396 | * @return String string representation 397 | */ 398 | inline String toISOString() { return format(DateFormatter::ISO8601); } 399 | /** 400 | * @brief String RFC1123 representation of local time 401 | * 402 | * @return String string representation 403 | */ 404 | inline String toUTCString() { return formatUTC(DateFormatter::HTTP); } 405 | // operator overloads 406 | DateTimeClass operator+(const time_t timeDeltaSecs) { 407 | DateTimeClass dt(getTime() + timeDeltaSecs, timeZone, ntpServer1); 408 | return dt; 409 | } 410 | DateTimeClass operator-(const time_t timeDeltaSecs) { 411 | DateTimeClass dt(getTime() - timeDeltaSecs, timeZone, ntpServer1); 412 | return dt; 413 | } 414 | DateTimeClass& operator-=(const time_t timeDeltaSecs) { 415 | bootTimeSecs += timeDeltaSecs; 416 | return *this; 417 | } 418 | DateTimeClass& operator+=(const time_t timeDeltaSecs) { 419 | bootTimeSecs -= timeDeltaSecs; 420 | return *this; 421 | } 422 | friend bool operator<(const DateTimeClass& lhs, const DateTimeClass& rhs) { 423 | return lhs.bootTimeSecs < rhs.bootTimeSecs; 424 | } 425 | friend bool operator>(const DateTimeClass& lhs, const DateTimeClass& rhs) { 426 | return rhs < lhs; 427 | } 428 | friend bool operator<=(const DateTimeClass& lhs, const DateTimeClass& rhs) { 429 | return !(lhs > rhs); 430 | } 431 | friend bool operator>=(const DateTimeClass& lhs, const DateTimeClass& rhs) { 432 | return !(lhs < rhs); 433 | } 434 | 435 | friend bool operator==(const DateTimeClass& lhs, const DateTimeClass& rhs) { 436 | return lhs.bootTimeSecs == rhs.bootTimeSecs && lhs.timeZone == rhs.timeZone; 437 | } 438 | friend bool operator!=(const DateTimeClass& lhs, const DateTimeClass& rhs) { 439 | return !(lhs == rhs); 440 | } 441 | 442 | private: 443 | /** 444 | * @brief Boot timestamp seconds. 445 | * 446 | */ 447 | unsigned long bootTimeSecs; 448 | /** 449 | * @brief Time zone offset 450 | * 451 | */ 452 | const char* timeZone; 453 | /** 454 | * @brief First ntp server address. 455 | * 456 | */ 457 | const char* ntpServer1 = NTP_SERVER_1; 458 | const char* ntpServer2 = NTP_SERVER_2; 459 | const char* ntpServer3 = NTP_SERVER_3; 460 | bool ntpMode; 461 | }; 462 | 463 | /** 464 | * @brief Global DateTimeClass object. 465 | * 466 | */ 467 | extern DateTimeClass DateTime; // define in cpp 468 | 469 | #endif 470 | -------------------------------------------------------------------------------- /src/ESPDateTime.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP_DATE_TIME_LIB_H 2 | #define ESP_DATE_TIME_LIB_H 3 | 4 | /** 5 | * @file ESPDateTime.h 6 | * @author Zhang Xiaoke (github@mcxiaoke.com) 7 | * @brief ESPDateTime header 8 | * 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #endif -------------------------------------------------------------------------------- /src/TimeElapsed.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP_DATE_TIME_TIME_ELAPSED_H 2 | #define ESP_DATE_TIME_TIME_ELAPSED_H 3 | 4 | /** 5 | * @file TimeElapsed.h 6 | * @author Zhang Xiaoke (github@mcxiaoke.com) 7 | * @brief ESPDateTime header 8 | * 9 | */ 10 | 11 | #include 12 | 13 | /** 14 | * @brief TimeElapsed class 15 | * 16 | */ 17 | 18 | class TimeElapsed { 19 | private: 20 | unsigned long ms; 21 | 22 | public: 23 | TimeElapsed() : ms(millis()) {} 24 | TimeElapsed(unsigned long val) { ms = millis() - val; } 25 | TimeElapsed(const TimeElapsed& rhs) { ms = rhs.ms; } 26 | operator unsigned long() const { return millis() - ms; } 27 | TimeElapsed& operator=(const TimeElapsed& rhs) { 28 | ms = rhs.ms; 29 | return *this; 30 | } 31 | TimeElapsed& operator=(unsigned long val) { 32 | ms = millis() - val; 33 | return *this; 34 | } 35 | TimeElapsed& operator-=(unsigned long val) { 36 | ms += val; 37 | return *this; 38 | } 39 | TimeElapsed& operator+=(unsigned long val) { 40 | ms -= val; 41 | return *this; 42 | } 43 | TimeElapsed operator-(int val) const { 44 | TimeElapsed r(*this); 45 | r.ms += val; 46 | return r; 47 | } 48 | TimeElapsed operator-(unsigned int val) const { 49 | TimeElapsed r(*this); 50 | r.ms += val; 51 | return r; 52 | } 53 | TimeElapsed operator-(long val) const { 54 | TimeElapsed r(*this); 55 | r.ms += val; 56 | return r; 57 | } 58 | TimeElapsed operator-(unsigned long val) const { 59 | TimeElapsed r(*this); 60 | r.ms += val; 61 | return r; 62 | } 63 | TimeElapsed operator+(int val) const { 64 | TimeElapsed r(*this); 65 | r.ms -= val; 66 | return r; 67 | } 68 | TimeElapsed operator+(unsigned int val) const { 69 | TimeElapsed r(*this); 70 | r.ms -= val; 71 | return r; 72 | } 73 | TimeElapsed operator+(long val) const { 74 | TimeElapsed r(*this); 75 | r.ms -= val; 76 | return r; 77 | } 78 | TimeElapsed operator+(unsigned long val) const { 79 | TimeElapsed r(*this); 80 | r.ms -= val; 81 | return r; 82 | } 83 | }; 84 | 85 | #endif -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /test/test_config.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ae(arg1, arg2) assertEqual(arg1, arg2) 4 | #define ane(arg1, arg2) assertNotEqual(arg1, arg2) 5 | #define al(arg1, arg2) assertLess(arg1, arg2) 6 | #define am(arg1, arg2) assertMore(arg1, arg2) 7 | #define ale(arg1, arg2) assertLessOrEqual(arg1, arg2) 8 | #define ame(arg1, arg2) assertMoreOrEqual(arg1, arg2) 9 | #define at(arg) assertTrue(arg) 10 | #define af(arg) assertFalse(arg) 11 | 12 | inline bool contains(const char* str, const String& text) { 13 | return strstr(str, text.c_str()) != nullptr; 14 | } -------------------------------------------------------------------------------- /test/test_date_time.cpp: -------------------------------------------------------------------------------- 1 | #line 2 "test_date_time.cpp" 2 | #include 3 | #if defined(ESP8266) 4 | #include 5 | #elif defined(ESP32) 6 | #include 7 | #endif 8 | #include 9 | #include 10 | #include "config.h" 11 | #include "test_config.h" 12 | 13 | // https://github.com/bxparks/AUnit 14 | using namespace aunit; 15 | 16 | test(T001ZeroConstructorA) { 17 | af(DateTime.isTimeValid()); 18 | ae(DateTimeClass::TIME_ZERO, 19 | DateTime.getBootTime() + (time_t)(millis() / 1000)); 20 | ae(DateTimeClass::DEFAULT_TIMEZONE, DateTime.getTimeZone()); 21 | ae(DateTimeClass::TIME_ZERO, DateTime.now()); 22 | ae(DateTimeClass::TIME_ZERO, DateTime.getTime()); 23 | ae(DateTimeClass::TIME_ZERO, DateTime.utcTime()); 24 | ae(DateTimeClass::NTP_SERVER_1, DateTime.getServer()); 25 | } 26 | 27 | test(T002ZeroConstructorB) { 28 | af(DateTime.isTimeValid()); 29 | ae("1970-01-01 00:00:00", DateTime.toString()); 30 | ae("1970-01-01T00:00:00+0000", DateTime.toISOString()); 31 | ae("Thu, 01 Jan 1970 00:00:00 GMT", DateTime.toUTCString()); 32 | } 33 | 34 | test(T003NewConstructorA) { 35 | DateTimeClass d; 36 | af(d.isTimeValid()); 37 | ae(DateTimeClass::TIME_ZERO, d.getBootTime() + (time_t)(millis() / 1000)); 38 | ae(DateTimeClass::DEFAULT_TIMEZONE, d.getTimeZone()); 39 | ae(DateTimeClass::TIME_ZERO, d.now()); 40 | ae(DateTimeClass::TIME_ZERO, d.getTime()); 41 | ae(DateTimeClass::TIME_ZERO, d.utcTime()); 42 | ae(DateTimeClass::NTP_SERVER_1, d.getServer()); 43 | } 44 | 45 | test(T004NewConstructorB) { 46 | DateTimeClass d; 47 | af(d.isTimeValid()); 48 | ae("1970-01-01 00:00:00", d.toString()); 49 | ae("1970-01-01T00:00:00+0000", d.toISOString()); 50 | ae("Thu, 01 Jan 1970 00:00:00 GMT", d.toUTCString()); 51 | } 52 | 53 | test(T005CustomConstructorA) { 54 | // 1574956800 = 20191129000000 55 | time_t t = 1574956800; 56 | int z = 8; 57 | const char* s = "time.apple.com"; 58 | DateTimeClass d(t, z, s); 59 | at(d.isTimeValid()); 60 | ae(t, d.getBootTime() + (time_t)(millis() / 1000)); 61 | ae(z, d.getTimeZone()); 62 | ae(t, d.now()); 63 | ae(t, d.getTime()); 64 | ae(t - 8 * 3600, d.utcTime()); 65 | ae(s, d.getServer()); 66 | } 67 | 68 | test(T006CustomConstructorB) { 69 | // 1574956800 = 20191129000000 70 | time_t t = 1574956800; 71 | int z = 8; 72 | const char* s = "time.apple.com"; 73 | DateTimeClass d(t, z, s); 74 | at(d.isTimeValid()); 75 | ae("2019-11-28 16:00:00", d.toString()); 76 | ae("2019-11-28T16:00:00+0000", d.toISOString()); 77 | ae("Thu, 28 Nov 2019 08:00:00 GMT", d.toUTCString()); 78 | } 79 | 80 | test(T007NTPDateTime) { 81 | // 1574956800 = 20191129000000 82 | DateTime.setTimeZone(8); 83 | DateTime.setServer("time.apple.com"); 84 | af(DateTime.isTimeValid()); 85 | ae(8, DateTime.getTimeZone()); 86 | ae("time.apple.com", DateTime.getServer()); 87 | DateTime.begin(); 88 | Serial.printf("%s (%s, %d)\n", DateTime.toISOString().c_str(), __FUNCTION__, 89 | __LINE__); 90 | at(DateTime.isTimeValid()); 91 | // 1574956800 < timestamp 92 | ale(1574956800L, DateTime.now()); 93 | ale(1574956800L, DateTime.getTime()); 94 | ale(1574956800L - 8 * 3600, DateTime.utcTime()); 95 | } 96 | 97 | test(T008NTPDateTimeClass) { 98 | // 1574956800 = 20191129000000 99 | DateTimeClass d(0, 8); 100 | af(d.isTimeValid()); 101 | ae(8, d.getTimeZone()); 102 | ae(DateTimeClass::NTP_SERVER_1, d.getServer()); 103 | d.begin(); 104 | Serial.printf("%s (%s, %d)\n", d.toISOString().c_str(), __FUNCTION__, 105 | __LINE__); 106 | at(d.isTimeValid()); 107 | // 1574956800 < timestamp 108 | ale(1574956800L, d.now()); 109 | ale(1574956800L, d.getTime()); 110 | ale(1574956800L - 8 * 3600, d.utcTime()); 111 | } 112 | 113 | test(T009DateTimeParts) { 114 | // 1613277037 = 202102141230 115 | int z = 8; 116 | DateTimeClass d; 117 | d.setTimeZone(8); 118 | d.begin(); 119 | at(d.isTimeValid()); 120 | Serial.printf("%s (%s, %d)\n", d.toISOString().c_str(), __FUNCTION__, 121 | __LINE__); 122 | auto p = d.getParts(); 123 | ae(z, p._tz); 124 | // real time test 125 | // replace with cur date 126 | ae(2021, p.getYear()); 127 | ae(2, p.getMonth()); 128 | ae(14, p.getMonthDay()); 129 | ae(6, p.getWeekDay()); 130 | // ae(0, p.getHours()); 131 | // ae(0, p.getMinutes()); 132 | // ae(0, p.getSeconds()); 133 | } 134 | 135 | void setupWiFi() { 136 | WiFi.mode(WIFI_STA); 137 | WiFi.begin(WIFI_SSID, WIFI_PASS); 138 | while (WiFi.status() != WL_CONNECTED) { 139 | delay(200); 140 | } 141 | Serial.println("WiFi Connected"); 142 | } 143 | 144 | void setup() { 145 | delay(1000); 146 | Serial.begin(115200); 147 | setupWiFi(); 148 | TestRunner::setTimeout(120); 149 | TestRunner::setVerbosity(Verbosity::kTestFailed | Verbosity::kTestRunSummary); 150 | } 151 | 152 | void loop() { 153 | // Should get: 154 | // TestRunner summary: 155 | // 3 passed, 1 failed, 0 skipped, 0 timed out, out of 8 test(s). 156 | TestRunner::run(); 157 | } --------------------------------------------------------------------------------