mirror of
https://github.com/PaulStoffregen/Time.git
synced 2025-08-02 23:34:25 +02:00
Merge pull request #143 from pieterbl/master
Few minor updates to the Readme.md file
This commit is contained in:
32
Readme.md
32
Readme.md
@@ -66,8 +66,8 @@ timeNeedsSync // the time had been set but a sync attempt did
|
|||||||
timeSet // the time is set and is synced
|
timeSet // the time is set and is synced
|
||||||
```
|
```
|
||||||
|
|
||||||
Time and Date values are not valid if the status is timeNotSet. Otherwise, values can be used but
|
Time and Date values are not valid if the status is `timeNotSet`. Otherwise, values can be used but
|
||||||
the returned time may have drifted if the status is timeNeedsSync.
|
the returned time may have drifted if the status is `timeNeedsSync`.
|
||||||
|
|
||||||
```c
|
```c
|
||||||
setSyncProvider(getTimeFunction); // set the external time provider
|
setSyncProvider(getTimeFunction); // set the external time provider
|
||||||
@@ -89,15 +89,15 @@ illustrating how the library can be used with various time sources:
|
|||||||
A companion Processing sketch will automatically provide these messages
|
A companion Processing sketch will automatically provide these messages
|
||||||
if it is running and connected to the Arduino serial port.
|
if it is running and connected to the Arduino serial port.
|
||||||
|
|
||||||
- `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above
|
- `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above.
|
||||||
Short (3 characters) and long strings are available to print the days of
|
Short (3 characters) and long strings are available to print the days of
|
||||||
the week and names of the months.
|
the week and names of the months.
|
||||||
|
|
||||||
- `TimeRTC` uses a DS1307 real-time clock to provide time synchronization.
|
- `TimeRTC` uses a DS1307 real-time clock to provide time synchronization.
|
||||||
A basic RTC library named DS1307RTC is included in the download.
|
The basic [DS1307RTC library][1] must be downloaded and installed,
|
||||||
To run this sketch the DS1307RTC library must be installed.
|
in order to run this sketch.
|
||||||
|
|
||||||
- `TimeRTCSet` is similar to the above and adds the ability to set the Real Time Clock
|
- `TimeRTCSet` is similar to the above and adds the ability to set the Real Time Clock.
|
||||||
|
|
||||||
- `TimeRTCLog` demonstrates how to calculate the difference between times.
|
- `TimeRTCLog` demonstrates how to calculate the difference between times.
|
||||||
It is a very simple logger application that monitors events on digital pins
|
It is a very simple logger application that monitors events on digital pins
|
||||||
@@ -106,11 +106,11 @@ illustrating how the library can be used with various time sources:
|
|||||||
|
|
||||||
- `TimeNTP` uses the Arduino Ethernet shield to access time using the internet NTP time service.
|
- `TimeNTP` uses the Arduino Ethernet shield to access time using the internet NTP time service.
|
||||||
The NTP protocol uses UDP and the UdpBytewise library is required, see:
|
The NTP protocol uses UDP and the UdpBytewise library is required, see:
|
||||||
http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/
|
<http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/>
|
||||||
|
|
||||||
- `TimeGPS` gets time from a GPS
|
- `TimeGPS` gets time from a GPS.
|
||||||
This requires the TinyGPS library from Mikal Hart:
|
This requires the TinyGPS library from Mikal Hart:
|
||||||
http://arduiniana.org/libraries/TinyGPS
|
<http://arduiniana.org/libraries/TinyGPS>
|
||||||
|
|
||||||
## Differences
|
## Differences
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ Changes in the Time library API:
|
|||||||
- function added to automatically sync time with external source
|
- function added to automatically sync time with external source
|
||||||
- `localTime` and `maketime` parameters changed, `localTime` renamed to `breakTime`
|
- `localTime` and `maketime` parameters changed, `localTime` renamed to `breakTime`
|
||||||
|
|
||||||
## Technical notes:
|
## Technical Notes
|
||||||
|
|
||||||
Internal system time is based on the standard Unix `time_t`.
|
Internal system time is based on the standard Unix `time_t`.
|
||||||
The value is the number of seconds since Jan 1, 1970.
|
The value is the number of seconds since Jan 1, 1970.
|
||||||
@@ -140,16 +140,18 @@ See the sketches in the examples directory for usage.
|
|||||||
The default interval for re-syncing the time is 5 minutes but can be changed by calling the
|
The default interval for re-syncing the time is 5 minutes but can be changed by calling the
|
||||||
`setSyncInterval(interval)` method to set the number of seconds between re-sync attempts.
|
`setSyncInterval(interval)` method to set the number of seconds between re-sync attempts.
|
||||||
|
|
||||||
The Time library defines a structure for holding time elements that is a compact version of the C tm structure.
|
The Time library defines a structure for holding time elements that is a compact version of the C `tm` structure.
|
||||||
All the members of the Arduino tm structure are bytes and the year is offset from 1970.
|
All the members of the Arduino `tm` structure are bytes and the year is offset from 1970.
|
||||||
Convenience macros provide conversion to and from the Arduino format.
|
Convenience macros provide conversion to and from the Arduino format.
|
||||||
|
|
||||||
Low level functions to convert between system time and individual time elements are provided:
|
Low-level functions to convert between system time and individual time elements are provided:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
breakTime(time, &tm); // break time_t into elements stored in tm struct
|
breakTime(time, &tm); // break time_t into elements stored in tm struct
|
||||||
makeTime(&tm); // return time_t from elements stored in tm struct
|
makeTime(&tm); // return time_t from elements stored in tm struct
|
||||||
```
|
```
|
||||||
|
|
||||||
The DS1307RTC library included in the download provides an example of how a time provider
|
This [DS1307RTC library][1] provides an example of how a time provider
|
||||||
can use the low-level functions to interface with the Time library.
|
can use the low-level functions to interface with the Time library.
|
||||||
|
|
||||||
|
[1]:<https://github.com/PaulStoffregen/DS1307RTC>
|
||||||
|
6
Time.cpp
6
Time.cpp
@@ -141,9 +141,9 @@ int year(time_t t) { // the year for the given time
|
|||||||
|
|
||||||
/*============================================================================*/
|
/*============================================================================*/
|
||||||
/* functions to convert to and from system time */
|
/* functions to convert to and from system time */
|
||||||
/* These are for interfacing with time serivces and are not normally needed in a sketch */
|
/* These are for interfacing with time services and are not normally needed in a sketch */
|
||||||
|
|
||||||
// leap year calulator expects year argument as years offset from 1970
|
// leap year calculator expects year argument as years offset from 1970
|
||||||
#define LEAP_YEAR(Y) ( ((1970+(Y))>0) && !((1970+(Y))%4) && ( ((1970+(Y))%100) || !((1970+(Y))%400) ) )
|
#define LEAP_YEAR(Y) ( ((1970+(Y))>0) && !((1970+(Y))%4) && ( ((1970+(Y))%100) || !((1970+(Y))%400) ) )
|
||||||
|
|
||||||
static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0
|
static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0
|
||||||
@@ -213,7 +213,7 @@ time_t makeTime(const tmElements_t &tm){
|
|||||||
seconds= tm.Year*(SECS_PER_DAY * 365);
|
seconds= tm.Year*(SECS_PER_DAY * 365);
|
||||||
for (i = 0; i < tm.Year; i++) {
|
for (i = 0; i < tm.Year; i++) {
|
||||||
if (LEAP_YEAR(i)) {
|
if (LEAP_YEAR(i)) {
|
||||||
seconds += SECS_PER_DAY; // add extra days for leap years
|
seconds += SECS_PER_DAY; // add extra days for leap years
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ typedef time_t(*getExternalTime)();
|
|||||||
#define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970
|
#define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970
|
||||||
#define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight
|
#define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight
|
||||||
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
|
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
|
||||||
// Always set the correct time before settting alarms
|
// Always set the correct time before setting alarms
|
||||||
#define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
|
#define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
|
||||||
#define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day
|
#define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day
|
||||||
#define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1
|
#define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1
|
||||||
|
Reference in New Issue
Block a user