00

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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