forked
platform/mbed_mktime.h@167:e84263d55307, 2017-06-21 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Jun 21 17:46:44 2017 +0100
- Revision:
- 167:e84263d55307
This updates the lib to the mbed lib v 145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 167:e84263d55307 | 1 | |
AnnaBridge | 167:e84263d55307 | 2 | /** \addtogroup platform */ |
AnnaBridge | 167:e84263d55307 | 3 | /** @{*/ |
AnnaBridge | 167:e84263d55307 | 4 | /* mbed Microcontroller Library |
AnnaBridge | 167:e84263d55307 | 5 | * Copyright (c) 2017-2017 ARM Limited |
AnnaBridge | 167:e84263d55307 | 6 | * |
AnnaBridge | 167:e84263d55307 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 167:e84263d55307 | 8 | * you may not use this file except in compliance with the License. |
AnnaBridge | 167:e84263d55307 | 9 | * You may obtain a copy of the License at |
AnnaBridge | 167:e84263d55307 | 10 | * |
AnnaBridge | 167:e84263d55307 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 167:e84263d55307 | 12 | * |
AnnaBridge | 167:e84263d55307 | 13 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 167:e84263d55307 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 167:e84263d55307 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 167:e84263d55307 | 16 | * See the License for the specific language governing permissions and |
AnnaBridge | 167:e84263d55307 | 17 | * limitations under the License. |
AnnaBridge | 167:e84263d55307 | 18 | */ |
AnnaBridge | 167:e84263d55307 | 19 | |
AnnaBridge | 167:e84263d55307 | 20 | #ifndef MBED_MKTIME_H |
AnnaBridge | 167:e84263d55307 | 21 | #define MBED_MKTIME_H |
AnnaBridge | 167:e84263d55307 | 22 | |
AnnaBridge | 167:e84263d55307 | 23 | #include <time.h> |
AnnaBridge | 167:e84263d55307 | 24 | #include <stdbool.h> |
AnnaBridge | 167:e84263d55307 | 25 | #include <stdint.h> |
AnnaBridge | 167:e84263d55307 | 26 | |
AnnaBridge | 167:e84263d55307 | 27 | #ifdef __cplusplus |
AnnaBridge | 167:e84263d55307 | 28 | extern "C" { |
AnnaBridge | 167:e84263d55307 | 29 | #endif |
AnnaBridge | 167:e84263d55307 | 30 | |
AnnaBridge | 167:e84263d55307 | 31 | /** Compute if a year is a leap year or not. |
AnnaBridge | 167:e84263d55307 | 32 | * |
AnnaBridge | 167:e84263d55307 | 33 | * @param year The year to test it shall be in the range [70:138]. Year 0 is |
AnnaBridge | 167:e84263d55307 | 34 | * translated into year 1900 CE. |
AnnaBridge | 167:e84263d55307 | 35 | * @return true if the year in input is a leap year and false otherwise. |
AnnaBridge | 167:e84263d55307 | 36 | * @note - For use by the HAL only |
AnnaBridge | 167:e84263d55307 | 37 | */ |
AnnaBridge | 167:e84263d55307 | 38 | bool _rtc_is_leap_year(int year); |
AnnaBridge | 167:e84263d55307 | 39 | |
AnnaBridge | 167:e84263d55307 | 40 | /* Convert a calendar time into time since UNIX epoch as a time_t. |
AnnaBridge | 167:e84263d55307 | 41 | * |
AnnaBridge | 167:e84263d55307 | 42 | * This function is a thread safe (partial) replacement for mktime. It is |
AnnaBridge | 167:e84263d55307 | 43 | * tailored around RTC peripherals needs and is not by any mean a complete |
AnnaBridge | 167:e84263d55307 | 44 | * replacement of mktime. |
AnnaBridge | 167:e84263d55307 | 45 | * |
AnnaBridge | 167:e84263d55307 | 46 | * @param calendar_time The calendar time to convert into a time_t since epoch. |
AnnaBridge | 167:e84263d55307 | 47 | * The fields from tm used for the computation are: |
AnnaBridge | 167:e84263d55307 | 48 | * - tm_sec |
AnnaBridge | 167:e84263d55307 | 49 | * - tm_min |
AnnaBridge | 167:e84263d55307 | 50 | * - tm_hour |
AnnaBridge | 167:e84263d55307 | 51 | * - tm_mday |
AnnaBridge | 167:e84263d55307 | 52 | * - tm_mon |
AnnaBridge | 167:e84263d55307 | 53 | * - tm_year |
AnnaBridge | 167:e84263d55307 | 54 | * Other fields are ignored and won't be renormalized by a call to this function. |
AnnaBridge | 167:e84263d55307 | 55 | * A valid calendar time is comprised between the 1st january of 1970 at |
AnnaBridge | 167:e84263d55307 | 56 | * 00:00:00 and the 19th of january 2038 at 03:14:07. |
AnnaBridge | 167:e84263d55307 | 57 | * |
AnnaBridge | 167:e84263d55307 | 58 | * @return The calendar time as seconds since UNIX epoch if the input is in the |
AnnaBridge | 167:e84263d55307 | 59 | * valid range. Otherwise ((time_t) -1). |
AnnaBridge | 167:e84263d55307 | 60 | * |
AnnaBridge | 167:e84263d55307 | 61 | * @note Leap seconds are not supported. |
AnnaBridge | 167:e84263d55307 | 62 | * @note Values in output range from 0 to INT_MAX. |
AnnaBridge | 167:e84263d55307 | 63 | * @note - For use by the HAL only |
AnnaBridge | 167:e84263d55307 | 64 | */ |
AnnaBridge | 167:e84263d55307 | 65 | time_t _rtc_mktime(const struct tm* calendar_time); |
AnnaBridge | 167:e84263d55307 | 66 | |
AnnaBridge | 167:e84263d55307 | 67 | /* Convert a given time in seconds since epoch into calendar time. |
AnnaBridge | 167:e84263d55307 | 68 | * |
AnnaBridge | 167:e84263d55307 | 69 | * This function is a thread safe (partial) replacement for localtime. It is |
AnnaBridge | 167:e84263d55307 | 70 | * tailored around RTC peripherals specification and is not by any means a |
AnnaBridge | 167:e84263d55307 | 71 | * complete of localtime. |
AnnaBridge | 167:e84263d55307 | 72 | * |
AnnaBridge | 167:e84263d55307 | 73 | * @param timestamp The time (in seconds) to convert into calendar time. Valid |
AnnaBridge | 167:e84263d55307 | 74 | * input are in the range [0 : INT32_MAX]. |
AnnaBridge | 167:e84263d55307 | 75 | * @param calendar_time Pointer to the object which will contain the result of |
AnnaBridge | 167:e84263d55307 | 76 | * the conversion. The tm fields filled by this function are: |
AnnaBridge | 167:e84263d55307 | 77 | * - tm_sec |
AnnaBridge | 167:e84263d55307 | 78 | * - tm_min |
AnnaBridge | 167:e84263d55307 | 79 | * - tm_hour |
AnnaBridge | 167:e84263d55307 | 80 | * - tm_mday |
AnnaBridge | 167:e84263d55307 | 81 | * - tm_mon |
AnnaBridge | 167:e84263d55307 | 82 | * - tm_year |
AnnaBridge | 167:e84263d55307 | 83 | * - tm_wday |
AnnaBridge | 167:e84263d55307 | 84 | * - tm_yday |
AnnaBridge | 167:e84263d55307 | 85 | * The object remains untouched if the time in input is invalid. |
AnnaBridge | 167:e84263d55307 | 86 | * @return true if the conversion was successful, false otherwise. |
AnnaBridge | 167:e84263d55307 | 87 | * |
AnnaBridge | 167:e84263d55307 | 88 | * @note - For use by the HAL only |
AnnaBridge | 167:e84263d55307 | 89 | */ |
AnnaBridge | 167:e84263d55307 | 90 | bool _rtc_localtime(time_t timestamp, struct tm* calendar_time); |
AnnaBridge | 167:e84263d55307 | 91 | |
AnnaBridge | 167:e84263d55307 | 92 | #ifdef __cplusplus |
AnnaBridge | 167:e84263d55307 | 93 | } |
AnnaBridge | 167:e84263d55307 | 94 | #endif |
AnnaBridge | 167:e84263d55307 | 95 | |
AnnaBridge | 167:e84263d55307 | 96 | #endif /* MBED_MKTIME_H */ |
AnnaBridge | 167:e84263d55307 | 97 | |
AnnaBridge | 167:e84263d55307 | 98 | /** @}*/ |