Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
mbed_mktime.h
00001 00002 /** \addtogroup platform */ 00003 /** @{*/ 00004 /* mbed Microcontroller Library 00005 * Copyright (c) 2017-2017 ARM Limited 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); 00008 * you may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 */ 00019 00020 #ifndef MBED_MKTIME_H 00021 #define MBED_MKTIME_H 00022 00023 #include <time.h> 00024 #include <stdbool.h> 00025 #include <stdint.h> 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 /** 00032 * \defgroup platform_mktime mktime functions 00033 * @{ 00034 */ 00035 00036 /** Compute if a year is a leap year or not. 00037 * 00038 * @param year The year to test it shall be in the range [70:138]. Year 0 is 00039 * translated into year 1900 CE. 00040 * @return true if the year in input is a leap year and false otherwise. 00041 * @note - For use by the HAL only 00042 */ 00043 bool _rtc_is_leap_year(int year); 00044 00045 /* Convert a calendar time into time since UNIX epoch as a time_t. 00046 * 00047 * This function is a thread safe (partial) replacement for mktime. It is 00048 * tailored around RTC peripherals needs and is not by any mean a complete 00049 * replacement of mktime. 00050 * 00051 * @param calendar_time The calendar time to convert into a time_t since epoch. 00052 * The fields from tm used for the computation are: 00053 * - tm_sec 00054 * - tm_min 00055 * - tm_hour 00056 * - tm_mday 00057 * - tm_mon 00058 * - tm_year 00059 * Other fields are ignored and won't be renormalized by a call to this function. 00060 * A valid calendar time is comprised between the 1st january of 1970 at 00061 * 00:00:00 and the 19th of january 2038 at 03:14:07. 00062 * 00063 * @return The calendar time as seconds since UNIX epoch if the input is in the 00064 * valid range. Otherwise ((time_t) -1). 00065 * 00066 * @note Leap seconds are not supported. 00067 * @note Values in output range from 0 to INT_MAX. 00068 * @note - For use by the HAL only 00069 */ 00070 time_t _rtc_mktime(const struct tm* calendar_time); 00071 00072 /* Convert a given time in seconds since epoch into calendar time. 00073 * 00074 * This function is a thread safe (partial) replacement for localtime. It is 00075 * tailored around RTC peripherals specification and is not by any means a 00076 * complete of localtime. 00077 * 00078 * @param timestamp The time (in seconds) to convert into calendar time. Valid 00079 * input are in the range [0 : INT32_MAX]. 00080 * @param calendar_time Pointer to the object which will contain the result of 00081 * the conversion. The tm fields filled by this function are: 00082 * - tm_sec 00083 * - tm_min 00084 * - tm_hour 00085 * - tm_mday 00086 * - tm_mon 00087 * - tm_year 00088 * - tm_wday 00089 * - tm_yday 00090 * The object remains untouched if the time in input is invalid. 00091 * @return true if the conversion was successful, false otherwise. 00092 * 00093 * @note - For use by the HAL only 00094 */ 00095 bool _rtc_localtime(time_t timestamp, struct tm* calendar_time); 00096 00097 /** @}*/ 00098 00099 #ifdef __cplusplus 00100 } 00101 #endif 00102 00103 #endif /* MBED_MKTIME_H */ 00104 00105 /** @}*/
Generated on Tue Jul 12 2022 18:02:51 by
1.7.2
